This excerpt takes you through the process of creating a simple actor(in this case a cube). This tutorial was created
and donated by Chris Whitman.
geActorDef *ADef;
geActor *Actor;
geBody *ABody;
geXForm3d Transform; // XForm to be filled with identity matrix
geVec3d V1,V2,V3,V4,V5,V6,V7,V8,N1,N2,N3,N4,N5,N6; // Points and Normals
int BIndex; // Index to the single bone
int MatIndex; // Material (Just white in this case)
geFloat Size=5.0f;
ABody=geBodyCreate(); // Initialize body data
geXForm3d_SetIdentity(&Transform); // Set Identity matrix
// Create the Bone
geBody_AddBone(ABody,GE_BODY_ROOT,"Bone1",&Transform,&BIndex);
// The second parameter to geBody_AddBone is the parent index,
// If no parent is used just specify GE_BODY_ROOT (which is -1)
// Create a white material
geBody_AddMaterial(ABody,NULL,NULL,255.0,255.0,255.0,&MatIndex);
// The second parameter would normally be the filename of the texturemap
// the third would be the name of the alpha map
// Lets set up all the vertices for our cube
geVec3d_Set(&V1,0.0f,0.0f,0.0f);
geVec3d_Set(&V2,Size,0.0f,0.0f);
geVec3d_Set(&V3,Size,Size,0.0f);
geVec3d_Set(&V4,0.0f,Size,0.0f);
geVec3d_Set(&V5,0.0f,0.0f,Size);
geVec3d_Set(&V6,Size,0.0f,Size);
geVec3d_Set(&V7,Size,Size,Size);
geVec3d_Set(&V8,0.0f,Size,Size);
// Set up normals
geVec3d_Set(&N1,0.0f,0.0f,1.0f); // Front
geVec3d_Set(&N2,0.0f,1.0f,0.0f); // Top
geVec3d_Set(&N3,1.0f,0.0f,0.0f); // Right
geVec3d_Set(&N4,0.0f,0.0f,-1.0f); // Back
geVec3d_Set(&N5,0.0f,-1.0f,0.0f); // Bottom
geVec3d_Set(&N6,-1.0f,0.0f,0.0f); // Left
// Now Create the cube front. I'm not including texture coords seeing
// as they are unnecessary.
// You could add them if you wanted though.
geBody_AddFace(ABody,&V1,&N1,0.0f,0.0f,BIndex,
&V2,&N1,0.0f,0.0f,BIndex,
&V3,&N1,0.0f,0.0f,BIndex,
MatIndex);
geBody_AddFace(ABody,&V1,&N1,0.0f,0.0f,BIndex,
&V3,&N1,0.0f,0.0f,BIndex,
&V4,&N1,0.0f,0.0f,BIndex,
MatIndex);
// Now add the top
geBody_AddFace(ABody,&V5,&N2,0.0f,0.0f,BIndex,
&V6,&N2,0.0f,0.0f,BIndex,
&V2,&N2,0.0f,0.0f,BIndex,
MatIndex);
geBody_AddFace(ABody,&V5,&N2,0.0f,0.0f,BIndex,
&V2,&N2,0.0f,0.0f,BIndex,
&V1,&N2,0.0f,0.0f,BIndex,
MatIndex);
// right
geBody_AddFace(ABody,&V2,&N3,0.0f,0.0f,BIndex,
&V6,&N3,0.0f,0.0f,BIndex,
&V7,&N3,0.0f,0.0f,BIndex,
MatIndex);
geBody_AddFace(ABody,&V2,&N3,0.0f,0.0f,BIndex,
&V7,&N3,0.0f,0.0f,BIndex,
&V3,&N3,0.0f,0.0f,BIndex,
MatIndex);
// back
geBody_AddFace(ABody,&V6,&N4,0.0f,0.0f,BIndex,
&V5,&N4,0.0f,0.0f,BIndex,
&V8,&N4,0.0f,0.0f,BIndex,
MatIndex);
geBody_AddFace(ABody,&V6,&N4,0.0f,0.0f,BIndex,
&V8,&N4,0.0f,0.0f,BIndex,
&V7,&N4,0.0f,0.0f,BIndex,
MatIndex);
// bottom
geBody_AddFace(ABody,&V4,&N5,0.0f,0.0f,BIndex,
&V2,&N5,0.0f,0.0f,BIndex,
&V7,&N5,0.0f,0.0f,BIndex,
MatIndex);
geBody_AddFace(ABody,&V4,&N5,0.0f,0.0f,BIndex,
&V7,&N5,0.0f,0.0f,BIndex,
&V8,&N5,0.0f,0.0f,BIndex,
MatIndex);
// left
geBody_AddFace(ABody,&V5,&N5,0.0f,0.0f,BIndex,
&V1,&N5,0.0f,0.0f,BIndex,
&V4,&N5,0.0f,0.0f,BIndex,
MatIndex);
geBody_AddFace(ABody,&V5,&N5,0.0f,0.0f,BIndex,
&V4,&N5,0.0f,0.0f,BIndex,
&V8,&N5,0.0f,0.0f,BIndex,
MatIndex);
geActor_DefCreate(ADef);
geActor_SetBody(ADef,ABody);
Actor=ge_ActorCreate(ADef);