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.