Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

ModelCtl.c

Go to the documentation of this file.
00001 #define WIN32_LEAN_AND_MEAN
00002 #include        <windows.h>
00003 
00004 #include        <math.h>
00005 #include        <stdlib.h>
00006 #include        <assert.h>
00007 
00008 #define BUILD_MODELCTL
00009 #include        "modelctl.h"
00010 #include        "errorlog.h"
00011 
00012 geBoolean ModelCtl_Init(void)
00013 {
00014         return GE_TRUE;
00015 }
00016 
00017 geBoolean ModelCtl_Reset(geWorld *World)
00018 {
00019         geEntity_EntitySet *    Set;
00020         geEntity *                              Entity;
00021  
00022         if      (World == NULL)
00023                 return GE_TRUE;
00024 
00025         Set = geWorld_GetEntitySet(World, "ModelController");
00026         if      (Set == NULL)
00027                 return GE_TRUE;
00028 
00029         Entity = geEntity_EntitySetGetNextEntity(Set, NULL);
00030         while   (Entity)
00031         {
00032                 ModelController *               Controller;
00033 
00034                 Controller = geEntity_GetUserData(Entity);
00035                 Controller->LastTime = 0.0f;
00036 
00037                 Entity = geEntity_EntitySetGetNextEntity(Set, Entity);
00038         }
00039 
00040         return GE_TRUE;
00041 }
00042 
00043 geBoolean ModelCtl_Shutdown(void)
00044 {
00045         return GE_TRUE;
00046 }
00047 
00048 geBoolean ModelCtl_Frame(geWorld *World, const geXForm3d *XForm, geFloat DeltaTime)
00049 {
00050         geEntity_EntitySet *    Set;
00051         geEntity *                              Entity;
00052  
00053         if      (World == NULL)
00054                 return GE_TRUE;
00055 
00056         Set = geWorld_GetEntitySet(World, "ModelController");
00057         if      (Set == NULL)
00058                 return GE_TRUE;
00059 
00060         Entity = geEntity_EntitySetGetNextEntity(Set, NULL);
00061         while   (Entity)
00062         {
00063                 ModelController *       Controller;
00064                 geMotion *                      Motion;
00065                 gePath *                        Path;
00066                 geFloat                         StartTime;
00067                 geFloat                         EndTime;
00068                 geXForm3d                       XForm;
00069 
00070                 #define MAX_NAME 200
00071                 char    EntityName[MAX_NAME];
00072 
00073                 geEntity_GetName(Entity, EntityName, MAX_NAME-1);
00074                 EntityName[MAX_NAME-1]=0;
00075 
00076                 Controller = geEntity_GetUserData(Entity);
00077                 if (Controller->Model==NULL)
00078                         {
00079                                 geErrorLog_AddString(0,"ModelCtl_Frame: Model controller has no model:",EntityName);
00080                                 return GE_FALSE;
00081                         }
00082                 Motion = geWorld_ModelGetMotion(Controller->Model);
00083                 if (Motion == NULL)
00084                         {
00085                                 geErrorLog_AddString(0,"ModelCtl_Frame: Model controller has no motion:",EntityName);
00086                                 return GE_FALSE;
00087                         }
00088                 Path = geMotion_GetPath(Motion, 0);
00089                 if (Path == NULL)
00090                         {
00091                                 geErrorLog_AddString(0,"ModelCtl_Frame: Model controller has no path in its motion:",EntityName);
00092                                 return GE_FALSE;
00093                         }
00094                 gePath_GetTimeExtents(Path, &StartTime, &EndTime);
00095                 gePath_Sample(Path, StartTime + Controller->LastTime, &XForm);
00096 
00097                 geWorld_SetModelXForm(World, Controller->Model, &XForm);
00098                 
00099                 Controller->LastTime = (geFloat)fmod(Controller->LastTime + DeltaTime, EndTime - StartTime);
00100 
00101                 Entity = geEntity_EntitySetGetNextEntity(Set, Entity);
00102         }
00103 
00104         return GE_TRUE;
00105 }

Generated on Tue Sep 30 12:36:01 2003 for GTestAndEngine by doxygen 1.3.2