Index: anim-tutorial.c =================================================================== --- anim-tutorial.c (revisión: 0) +++ anim-tutorial.c (revisión: 0) @@ -0,0 +1,286 @@ +/* + Raydium - CQFD Corp. + http://raydium.org/ + Released under both BSD license and Lesser GPL library license. + See "license.txt" file. +*/ + +// This file is a default skeleton. Replace all [ ... ] sections with yours. +// Have fun ! + +#include "raydium/index.c" + +//globals +int step=0; +int troopermodel; +int instance1; +int show=0; +float delay=0; + +void title (char *text) + { + float x,y,ang,width=0.4; + + //shadow (ugly way.... is there a better one?) + raydium_osd_color_rgba (0.2,0.2,0.2,0.3); + + for (ang=0; ang<6.27; ang+=0.1) + { + x=width*cos (ang); + y=width*sin (ang); + raydium_osd_printf (5+x,93+y,30,0.4,"bitstream.tga",text); + } + + raydium_osd_color_rgba (1,0.9,0.0,1); + raydium_osd_printf (5,93,30,0.4,"bitstream.tga",text); + } + +void echo (char * text) + { + float x,y,ang,width=0.4; + + //shadow (ugly way.... is there a better one?) + raydium_osd_color_rgba (0.2,0.2,0.2,0.3); + + for (ang=0; ang<6.27; ang+=0.1) + { + x=width*cos (ang); + y=width*sin (ang); + raydium_osd_printf (5+x,85+y,17,0.5,"bitstream.tga",text); + } + + raydium_osd_color_rgba (1,1,1,1); + raydium_osd_printf (5,85,17,0.5,"bitstream.tga",text); + + if (delay>0.3) + { + raydium_osd_color_rgba (1,1,1,1); + raydium_osd_printf (35.05,5.05,20,0.45,"bitstream.tga","Press SPACE to continue."); + raydium_osd_color_rgba (1,0.5,0,1); + raydium_osd_printf (35,5,20,0.45,"bitstream.tga","Press SPACE to continue."); + } + } + +void code (int level) + { + float x,y,ang,width=0.5; + char text[2048]; + + strcpy (text,""); + + switch (level) + { + case 1: + strcpy (text,"int modelid;\nvoid main()\n...\nmodelid=raydium_anim_model_load(\"trooper\");\n...\nraydium_callback(&display);\n..."); + break; + case 2: + strcpy (text,"int modelid;\nint instanceid;\nvoid main()\n...\nmodelid=raydium_anim_model_load(\"trooper\");\ninstanceid=raydium_anim_instance_new(modelid);\n...\nraydium_callback(&display);\n..."); + break; + case 3: + strcpy (text,"void main()\n...\ninstanceid=raydium_anim_instance_new(modelid);\nraydium_anim_instance_move(instanceid,0,-1,-1.28);\nraydium_anim_instance_rotate(instanceid,140,0,0);...\nraydium_callback(&display);\n..."); + break; + case 4: + strcpy (text,"void display()\n...\nraydium_anim_instance_update(instanceid,raydium_frame_time);\n...\nraydium_clear_frame();"); + break; + case 5: + strcpy (text,"void display()\n...\nraydium_ode_draw_all(0);\n...\nraydium_anim_instance_render(instanceid,RAYDIUM_ANIM_RENDER_MESH);\n...\nraydium_clear_frame();"); + break; + case 6: + strcpy (text,"void display()\n...\nif(raydium_key_last==1000+'a')\nraydium_anim_loop_set(instanceid,1,1,0.5);\nif(raydium_key_last==1000+'s')\nraydium_anim_loop_set(instanceid,2,1,0.5);\n..."); + break; + } + + //shadow (ugly way.... is there a better one?) + raydium_osd_color_rgba (0,0,0,0.3); + + for (ang=0; ang<6.27; ang+=0.1) + { + x=width*cos (ang); + y=width*sin (ang); + raydium_osd_printf (5+x,60+y,16,0.5,"font2.tga",text); + } + + raydium_osd_color_rgba (1,0.3,0.1,1); + raydium_osd_printf (5,60,16,0.5,"font2.tga",text); + } + +void display (void) + { + raydium_joy_key_emul(); + delay+=raydium_frame_time; + + if (raydium_key_last==1027) + exit (0); + + raydium_clear_frame(); + raydium_camera_look_at (2,2,0.8,0,-0.4,0.9); + raydium_anim_instance_update (instance1,raydium_frame_time); + raydium_ode_draw_all (0); + + if (show==1) + { + raydium_anim_instance_render (instance1,RAYDIUM_ANIM_RENDER_MESH); + } + + switch (step) + { + case 0: + echo ("Welcome to the raydium animation system tutorial."); + break; + + case 1: + echo ("The animation system needs to use models. Those models are stored \nin packages, zip files. There is more info about those packages\nin the raydium doc, in chapter \"24 File path:\"."); + break; + + case 2: + title ("Initialization"); + echo ("By default Raydium will always initialise the animation system.\n\nYou just have to worry about 5 things to see your model animated:\n\n 1-load the model\n\n 2-create an instance\n\n 3-locate the instance\n\n 4-update the instance\n\n 5-draw your instance"); + break; + + case 3: + title ("Starting"); + echo ("We are going to use a base file, like skel.c."); + break; + + case 4: + title ("1 Loading Model"); + echo ("We can load a model with just one function: \nint raydium_anim_model_load(filename).\n\nThis function will return the ID of the model loaded or NULL if\nan error occurred. "); + code (1); + break; + + case 5: + title ("1 Loading Model"); + echo ("Loading a model has NO GRAPHICAL REPRESENTATION.\nThe model is alike a container of the animation data. For \nget a graphical representation we will need an instance."); + break; + + case 6: + title ("2 Creating an instance"); + echo ("The instance is a graphical representation of an animated model\nwith a certain configuration of meshes and materials.\nBy default raydium will load the default mesh and material\nof the model."); + break; + + case 7: + title ("2 Creating an instance"); + echo ("We can create various instances from an unique loaded model.\nFor example we can load a \"people\" model. Creating a \nfew instances with different combinations of meshes\nand materials, we could populate an street in a realistic way."); + break; + + case 8: + title ("2 Creating an instance"); + echo ("We can create an insstance with the function:\nint raydium_anim_instance_new(int modelid);.\n\nThis function will return the ID of the instance or NULL if\nan error occurred."); + code (2); + break; + + case 9: + title ("3 Locating the instance"); + echo ("Instances can be placed with:\nraydium_anim_instance_move(int instance,float x, float y, float z)\n\nraydium_anim_instance_rotate(int instance,float x, float y, float z)"); + code (3); + break; + + case 10: + title ("4 Updating the instance"); + echo ("Each frame (usually) we need to update the internal time value\nof the instances. This internal time is needed to allow the\nanimation to go forward.\nUsually you will find that raydium_frame_time is the best value\n for the delta_time field."); + break; + + case 11: + title ("4 Updating the instance"); + echo ("The function used is:\nvoid raydium_anim_instance_update (int instance,float delta_time)\nNote: this funtion has to be placed in the display callback."); + code (4); + break; + + case 12: + title ("5 Render the instance"); + echo ("For rendering each instance, we have to use the function:\nvoid raydium_anim_instance_render(int instance, int type)\nThis function has to be placed after the raydium_ode_draw_all."); + code (5); + break; + + case 13: + title ("6 Launching a loop"); + echo ("The model, as so the instances, can have 2 types fo animations:\nloops and actions.\n\nThe loops are cyclic animations.\nThe actions just plays once."); + break; + + case 14: + title ("6 Launching a loop"); + echo ("The function used for launching a loop is:\nvoid raydium_anim_loop_set (int instance,int animation,\n float influence, float delay_seconds)"); + code (6); + break; + + case 15: + title ("6 Launching a loop"); + echo ("Trick: For good mixing of animations you have to adjust the values\n of the influence of each loop applied."); + break; + + case 16: + title ("End"); + echo ("That's all... right now.\n\nWe will try to prepare an advanced tutorial soon.\nSee You. "); + break; + + default: + echo ("you should not see this..."); + break; + } + + if (raydium_key_last==1000+'a') + raydium_anim_loop_set (instance1,2,1,0.5); + + if (raydium_key_last==1000+'s') + raydium_anim_loop_set (instance1,1,1,0.5); + + if (raydium_key_last==1032 && delay>0.3) + { + switch (step) + { + case 4: + troopermodel=raydium_anim_model_load ("trooper.zip"); + break; + case 6: + instance1=raydium_anim_instance_new (troopermodel); + break; + case 9: + raydium_anim_instance_move (instance1,0,-1,-1.28);//3D coords + raydium_anim_instance_rotate (instance1,140,0,0);//degrees x,y,z + break; + case 11: + show=1; + break; + case 13: + raydium_anim_loop_set (instance1,1,1,0.5); + break; + case 16: + exit (0); + break; + default: + break; + } + + delay=0; + step++; + } + + raydium_rendering_finish(); + } + + +int main (int argc, char **argv) + { + raydium_init_args (argc,argv); + raydium_window_create (800,600,RAYDIUM_RENDERING_WINDOW,"Animation tutorial"); + + raydium_texture_filter_change (RAYDIUM_TEXTURE_FILTER_TRILINEAR); + raydium_window_view_perspective (60,0.01,2500); // fov 60 + near and far planes + + raydium_fog_disable(); + raydium_light_enable(); + raydium_light_on (0); + + raydium_light_conf_7f (0,50,150,200,1000000,1,0.9,0.7); // id, pos, intensity and color (RGB) + raydium_background_color_change (1,0.9,0.7,1); + + raydium_sky_box_cache(); + + /* [ place base scene here ] */ + raydium_ode_ground_set_name ("cocorobix.tri"); + + raydium_callback (&display); + return (0); + } + +// EOF Index: Makefile =================================================================== --- Makefile (revisión: 969) +++ Makefile (copia de trabajo) @@ -11,9 +11,9 @@ CC = gcc AR = ar RANLIB = ranlib -SYSTEM_LIBS = -lGL -lGLU -lXinerama -lm -ljpeg -lopenal -lalut -lvorbis -lvorbisfile -logg -lresolv -lcrypt -lz -lcurl -lxml2 -lGLEW +SYSTEM_LIBS = -lGL -lGLU -lXinerama -lm -ljpeg -lopenal -lalut -lvorbis -lvorbisfile -logg -lresolv -lcrypt -lz -lcurl -lxml2 -lGLEW -lcal3d OTHER_LIBS = raydium/ode/ode/src/libode.a raydium/php/libs/libphp5.a -INCLUDE_PATH = -Iraydium/ode/include/ -Iraydium/php/ -Iraydium/php/include -Iraydium/php/main/ -Iraydium/php/Zend -Iraydium/php/TSRM -I/usr/include/curl +INCLUDE_PATH = -Iraydium/ode/include/ -Iraydium/php/ -Iraydium/php/include -Iraydium/php/main/ -Iraydium/php/Zend -Iraydium/php/TSRM -I/usr/include/curl -I/usr/include/ LIBS_PATH = -L/usr/X11R6/lib/ CFLAGS=-Wall COMPILE_OPTIONS=-g -DLIBRAY -O2 -DRAYPHP_PATH=\"$(SHARE)/rayphp\" @@ -25,7 +25,7 @@ LDFLAGS= LINKING_OPTIONS=-Wl,-soname,libraydium.so.0 AR_OPTIONS= -HEADERS=raydium/headers/background.h raydium/headers/callback.h raydium/headers/camera.h raydium/headers/capture.h raydium/headers/clear.h raydium/headers/console.h raydium/headers/file.h raydium/headers/file_tri.h raydium/headers/fog.h raydium/headers/init.h raydium/headers/cli.h raydium/headers/internal.h raydium/headers/joy.h raydium/headers/key.h raydium/headers/land.h raydium/headers/light.h raydium/headers/log.h raydium/headers/main.h raydium/headers/mouse.h raydium/headers/network.h raydium/headers/normal.h raydium/headers/object.h raydium/headers/ode.h raydium/headers/osd.h raydium/headers/parser.h raydium/headers/particle2.h raydium/headers/php.h raydium/headers/profile.h raydium/headers/random.h raydium/headers/rayphp.h raydium/headers/register.h raydium/headers/render.h raydium/headers/signal.h raydium/headers/sky.h raydium/headers/sound.h raydium/headers/texture.h raydium/headers/timecall.h raydium/headers/math.h raydium/headers/vertex.h raydium/headers/window.h raydium/headers/reg_api.h raydium/headers/gui.h raydium/headers/live.h raydium/headers/video.h raydium/headers/shadow.h raydium/headers/myglut.h raydium/headers/web.h raydium/headers/hdr.h raydium/headers/lensflare.h raydium/headers/shader.h raydium/headers/atexit.h raydium/headers/path.h raydium/headers/sprites.h +HEADERS=raydium/headers/background.h raydium/headers/callback.h raydium/headers/camera.h raydium/headers/capture.h raydium/headers/clear.h raydium/headers/console.h raydium/headers/file.h raydium/headers/file_tri.h raydium/headers/fog.h raydium/headers/init.h raydium/headers/cli.h raydium/headers/internal.h raydium/headers/joy.h raydium/headers/key.h raydium/headers/land.h raydium/headers/light.h raydium/headers/log.h raydium/headers/main.h raydium/headers/mouse.h raydium/headers/network.h raydium/headers/normal.h raydium/headers/object.h raydium/headers/ode.h raydium/headers/osd.h raydium/headers/parser.h raydium/headers/particle2.h raydium/headers/php.h raydium/headers/profile.h raydium/headers/random.h raydium/headers/rayphp.h raydium/headers/register.h raydium/headers/render.h raydium/headers/signal.h raydium/headers/sky.h raydium/headers/sound.h raydium/headers/texture.h raydium/headers/timecall.h raydium/headers/math.h raydium/headers/vertex.h raydium/headers/window.h raydium/headers/reg_api.h raydium/headers/gui.h raydium/headers/live.h raydium/headers/video.h raydium/headers/shadow.h raydium/headers/myglut.h raydium/headers/web.h raydium/headers/hdr.h raydium/headers/lensflare.h raydium/headers/shader.h raydium/headers/atexit.h raydium/headers/path.h raydium/headers/sprites.h raydium/headers/anim.h OBJECTS = $(HEADERS:raydium/headers/%.h=raydium/compile/%.o) Index: anim-test1.c =================================================================== --- anim-test1.c (revisión: 0) +++ anim-test1.c (revisión: 0) @@ -0,0 +1,232 @@ +/* + Raydium - CQFD Corp. + http://raydium.org/ + Released under both BSD license and Lesser GPL library license. + See "license.txt" file. +*/ + +#include "raydium/index.c" + +//GLOBALS +int model,model2; //the 2 models +int instance,instance2; //one instance per model +int rendermesh=0; //flag for showing mesh +int renderskel=1; //flag for showing skeleton +int anim=0; //animation id for both instances + +void clear_animation (void) + { + raydium_anim_loop_clear (instance,0,0.5); + raydium_anim_loop_clear (instance,1,0.5); + raydium_anim_loop_clear (instance,2,0.5); + raydium_anim_loop_clear (instance,3,0.5); + raydium_anim_loop_clear (instance,4,0.5); + raydium_anim_loop_clear (instance,5,0.5); + raydium_anim_loop_clear (instance,anim,0.5); + raydium_anim_loop_clear (instance2,0,0.5); + raydium_anim_loop_clear (instance2,1,0.5); + raydium_anim_loop_clear (instance2,2,0.5); + raydium_anim_loop_clear (instance2,3,0.5); + raydium_anim_loop_clear (instance2,4,0.5); + raydium_anim_loop_clear (instance2,5,0.5); + raydium_anim_loop_clear (instance2,anim,0.5); + } + +void display (void) + { +//each frame we update the instances + raydium_anim_instance_update (instance,raydium_frame_time); + raydium_anim_instance_update (instance2,raydium_frame_time); + + raydium_joy_key_emul(); + +//escape + if (raydium_key_last==1027) + exit (0); + +//F7 capture screen + if (raydium_key_last==7) + raydium_capture_frame_auto(); + +//switch meshes + if (raydium_key_last==1) + rendermesh=rendermesh?0:1; + +//switch skel + if (raydium_key_last==2) + renderskel=renderskel?0:1; + +//LOD setting + if (raydium_key_last==5) + { + //use a LOD 10% of the mesh for rendering + //raydium_anim_model_lod_set(instance,0.1); this crash as there is no LOD + raydium_anim_model_lod_set (instance2,0.1); + } + + if (raydium_key_last==6) + { + //restore LOD 100% of the mesh for rendering + //raydium_anim_model_lod_set(instance,1); this crash as there is no LOD + raydium_anim_model_lod_set (instance2,1); + } + +//change animations + if (raydium_key_last==1000+'1') + { + //remove animations + clear_animation(); + raydium_anim_loop_set (instance,1,1,1); + raydium_anim_loop_set (instance2,1,1,1); + anim=1; + } + + if (raydium_key_last==1000+'2') + { + //remove animations + clear_animation(); + raydium_anim_loop_set (instance,2,1,1); + raydium_anim_loop_set (instance2,2,1,1); + anim=2; + } + + //loop + if (raydium_key_last==1000+'3') + { + //remove animations + clear_animation(); + raydium_anim_loop_set (instance,3,1,1); + raydium_anim_loop_set (instance2,3,1,1); + anim=3; + } + +//loop + if (raydium_key_last==1000+'4') + { + //remove animations + clear_animation(); + raydium_anim_loop_set (instance,4,1,1); + raydium_anim_loop_set (instance2,4,1,1); + anim=4; + } + +//action + if (raydium_key_last==1000+'5') + { + //remove animations + clear_animation(); + raydium_anim_loop_set (instance,5,1,1); + raydium_anim_loop_set (instance2,5,1,1); + anim=5; + } + + if (raydium_key_last==1000+'0') + { + //remove animations + clear_animation(); + raydium_anim_loop_set (instance,0,1,1); + raydium_anim_loop_set (instance2,0,1,1); + anim=0; + } + + if (raydium_key_last==1000+'+') + { + //remove animations + clear_animation(); + raydium_anim_loop_set (instance,anim+1,1,1); + raydium_anim_loop_set (instance2,anim+1,1,1); + anim++; + } + + if (raydium_key_last==1000+'-') + { + //remove animations + clear_animation(); + raydium_anim_loop_set (instance,anim-1,1,1); + raydium_anim_loop_set (instance2,anim-1,1,1); + anim--; + } + + raydium_clear_frame(); + raydium_camera_orbitmove (0,0,0.5); + raydium_ode_draw_all (0); + +//render instances + if (rendermesh) + { +//the "1" as second parameter is use for skeleton mode + raydium_anim_instance_render (instance,RAYDIUM_ANIM_RENDER_MESH); + raydium_anim_instance_render (instance2,RAYDIUM_ANIM_RENDER_MESH); + } + + if (renderskel) + { +//to see "always" the skeletons we have to clear the Zbuffer + glClear (GL_DEPTH_BUFFER_BIT); + + raydium_osd_color_rgba (1,1,1,1); + raydium_osd_color_ega (0xf); + raydium_anim_instance_render (instance,RAYDIUM_ANIM_RENDER_SKELETON); + raydium_anim_instance_render (instance2,RAYDIUM_ANIM_RENDER_SKELETON); + } + + raydium_osd_color_rgba (1,1,1,1); + raydium_osd_printf (90,95,14,0.45,"bitstream.tga","FPS: %d",raydium_render_fps); + raydium_osd_printf (5,5,14,0.45,"bitstream.tga","raydium_frame_time: %5.5f (Value used for updating animation)",raydium_frame_time); + raydium_osd_printf (5,95,15,0.45,"bitstream.tga","F1: Switch render Mesh On/Off (F3 before)"); + raydium_osd_printf (5,92,15,0.45,"bitstream.tga","F2: Switch render Skeleton On/Off"); + raydium_osd_printf (5,83,15,0.45,"bitstream.tga","F5: LOD(level of detail) 10%% only for models supporting LOD"); + raydium_osd_printf (5,80,15,0.45,"bitstream.tga","F6: LOD(level of detail) 100%% only for models supporting LOD"); + raydium_osd_printf (5,77,15,0.45,"bitstream.tga","F7: Capture screen"); + raydium_osd_printf (5,74,15,0.45,"bitstream.tga","1,2,3,4,5,0,+ and -: Choose animation"); + raydium_osd_printf (25,15,19,0.45,"bitstream.tga","Playing animation %d as a LOOP",anim ); + + raydium_rendering_finish(); + } + + +int main (int argc, char **argv) + { + raydium_init_args (argc,argv); + raydium_window_create (800,600,RAYDIUM_RENDERING_WINDOW,"Cal3D Animation test 1"); + + raydium_texture_filter_change (RAYDIUM_TEXTURE_FILTER_TRILINEAR); + raydium_window_view_perspective (60,0.01,2500); // fov 60 + near and far planes + + raydium_fog_disable(); + raydium_light_enable(); + raydium_light_on (0); + + raydium_light_conf_7f (0,50,150,200,1000000,1,0.9,0.7); // id, pos, intensity and color (RGB) + raydium_background_color_change (1,0.9,0.7,1); + + raydium_sky_box_cache(); + raydium_anim_init(); + raydium_ode_ground_set_name ("cocorobix.tri"); + +//Cal3D loading models +//Cal3D models are like reference/data containers, that can not be directly used. + model=raydium_anim_model_load ("trooper.zip"); + model2=raydium_anim_model_load ("cally.zip"); + +//Cal3D models are uselees by themselves, we need create instances of them +//Cal3D creating instances + instance=raydium_anim_instance_new (model); + instance2=raydium_anim_instance_new (model2); + +//Cal3D placing/rotating instances + raydium_anim_instance_move (instance,0,-1,-1.28);//3D coords + raydium_anim_instance_rotate (instance,140,0,0);//degrees x,y,z + raydium_anim_instance_move (instance2,0,1,-1.3);//3D coords + raydium_anim_instance_rotate (instance2,110,0,0);//degrees x,y,z +//Cal3D load finished + + raydium_callback (&display); + +//Cal3D needs to destroy all the models before exiting. +//In a future this should be done by raydium internals. + raydium_anim_models_destroy_all(); + return (0); + } + +// EOF Index: anim-viewer.c =================================================================== --- anim-viewer.c (revisión: 0) +++ anim-viewer.c (revisión: 0) @@ -0,0 +1,387 @@ +/* + Raydium - CQFD Corp. + http://raydium.org/ + Released under both BSD license and Lesser GPL library license. + See "license.txt" file. +*/ + +#include "raydium/index.c" + +//GLOBALS +int model; //model loaded +int instance; //the instance of the model +int rendermesh=0; //flag for rendering mesh +int renderskel=1; //flag for rendering skeleton +int camera=1; //type of camera +int animations=0; //number of animations +int curanimation=0; //id of the current animation +float fade=0.5; //cross fade time +char arg[16][512]; +int fixup=0; //workaround for wrong up vector + + +#define GRIDPOINTS 41 +static GLfloat grid[GRIDPOINTS][GRIDPOINTS][3] = {{{ 0 }}}; //Why 3? + +void InitGrid ( void ) + { + int i, j; + float x, y, spacing; + + /* Create a flat grid composed of points + * with the z value = 0 + */ + + /* spacing = distance between adjacent grid points in x and y */ + spacing = 15.0f / (float) (GRIDPOINTS - 1); + + /* x and z range from -1.0 to 1.0 by spacing interval */ + for ( x = -1.0*spacing/2.0f*GRIDPOINTS, i = 0; i < GRIDPOINTS; x += spacing, i++ ) + { + for ( y = -1.0*spacing/2.0f*GRIDPOINTS, j = 0; j < GRIDPOINTS; y += spacing, j++ ) + { + grid[i][j][0] = x; + grid[i][j][1] = y; + grid[i][j][2] = 0.0; + } + } + } + +void WireGrid ( void ) + { + register int i, j; + + + glNormal3f ( 0.0f, 0.0f, 1.0f ); + + /* draw vertical lines connecting grid points */ + for ( i = 0; i < (GRIDPOINTS); i++ ) + { + glBegin ( GL_LINE_STRIP ); + + for ( j = 0; j < (GRIDPOINTS); j++ ) + { + glVertex3fv ( &grid[i][j][0] ); + } + + glEnd(); + } + + /* draw horizontal lines connecting grid points */ + for ( j = 0; j < (GRIDPOINTS); j++ ) + { + glBegin ( GL_LINE_STRIP ); + + for ( i = 0; i < (GRIDPOINTS); i++ ) + { + glVertex3fv ( &grid[i][j][0] ); + } + + glEnd(); + } + } + + +//clean all animations of the model +void clean_animations (void) + { + int a; + + for (a=0; a=animations) + curanimation=0; + + clean_animations(); + raydium_anim_loop_set (instance,curanimation,1,fade); + } + + if (raydium_key_last==1000+'-') + { + curanimation--; + + if (curanimation<0) + curanimation=animations-1; + + clean_animations (); + raydium_anim_loop_set (instance,curanimation,1,fade); + } + + if (raydium_key_last==1000+'r') + { + if(fixup) + { + raydium_anim_instance_rotate_relative(instance,0,0,-90); + fixup=0; + } + else + { + raydium_anim_instance_rotate_relative(instance,0,0,90); + fixup=1; + } + } + + raydium_clear_frame(); + + if (camera==1) + raydium_camera_orbitmove (0,0,1.2); + + else + raydium_camera_freemove (1); + + raydium_ode_draw_all (0); + + WireGrid(); + +//render instances + if (rendermesh) + { + raydium_anim_instance_render (instance,RAYDIUM_ANIM_RENDER_MESH); + } + + if (renderskel) + { + glClear (GL_DEPTH_BUFFER_BIT); + raydium_osd_color_rgba (1,1,1,1); + raydium_anim_instance_render (instance,RAYDIUM_ANIM_RENDER_SKELETON); + } + +//OSD(behind of the model) + raydium_osd_color_rgba (0,0,0,1); + raydium_osd_printf (90,95,14,0.45,"bitstream.tga","FPS: %d",raydium_render_fps); + raydium_osd_printf (5,5,14,0.45,"bitstream.tga","raydium_frame_time: %5.5f (Value used for updating animation)",raydium_frame_time); + raydium_osd_printf (5,95,15,0.45,"bitstream.tga","F1: Switch render Mesh On/Off (F3 before)"); + raydium_osd_printf (5,92,15,0.45,"bitstream.tga","F2: Switch render Skeleton On/Off"); + raydium_osd_printf (5,83,15,0.45,"bitstream.tga","F5: LOD(level of detail) 10%% only for models supporting LOD"); + raydium_osd_printf (5,80,15,0.45,"bitstream.tga","F6: LOD(level of detail) 100%% only for models supporting LOD"); + raydium_osd_printf (5,77,15,0.45,"bitstream.tga","F7: Capture screen"); + raydium_osd_printf (5,74,15,0.45,"bitstream.tga","F8: Switch betwen orbit and freemove cameras"); + raydium_osd_printf (5,71,15,0.45,"bitstream.tga","1,2,3,4,5: Choose animation"); + raydium_osd_printf (5,68,15,0.45,"bitstream.tga","+,-: Choose next/previous animation"); + raydium_osd_printf (5,65,15,0.45,"bitstream.tga","r: fix for rotated models (wrong up vector)"); + raydium_osd_printf (25,15,19,0.45,"bitstream.tga","Playing animation %d as a LOOP",curanimation); + raydium_osd_stop(); + + raydium_rendering_finish(); + } + +unsigned char load_new_model (char *filename) + { + + if ( (model=raydium_anim_model_load (filename) ) ==-1) + { + raydium_log ("Invalid model"); + return -1; + } + + else + { + //creating instances + instance=raydium_anim_instance_new (model); + + //placing/rotating instances + raydium_anim_instance_move (instance,0,0,0); + raydium_anim_instance_rotate (instance,0,0,0); + + animations=raydium_anim_animation_get_number (model); + curanimation=0; + raydium_anim_loop_set (instance,curanimation,1,fade); + } + } + +int cutcut (char *entry) + { + int i,j,n; + + for (i=0,j=0,n=0; i<=strlen (entry); i++) + { + if (entry[i]==' ' || entry[i]==0) + { + arg[n][j]=0; + j=0; + + if (n<16) + n++; + } + + else + arg[n][j++]=entry[i]; + } + + if (arg[0][0]) + return n; + + else + return 0; + } + +void prompt (char *entry) + { + int argc; + + argc=cutcut (entry); + + if (!argc) + return; + + if (!strcmp (arg[0],"load") && argc==2) + load_new_model (arg[1]); + + } + + + + +int main (int argc, char **argv) + { + raydium_init_args (argc,argv); + + if (!argv[1]) + { + raydium_log ("\n\n\nERROR!!!!!\n You must indicate a valid animation file(.cfg) in the command line. Example:\n./odyncomp.sh anim.viewer.c anim1.cfg\n\n\n"); + return 0; + } + + raydium_console_gets_callback=prompt; + + raydium_window_create (1024,768,RAYDIUM_RENDERING_WINDOW,"Cal3D Animation test 1"); + + raydium_texture_filter_change (RAYDIUM_TEXTURE_FILTER_TRILINEAR); + raydium_window_view_perspective (60,0.01,2500); // fov 60 + near and far planes + + raydium_fog_disable(); + + raydium_light_on (0); + raydium_light_on (1); + raydium_light_on (2); + + raydium_light_conf_7f (0,50,150,200,10000000,1,1,1); // id, pos, intensity and color (RGB) + raydium_light_conf_7f (1,-50,-150,-200,10000000,1,1,1); // id, pos, intensity and color (RGB) + raydium_light_conf_7f (2,0,0,100,10000000,1,1,1); // id, pos, intensity and color (RGB) + +//raydium_background_color_change(1,0.9,0.7,1); + + raydium_sky_box_cache(); + raydium_anim_init(); + +//loading models + if ( (model=raydium_anim_model_load (argv[1]) ) ==-1) + { + raydium_log ("Invalid model"); + return -1; + } + +//creating instances + instance=raydium_anim_instance_new (model); + +//placing/rotating instances + raydium_anim_instance_move (instance,0,0,0); + raydium_anim_instance_rotate (instance,0,0,0); + +//get number of animations + animations=raydium_anim_animation_get_number (model); + curanimation=0; + raydium_anim_loop_set (instance,curanimation,1,fade); + InitGrid(); + raydium_callback (&display); + raydium_anim_models_destroy_all(); + return (0); + } + +// EOF Index: raydium/init.c =================================================================== --- raydium/init.c (revisión: 969) +++ raydium/init.c (copia de trabajo) @@ -97,6 +97,7 @@ raydium_osd_fade_init(); raydium_console_init(); raydium_gui_init(); +raydium_anim_init(); //#ifndef WIN32 raydium_live_init(); //#endif @@ -293,6 +294,7 @@ raydium_sound_init(); raydium_viewport_init(); raydium_callback_set(); +raydium_anim_init(); #ifdef PHP_SUPPORT raydium_php_init(); #endif Index: raydium/anim.c =================================================================== --- raydium/anim.c (revisión: 0) +++ raydium/anim.c (revisión: 0) @@ -0,0 +1,1115 @@ +/* + Raydium - CQFD Corp. + http://raydium.org/ + Released under both BSD license and Lesser GPL library license. + See "license.txt" file. +*/ + +#ifndef DONT_INCLUDE_HEADERS +#include "index.h" +#else +#include "headers/anim.h" +#endif + +//usage of coremodels +int raydium_anim_model_use [RAYDIUM_ANIM_MAX_MODELS]; //model slot is being used or not +int raydium_anim_animations [RAYDIUM_ANIM_MAX_MODELS]; //quantity of animations +int raydium_anim_meshes [RAYDIUM_ANIM_MAX_MODELS]; //quantity of meshes +int raydium_anim_materials [RAYDIUM_ANIM_MAX_MODELS]; //quantity of materials +int raydium_anim_animationid [RAYDIUM_ANIM_MAX_MODELS][RAYDIUM_ANIM_MAX_ANIMATIONS]; //the id of the animation of the model +int raydium_anim_instance_use [RAYDIUM_ANIM_MAX_INSTANCES]; //instance slot is being used or not +int raydium_anim_instance_model [RAYDIUM_ANIM_MAX_INSTANCES]; //the model used by this instance +int raydium_anim_mesh_use [RAYDIUM_ANIM_MAX_MESHES]; //mesh slot is being used or not +int raydium_anim_meshid [RAYDIUM_ANIM_MAX_MODELS][RAYDIUM_ANIM_MAX_MESHES]; //the id of the mesh +int raydium_anim_material_use [RAYDIUM_ANIM_MAX_MESHES]; //material slot is being used or not +int raydium_anim_materialid [RAYDIUM_ANIM_MAX_MODELS][RAYDIUM_ANIM_MAX_MATERIALS]; //the id of the material +float raydium_anim_instance_pos_rot[RAYDIUM_ANIM_MAX_INSTANCES][6]; //position and rotation of the instance. The format is posx,posy,posz,rotx,roty,yrotz in a 6 float array. + +//instances +struct CalModel *raydium_anim_instance[RAYDIUM_ANIM_MAX_INSTANCES]; +//coremodels +struct CalCoreModel *raydium_anim_model[RAYDIUM_ANIM_MAX_MODELS]; + +/*********************************************************************/ +/******************* ANIM FUNCTIONS ***********************/ +/*********************************************************************/ + +void raydium_anim_init (void) + { + int a,b; + + //loop all model slots + for (a=0; a=0.0f) + raydium_anim_cal3d_instance_update (instance,delta_time); + } + +void raydium_anim_animation_scale (int model,int animation,float scale) + { + if (raydium_anim_model_use[model]) + raydium_anim_cal3d_animation_scale (model,animation,scale); + + else + raydium_log ("ANIM:ERROR: Invalid model index"); + } + +void raydium_anim_skeleton_scale (int model,float scale) + { + if (raydium_anim_model_use[model]) + raydium_anim_cal3d_skeleton_scale ( model, scale); + } + +void raydium_anim_loop_set (int instance,int animation, float influence, float delay_seconds) + { + raydium_anim_cal3d_loop_set ( instance, animation, influence, delay_seconds); + } + +void raydium_anim_action_remove (int instance,int animation) + { + raydium_anim_cal3d_action_remove (instance,animation); + } + +void raydium_anim_instance_render (int instance, int type) + { + //glPushMatrix(); + //glLoadIdentity(); + raydium_camera_replace(); + glTranslatef ( raydium_anim_instance_pos_rot[instance][0], + raydium_anim_instance_pos_rot[instance][1], + raydium_anim_instance_pos_rot[instance][2]); + glRotatef ( raydium_anim_instance_pos_rot[instance][3],0,0,1); + glRotatef ( raydium_anim_instance_pos_rot[instance][4],0,1,0); + glRotatef ( raydium_anim_instance_pos_rot[instance][5],1,0,0); + + switch (type) + { + case RAYDIUM_ANIM_RENDER_NONE: + //do nothing + break; + case RAYDIUM_ANIM_RENDER_MESH: + raydium_anim_instance_render_mesh (instance); + break; + case RAYDIUM_ANIM_RENDER_SKELETON: + raydium_anim_instance_render_skeleton (instance); + break; + } + + //glPopMatrix(); + } + +void raydium_anim_instance_move (int instance,float x, float y, float z) + { + if (raydium_anim_instance_use[instance]) + { + raydium_anim_instance_pos_rot[instance][0]=x; + raydium_anim_instance_pos_rot[instance][1]=y; + raydium_anim_instance_pos_rot[instance][2]=z; + } + } + +void raydium_anim_instance_move_relative (int instance,float x, float y, float z) + { + if (raydium_anim_instance_use[instance]) + { + raydium_anim_instance_pos_rot[instance][0]+=x; + raydium_anim_instance_pos_rot[instance][1]+=y; + raydium_anim_instance_pos_rot[instance][2]+=z; + } + } + +void raydium_anim_instance_rotate (int instance,float x, float y, float z) + { + if (raydium_anim_instance_use[instance]) + { + raydium_anim_instance_pos_rot[instance][3]=x; + raydium_anim_instance_pos_rot[instance][4]=y; + raydium_anim_instance_pos_rot[instance][5]=z; + } + } + +void raydium_anim_instance_rotate_relative (int instance,float x, float y, float z) + { + if (raydium_anim_instance_use[instance]) + { + raydium_anim_instance_pos_rot[instance][3]+=x; + raydium_anim_instance_pos_rot[instance][4]+=y; + raydium_anim_instance_pos_rot[instance][5]+=z; + } + } + +void raydium_anim_instance_render_mesh (int instance) + { + if (raydium_anim_instance_use[instance]) + raydium_anim_cal3d_instance_render_mesh (instance); + + else + raydium_log ("ANIM:ERROR: Invalid instance index."); + } + +void raydium_anim_model_materials_apply (int instance, int set) + { + raydium_anim_cal3d_model_materials_apply (instance,set); + } + +void raydium_anim_model_lod_set (int instance, float lod_level) + { + raydium_anim_cal3d_model_lod_set (instance,lod_level); + } + +void raydium_anim_action_set (int instance,int animation, float fadein_seconds, float fadeout_seconds, int autolock) + { + raydium_anim_cal3d_action_set (instance,animation, fadein_seconds, fadeout_seconds,autolock); + } + +void raydium_anim_loop_clear (int instance,int animation, float delay_seconds) + { + raydium_anim_cal3d_loop_clear (instance,animation, delay_seconds); + } + +int raydium_anim_cal3d_animation_get_number (int model) + { + return CalCoreModel_GetCoreAnimationCount (raydium_anim_model[model]); + } + +/*********************************************************************/ +/******************* CAL3D FUNCTIONS **********************/ +/*********************************************************************/ + +void raydium_anim_cal3d_instance_render_skeleton (int instance) + { + float lines[1024][2][3]; + int nrLines; + float points[1024][3]; + int nrPoints; + int currLine; + int currPoint; + + if (!raydium_anim_instance_use[instance]) + { + raydium_log ("ANIM:ERROR: Instance index %d not valid. ",instance); + } + + else + { + // draw the bone lines + nrLines=CalSkeleton_GetBoneLines (CalModel_GetSkeleton (raydium_anim_instance[instance]),&lines[0][0][0]); + + glLineWidth (3.0f); + glColor3f (1.0f, 1.0f, 1.0f); + glBegin (GL_LINES); + + for (currLine = 0; currLine < nrLines; currLine++) + { + glVertex3f (lines[currLine][0][0], lines[currLine][0][1], lines[currLine][0][2]); + glVertex3f (lines[currLine][1][0], lines[currLine][1][1], lines[currLine][1][2]); + } + + glEnd(); + glLineWidth (1.0f); + + // draw the bone points + nrPoints = CalSkeleton_GetBonePoints (CalModel_GetSkeleton (raydium_anim_instance[instance]),&points[0][0]); + + glPointSize (4.0f); + glBegin (GL_POINTS); + glColor3f (0.0f, 0.0f, 1.0f); + + for (currPoint = 0; currPoint < nrPoints; currPoint++) + { + glVertex3f (points[currPoint][0], points[currPoint][1], points[currPoint][2]); + } + + glEnd(); + glPointSize (1.0f); + } + } + +void raydium_anim_cal3d_instance_update (int instance,float delta_time) + { + if (raydium_anim_instance_use[instance] && delta_time>0.0f) + CalModel_Update (raydium_anim_instance[instance],delta_time); + } + +void raydium_anim_cal3d_animation_scale (int model,int animation,float scale) + { + if (raydium_anim_model_use[model]) + CalCoreAnimation_Scale (CalCoreModel_GetCoreAnimation (raydium_anim_model[model],animation),scale); + + else + raydium_log ("ANIM:ERROR: Invalid model index"); + } + +void raydium_anim_cal3d_skeleton_scale (int model,float scale) + { + if (raydium_anim_model_use[model]) + CalCoreSkeleton_Scale (CalCoreModel_GetCoreSkeleton (raydium_anim_model[model]), (float) scale); + + else + raydium_log ("ANIM:ERROR: Invalid model index"); + } + +void raydium_anim_cal3d_instance_render_mesh (int instance) + { + int bWireframe=0; + int meshCount; + int meshId; + //renderer of the model + struct CalRenderer *pCalRenderer; + int submeshCount; + int submeshId; + unsigned char meshColor[4]; + GLfloat materialColor[4]; + float shininess; + static float meshVertices[30000][3]; + int vertexCount; + static float meshNormals[30000][3]; + static float meshTextureCoordinates[30000][2]; + int textureCoordinateCount; + static CalIndex meshFaces[50000][3]; + int faceCount; + int vertexId; + const float scale = 0.3f; + + if (raydium_anim_instance[instance]) + { + + // get the renderer of the model + pCalRenderer = CalModel_GetRenderer (raydium_anim_instance[instance]); + + // begin the rendering loop + if (!CalRenderer_BeginRendering (pCalRenderer) ) + return; + + // set wireframe mode if necessary + if (bWireframe) + { + glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); + } + + // set the global OpenGL states + //glEnable(GL_DEPTH_TEST); + //glShadeModel(GL_SMOOTH); + + + // we will use vertex arrays, so enable them + glEnableClientState (GL_VERTEX_ARRAY); + glEnableClientState (GL_NORMAL_ARRAY); + + // get the number of meshes + + meshCount = CalRenderer_GetMeshCount (pCalRenderer); + + // render all meshes of the model + + + for (meshId = 0; meshId < meshCount; meshId++) + { + // get the number of submeshes + + submeshCount = CalRenderer_GetSubmeshCount (pCalRenderer,meshId); + + // render all submeshes of the mesh + + for (submeshId = 0; submeshId < submeshCount; submeshId++) + { + // select mesh and submesh for further data access + if (CalRenderer_SelectMeshSubmesh (pCalRenderer,meshId,submeshId) ) + { + + + // set the material ambient color + CalRenderer_GetAmbientColor (pCalRenderer, &meshColor[0]); + materialColor[0] = meshColor[0] / 255.0f; + materialColor[1] = meshColor[1] / 255.0f; + materialColor[2] = meshColor[2] / 255.0f; + materialColor[3] = meshColor[3] / 255.0f; + //glMaterialfv(GL_FRONT, GL_AMBIENT, materialColor); + + // set the material diffuse color + CalRenderer_GetDiffuseColor (pCalRenderer,&meshColor[0]); + materialColor[0] = meshColor[0] / 255.0f; + materialColor[1] = meshColor[1] / 255.0f; + materialColor[2] = meshColor[2] / 255.0f; + materialColor[3] = meshColor[3] / 255.0f; + //glMaterialfv(GL_FRONT, GL_DIFFUSE, materialColor); + + // set the vertex color if we have no lights + glColor4fv (materialColor); + + // set the material specular color + CalRenderer_GetSpecularColor (pCalRenderer,&meshColor[0]); + materialColor[0] = meshColor[0] / 255.0f; + materialColor[1] = meshColor[1] / 255.0f; + materialColor[2] = meshColor[2] / 255.0f; + materialColor[3] = meshColor[3] / 255.0f; + //glMaterialfv(GL_FRONT, GL_SPECULAR, materialColor); + + // set the material shininess factor + + shininess = 50.0f; //TODO: pCalRenderer->getShininess(); + shininess = CalRenderer_GetShininess (pCalRenderer); + //glMaterialfv(GL_FRONT, GL_SHININESS, &shininess); + + // get the transformed vertices of the submesh + + vertexCount = CalRenderer_GetVertices (pCalRenderer,&meshVertices[0][0]); + + // get the transformed normals of the submesh + + CalRenderer_GetNormals (pCalRenderer, &meshNormals[0][0]); + + // get the texture coordinates of the submesh + + textureCoordinateCount = CalRenderer_GetTextureCoordinates (pCalRenderer,0,&meshTextureCoordinates[0][0]); + + // get the faces of the submesh + faceCount = CalRenderer_GetFaces (pCalRenderer,&meshFaces[0][0]); + + // set the vertex and normal buffers + glVertexPointer (3, GL_FLOAT, 0, &meshVertices[0][0]); + glNormalPointer (GL_FLOAT, 0, &meshNormals[0][0]); + + // set the texture coordinate buffer and state if necessary + if (CalRenderer_GetMapCount (pCalRenderer) >0 && (textureCoordinateCount > 0) ) + { + //glEnable(GL_TEXTURE_2D); + glEnableClientState (GL_TEXTURE_COORD_ARRAY); + //glEnable(GL_COLOR_MATERIAL); + + // set the texture id we stored in the map user data + //I don't know how to get rid of the next warning... + glBindTexture (GL_TEXTURE_2D, (GLuint) CalRenderer_GetMapUserData (pCalRenderer,0) ); + // set the texture coordenates buffer + glColor4f (1.0f, 1.0f, 1.0f,1.0f); + glTexCoordPointer (2, GL_FLOAT, 0, &meshTextureCoordinates[0][0]); + //glColor4f(1.0f, 1.0f, 1.0f,1.0f); + } + + // draw the submesh + + if (sizeof (CalIndex) ==2) + glDrawElements (GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_SHORT, &meshFaces[0][0]); + + else + glDrawElements (GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_INT, &meshFaces[0][0]); + + // disable the texture coordinate state if necessary + //TODO: temporary disabled this code... + //if (CalRenderer_GetMapCount (pCalRenderer) >0 && (textureCoordinateCount > 0) ) + //{ + //glDisable(GL_COLOR_MATERIAL); + //glDisableClientState(GL_TEXTURE_COORD_ARRAY); + //glDisable(GL_TEXTURE_2D); + //} + + //////////////////////////////////////////////////////////////////////////////// + //to show vertex normals do if(1) + if (0) + { + glBegin (GL_LINES); + glColor3f (1.0f, 1.0f, 1.0f); + + for (vertexId = 0; vertexId < vertexCount; vertexId++) + { + glVertex3f (meshVertices[vertexId][0], meshVertices[vertexId][1], meshVertices[vertexId][2]); + glVertex3f (meshVertices[vertexId][0] + meshNormals[vertexId][0] * scale, meshVertices[vertexId][1] + meshNormals[vertexId][1] * scale, meshVertices[vertexId][2] + meshNormals[vertexId][2] * scale); + } + + glEnd(); + } + + //////////////////////////////////////////////////////////////////////////////// + GLfloat one[]={0.8f, 0.8f, 0.8f, 1.f}; + GLfloat zero[]={0.0,0.0,0.0,0.0}; + glMaterialfv ( GL_FRONT_AND_BACK, GL_DIFFUSE, one); + glMaterialfv ( GL_FRONT_AND_BACK, GL_AMBIENT, zero); + //glEnable(GL_TEXTURE_2D); + glBindTexture (GL_TEXTURE_2D,0); + } + } + } + + // clear vertex array state + glDisableClientState (GL_NORMAL_ARRAY); + glDisableClientState (GL_VERTEX_ARRAY); + + // reset wireframe mode if necessary + if (bWireframe) + { + glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); + } + + // end the rendering + CalRenderer_EndRendering (pCalRenderer); + } + } + +void raydium_anim_cal3d_loop_set (int instance,int animation, float influence, float delay_seconds) + { + if (raydium_anim_instance_use[instance]) + if (delay_seconds>=0) + if (influence>=0 && influence<=1 ) + CalMixer_BlendCycle (CalModel_GetMixer (raydium_anim_instance[instance]),raydium_anim_animationid[raydium_anim_instance_model[instance]][animation],influence,delay_seconds); + + else + raydium_log ("ANIM:ERROR: Influence must be betwen 0 and 1"); + + else + raydium_log ("ANIM:ERROR: invalid delay time for setting loop in instance %d",instance); + + else + raydium_log ("ANIM:ERROR: Invalid instance index"); + } + +void raydium_anim_cal3d_loop_clear (int instance,int animation, float delay_seconds) + { + if (raydium_anim_instance_use[instance]) + if (delay_seconds>=0) + CalMixer_ClearCycle (CalModel_GetMixer (raydium_anim_instance[instance]),raydium_anim_animationid[raydium_anim_instance_model[instance]][animation],delay_seconds); + + else + raydium_log ("ANIM:ERROR: invalid delay time for clearing loop in instance %d",instance); + + else + raydium_log ("ANIM:ERROR: Invalid instance index."); + } + +void raydium_anim_cal3d_action_set (int instance,int animation, float fadein_seconds, float fadeout_seconds, int autolock) + { + if (raydium_anim_instance_use[instance]) + if (fadein_seconds>=0 && fadeout_seconds>=0) + CalMixer_ExecuteAction (CalModel_GetMixer (raydium_anim_instance[instance]),raydium_anim_animationid[raydium_anim_instance_model[instance]][animation],fadein_seconds, fadeout_seconds,autolock); + + else + raydium_log ("ANIM:ERROR: Fadein_seconds and fadeout seconds must be positive"); + + else + raydium_log ("ANIM:ERROR: Invalid instance index."); + } + +void raydium_anim_cal3d_model_lod_set (int instance, float lod_level) + { + if (raydium_anim_instance_use[instance]) + CalModel_SetLodLevel (raydium_anim_instance[instance],lod_level); + + else + raydium_log ("ANIM:ERROR: Invalid instance index."); + } + +void raydium_anim_cal3d_model_materials_apply (int instance, int set) + { + if (raydium_anim_instance_use[instance]) + CalModel_SetMaterialSet (raydium_anim_instance[instance],set); + + else + raydium_log ("ANIM:ERROR: Invalid instance index."); + } + +void raydium_anim_cal3d_action_remove (int instance, int animation) + { + if (raydium_anim_instance_use[instance]) + CalMixer_RemoveAction ( (CalModel_GetMixer (raydium_anim_instance[instance]) ),animation); + + else + raydium_log ("ANIM:ERROR: Invalid instance index."); + } + +int raydium_anim_cal3d_instance_new_internal (int num,int model) + { + if (!raydium_anim_instance_use[num]) + { + raydium_anim_instance[num]=CalModel_New (raydium_anim_model[num]); + + if (raydium_anim_instance[num]) + { + + return 1; + } + + else + { + return 0; + } + } + + else + { + raydium_log ("ANIM:ERROR: that instance alread in use. Bad index"); + return 0; + } + } + +void raydium_anim_cal3d_instance_destroy (int instance) + { + CalModel_Delete (raydium_anim_instance[instance]); + raydium_anim_instance[instance]=NULL; + } + +void raydium_anim_cal3d_instance_attach_meshes (int instance) + { + int b; + int model; + + if (raydium_anim_instance[instance]) + { + model = raydium_anim_instance_model[instance]; + + for (b=0; b CalCoreMaterial_GetMapCount(CalCoreModel_GetCoreMaterial(raydium_anim_model[a])) + // loop through all the maps of the current core material + + for (mapid = 0; mapid < CalCoreMaterial_GetMapCount (pCoreMaterial); mapid++) + { + if (RADYIUM_ANIM_DEBUG) + raydium_log ("processing texture %d of material %d of model", mapid,c); + + // get the filename of the map + //char strFilename[RAYDIUM_MAX_NAME_LEN]; + //strcpy(strFilename,CalCoreMaterial_GetMapFilename(pCoreMaterial,mapid)); + raydium_path_resolv (CalCoreMaterial_GetMapFilename (pCoreMaterial,mapid), newstr,'r'); + + // load the texture from the file + textureid=raydium_texture_find_by_name (newstr); + + //raydium_path_reset(); BAD IDEA + // store the texture id in the user data of the map + + CalUserData textureCUD; + + //I can not get rid of the next warning + textureCUD=textureid ; + CalCoreMaterial_SetMapUserData (pCoreMaterial,mapid,textureCUD); + + } + + CalCoreModel_CreateCoreMaterialThread (raydium_anim_model[a],c); + + CalCoreModel_SetCoreMaterialId (raydium_anim_model[a],c,0,c); + + //CalCoreModel_SetCoreMaterialId(raydium_anim_model[a],c,0,c); + } + + } + + //This is gonna read the cfg file and set the model with those values + if (RADYIUM_ANIM_DEBUG) + raydium_log ("finished the initialisation of this model."); + } + + else + { + raydium_log ("ANIM:ERROR: Couldn't open file \"%s\".",filename); + error=1; + } + } + + else + { + raydium_log ("ANIM:ERROR:raydium_anim_model[%d] was not unset",a); + error=1; + } + + if (error) + return 0; + + else + return 1; + } + +void raydium_anim_instance_get_pos_rot (int instance, float posrot[]) + { + if (raydium_anim_instance_use[instance]) + { + posrot=raydium_anim_instance_pos_rot[instance]; + } + + else + { + raydium_log ("ANIM:ERROR: Invalid instance index"); + } + } + +//NOT WORKING (YET) +//Trying for getting the absolute-universal posrotq matrix for a certain bone. +void raydium_anim_bone_get_absolute_posrotq (int instance,int boneid,float pos[],float *rotq) + { + struct CalBone *bone; + struct CalSkeleton *skel; + float *k; + + raydium_log ("NOT WORKING: raydium_anim_bone_get_absolute_posrotq()"); + + if (raydium_anim_instance_use[instance]) + { + //get the corebone + + skel=CalModel_GetSkeleton (raydium_anim_instance[instance]); + bone=CalSkeleton_GetBone (skel,boneid); + k=CalVector_Get (CalBone_GetTranslationAbsolute (bone) ); + pos[0]=k[0]; + pos[1]=k[1]; + pos[2]=k[2]; + //pos[0]+=(float)raydium_anim_instance_pos_rot[instance][0]; + //pos[1]+=(float)raydium_anim_instance_pos_rot[instance][1]; + //pos[2]+=(float)raydium_anim_instance_pos_rot[instance][2]; + k=CalQuaternion_Get (CalBone_GetRotationAbsolute (bone) ); + rotq[0]=k[0]; + rotq[1]=k[1]; + rotq[2]=k[2]; + rotq[3]=k[3]; + } + + else + { + raydium_log ("ANIM:ERROR: Invalid instance index"); + } + } + +int raydium_anim_animation_get_number (int model) + { + return raydium_anim_cal3d_animation_get_number (model); + } + Index: raydium/index.c =================================================================== --- raydium/index.c (revisión: 969) +++ raydium/index.c (copia de trabajo) @@ -75,6 +75,7 @@ #include "land.c" #include "sky.c" #include "internal.c" +#include "anim.c" #include "file_tri.c" #include "camera.c" #include "object.c" Index: raydium/index.h =================================================================== --- raydium/index.h (revisión: 969) +++ raydium/index.h (copia de trabajo) @@ -58,6 +58,7 @@ #include "headers/lensflare.h" #include "headers/shader.h" #include "headers/register.h" +#include "headers/anim.h" #ifdef PHP_SUPPORT #include "headers/php.h" #include "headers/rayphp.h" Index: raydium/headers/anim.h =================================================================== --- raydium/headers/anim.h (revisión: 0) +++ raydium/headers/anim.h (revisión: 0) @@ -0,0 +1,786 @@ +#ifndef _ANIM_H +#define _ANIM_H +#include + +//TODO:This should be in other place +#define RAYDIUM_ANIM_CAL3D + +//limits +#define RAYDIUM_ANIM_MAX_MODELS 20 //max number of models in the application +#define RAYDIUM_ANIM_MAX_ANIMATIONS 32//max number of animations in each model +#define RAYDIUM_ANIM_MAX_INSTANCES 16//max number of instances in the applicaction +#define RAYDIUM_ANIM_MAX_MESHES 30//max number of meshes in each model +#define RAYDIUM_ANIM_MAX_MATERIALS 30//max number of materials in each model + +//keywords +#define RAYDIUM_ANIM_RENDER_NONE 0 //the instance is invisible +#define RAYDIUM_ANIM_RENDER_MESH 1 //the mesh is visible +#define RAYDIUM_ANIM_RENDER_SKELETON 2 //the skeleton is visible + +#define RADYIUM_ANIM_DEBUG 0 //no debug + +/*= +Animation System +2200 +Raydium allows you to use Animated Models in Cal3D(http://home.gna.org/cal3d/) format. +It's important to know well how cal3d animation works before starting to suing it. + +A common cal3d model is compound of: + +-.cfg file with a few parameters and a list of used files +-.csf file with the unique skeleton per model +-.caf or .xaf files, each one is 1 animation loop/action for the current model +-.crf or .xrf files, each one is a material +-.cmf or .xmf files, each one is a mesh to apply in the model +* +Note: "x-starting" files are XML files and easy to edit. By other side "c-starting" files are binary compiled files. They can not be edited but are faster to load. + + +So raydium will load the cfg file an, internally, it will load all needed subfiles. +The models can NOT be used directly so, once loaded the model you MUST create instances of the model for your application. +Then you can apply loops or actions to each instance independently. +NOTE: Don't confuse these "loops" with raydium_display function or other callbacks. + + +Types of animations: + +Even if the animation files are the same, you can apply that animation as a loop or as an action. +Loops: the animation loops forever (until you deactivate it) +Actions: The animation will play just once, and you can set a lock. If the action is locked, the instance will be keep in the last frame of the animation, else it will return to the previous animation fame(if any). +So, what's de difference? The loops are animations that repeats once and again, but actions just plays once. + +Mixing: + +To achieve good animations you will have to mix diferent animations at time. +For example your model could be walking and sometimes it could throw an arrow. + +TODO: more explanation about mixing + +**/ + +/** +Beta +Animation system +Based on Cal3D (http://home.gna.org/cal3d/). +**/ + + +__rayapi int raydium_anim_model_load(char *filename); +/** +Beta +This function loads a model. +Currently only Cal3D models are allowed. So you have to specify a *.cfg file in +the ##filename##. + +##Parameters:## +##model##:the index of the model to instanciate + +##Returns:## +the index of the new model, or -1 if fails + +##Example:## +%%(c) +int paladin_model; +int create_model_paladin(void) + { + paladin_model=raydium_anim_model_load("paladin.cfg"); + return + } +%% +**/ + +__rayapi int raydium_anim_cal3d_model_load_internal(int a,char *filename); +/** +Beta +Internal. +**/ + +__rayapi void raydium_anim_models_destroy_all(void); +/** +Beta +Destroy all models used in raydium. +Beware. You should destroy all instances BEFORE call this function. +**/ + +__rayapi void raydium_anim_init(void); +/** +Beta +Initialise the animation system. +**/ + + +__rayapi int raydium_anim_instance_new(int model); +/** +Beta +Creates a new instance from a ##model##. + +##Parameters:## +##model##:the index of the model to instanciate + +##Returns:## +The index of the new instance + +##Example:## +%%(c) +int paladin_instance[2]; +int paladin_model; +void create_paladin_instances(void) + { + paladin_model=create_model_paladin(); + paladin_instance[0]=raydium_anim_instance_new(paladin_model); + paladin_instance[1]=raydium_anim_instance_new(paladin_model); + } +%% +**/ + +__rayapi void raydium_anim_instance_update(int instance,float time); +/** +Beta +This function is a must if you want to animate you models(instances). + +##Parameters:## +##instance##:the index of the instance +##time##: The time betwen the last call to thin function and this call. +Commonly this value is equal to ##raydium_frame_time## + +##Returns:## + +##Example:## +%%(c) +void display(void) + { + if(raydium_key_last==1027) + exit(0); + raydium_clear_frame(); + raydium_camera_freemove(RAYDIUM_CAMERA_FREEEMOVE_NORMAL); + raydium_ode_draw_all(0); + raydium_anim_instance_update(character,raydium_frame_time); + raydium_anim_instance_render_mesh(character); + raydium_rendering_finish(); + } +%% +**/ + +// __rayapi void raydium_anim_instance_update(int instance,float delta_time); + +__rayapi void raydium_anim_animation_scale(int model,int animation,float scale); +/** +Beta +This function allows you to scale an animation of your model BEFORE using it. +##Parameters:## +##model:##id of the model to sacle +##animation##:id of the animation to scale +##factor##: scale factor + +##Returns:## + +##Example:## +%%(c) +void scale_enemy(void) + { + raydium_anim_animation_scale(enemy_model,enemy_animations[7],2.1); + } +%% +**/ + +__rayapi int raydium_anim_cal3d_instance_new_internal(int num,int model); +/** +Beta +This will create a new instance from a model +##Parameters:## +##num:##id of the new instance to create. Should be an unused one. +##model##:id of the model + +##Returns:## 1 if everything goes right, elso 0. + +##Example:## +%%(c) +void new_enemy(void) + { + if(raydium_anim_cal3d_instance_new_internal(instace_counter,enemy_model)) + { + raydium_log("New enemy instance created"); + instance_counter++; + } + } +%% +**/ + +__rayapi void raydium_anim_instance_destroy(int instance); +/** +Beta +Destroy a certain instance + +##Parameters:## +##instance:##id of the instance to destroy + +##Returns:## none + +##Example:## +%%(c) +void enemy_die(enemy_instance) + { + raydium_anim_instance_destroy(enemy_instance); + } +%% +**/ + +__rayapi void raydium_anim_instance_get_pos_rot(int instance, float posrot[]); +/** +Beta +Returns the position,rotation of the instance + +##Parameters:## +##instance:##id of the instance to check +##posrot[]##float[6] with the position(float[3]) and rotation(float[3]) of the instance + +##Returns:## none + +##Example:## +%%(c) +void enemy_suicide(instance) + { + float posrot*; + posrot=raydium_anim_instance_get_pos_rot(instance); + raydium_anim_instance_destroy(instance); + raydium_ode_explosion_blow_rand_3f(10,50,1,posrot[0],posrot[1],posrot[2]) + } +%% +**/ + +__rayapi void raydium_anim_model_destroy(int a); +/** +Beta +Destroy a certain model + +##Parameters:## +##a:##id of the model to destroy + +##Returns:## none + +##Example:## +%%(c) +void enemy_extermination(enemy_model) + { + for(a=0;a