Raydium 3D Game Engine

Official forum for everything about Raydium, ManiaDrive, MeMak, ...
It is currently Tue Mar 19, 2024 9:23 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sat Feb 23, 2008 12:40 am 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
First try of a new funtion to allow create objects easily from a "library".
Raydium_object_load_from_library(name) should load and create a new object defined into a .object file.
The name parameter has NO extension.It's added by the internal code.

The code is:
Code:
/*
    Raydium - CQFD Corp.
    http://raydium.org/
    License: GPL - GNU General Public License, see "gpl.txt" file.
*/

// This file is a default skeleton. Replace all [ ... ] sections with yours.
// Have fun !

#include "raydium/index.c"

void raydium_object_load_from_library(char *filename)
{
   char var[255],val_s[255];
    float val_f[255];
    char tmp_model[256];
    float tmp_mass,tmp_xoffset,tmp_zoffset,tmp_yoffset;
    float tmp_slip;
    FILE *fp;
    int ret;
    int size;
    int object1;
    int flag_model=0, flag_mass=0;
    int flag_xoffset=0, flag_yoffset=0, flag_zoffset=0;
    int flag_slip=0;
    char longname[512];
    int version;
   
    strcpy(longname,filename);
    strcat(longname,".object");   
   
   fp=raydium_file_fopen(longname,"rt");
    if(fp)
    {   
       version=0;
       tmp_mass=0;
       tmp_xoffset=0;
       tmp_yoffset=0;
       tmp_zoffset=0;
       tmp_slip=0;
        raydium_log("Reading object...");
        while( (ret=raydium_parser_read(var,val_s,val_f,&size,fp))!=RAYDIUM_PARSER_TYPE_EOF)
        {     
           if(strcmp(var,"version")==0)
            {
                raydium_parser_trim(val_s);
                version=atof(val_s);
                raydium_log("Version of the object: %f",tmp_mass);
            }   
            if(strcmp(var,"model")==0)
            {
                raydium_parser_trim(val_s);
               strcpy(tmp_model,val_s);
                flag_model=1;
                raydium_log("Model to load: %s",tmp_model);
            }
            if(strcmp(var,"mass")==0)
            {
                raydium_parser_trim(val_s);
                tmp_mass=atof(val_s);
                flag_mass=1;
                raydium_log("Mass of the object: %f",tmp_mass);
            }
             if(strcmp(var,"xoffset")==0)
            {
                raydium_parser_trim(val_s);
                tmp_xoffset=atof(val_s);
                flag_xoffset=1;
                raydium_log("xoffset: %f",tmp_xoffset);
            }
            if(strcmp(var,"yoffset")==0)
            {
                raydium_parser_trim(val_s);
                tmp_yoffset=atof(val_s);
                flag_yoffset=1;
                raydium_log("yoffset: %f",tmp_yoffset);
            }   
            if(strcmp(var,"zoffset")==0)
            {
                raydium_parser_trim(val_s);
                tmp_zoffset=atof(val_s);
                flag_zoffset=1;
                raydium_log("zoffset: %f",tmp_zoffset);
            }   
            if(strcmp(var,"slip")==0)
            {
                raydium_parser_trim(val_s);
                tmp_slip=atof(val_s);
                flag_slip=1;
                raydium_log("slip: %f",tmp_slip);
            }               
        }
       
      if(flag_model  && version==1)
      {
         object1=raydium_ode_object_find("OBJx");
         object1=raydium_ode_object_create ("OBJx");
         raydium_ode_object_box_add("element1",object1,tmp_mass,RAYDIUM_ODE_AUTODETECT,0,0,RAYDIUM_ODE_STANDARD,0,tmp_model);
         raydium_ode_object_move_3f (object1,tmp_xoffset,tmp_yoffset,tmp_zoffset);   
         raydium_ode_element_slip_name("element1",0);
      }
      fclose(fp);
   }
}

void display(void)
{
raydium_camera_freemove(RAYDIUM_CAMERA_FREEMOVE_NORMAL);
if(raydium_key_last==1027)
    exit(0);
if(raydium_key_last==1000+'l')
   raydium_object_load_from_library("crate_1");
raydium_clear_frame();
/* [ draw here ] */ raydium_ode_draw_all(0);
raydium_rendering_finish();
}

int main(int argc, char **argv)
{
raydium_init_args(argc,argv);
raydium_init_load("ejemplo.config");
/* [ place base scene here ] */ raydium_ode_ground_set_name("cocorobix.tri");
raydium_callback(&display);
return(0);
}

// EOF


The crate_1.object file is
Code:
version=1
model="crate.tri"
mass=1.6
xoffset=2
yoffset=1
zoffset=0
slip=0.0001


A lot of things to fix/improve but this is the main idea.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 23, 2008 4:11 pm 
Offline

Joined: Sun Oct 09, 2005 10:46 pm
Posts: 759
Yes a great idea !

Do you think it's easy to make it xml compliant ?

Xml import and why not export could be a great thing.

Have a nice day.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 23, 2008 5:55 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
XML?... I suppose you mean the .object file, right?
Anyway i'm not able to program with XML and i think Raydium have no XML functions...but if someone wants to give it a try there is no problem on my side.

I am glad you liked the idea :D


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 09, 2008 10:18 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
I'm afraid that things like this can only turn to a unusable, unmaintained and bloated code ...

IMHO, there's way to much things to set on an element or an object with RayODE to make an interesting new file format. A script file will do things way better, no ? (train.php is quiet a good example)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group