Sign in to follow this  
  • entries
    45
  • comments
    44
  • views
    50131

Skinned mesh code part 5 - implementation example 2

Sign in to follow this  
Norman Barrows

1039 views

Skinned mesh code part 5 - implementation example 2

another implementation example from caveman 3.0:

this is the actual code that draws band members and NPCs in the game now.

void draw_caveman2(int a){// a is animal #int n;// n is npc #location f;// npc location for frustum cullint rad;// rad is NPC cliprad for frustum cullint ani;// ani is ani # to playint clothtex;// clothtex is the texture for loincloth and brafloat x,y,z;// x y z is the camera relative coordinates of the npcfloat yr;// yr is the y rotation to use for drawing the caveperson// === do frustum cull ===rad=6;f.mx=animal[a].mx;;f.mz=animal[a].mz;;f.x=animal[a].x;;f.z=animal[a].z;;f.y=heightmap(f.mx,f.mz,f.x,f.z);if (superclip4(&f,rad,animal_cliprng)) { return; }// === set npc # ====n=animal[a].butchered;// === set ani # ===ani=controller_pool[npc[n].controllerID].curani;// === set cloth texture ===// 159 = light hideclothtex=159;// === set world mat ====Mstart();camera_relative_coords(animal[a].mx,animal[a].mz,animal[a].x,animal[a].z,&x,&z);y=heightmap(animal[a].mx,animal[a].mz,animal[a].x,animal[a].z);if ((!animal[a].alive)&&(!animal[a].falling)) {// c deadani a MrotateRADS(1,pi); MrotateRADS(2,1.5f); y+=0.5f; }else { MrotateRADS(0,animal[a].xr); yr=animal[a].yr+pi; if (yr > pi*2.0f) { yr-=pi*2.0f; } MrotateRADS(1,yr); MrotateRADS(2,animal[a].zr); }Mmove(x,y,z);// === draw it ! ====draw_skinmesh_caveman(npc[n].sex,npc[n].hairmeshID,npc[n].skintexID,npc[n].hairtexID,npc[n].eyetexID,clothtex,ani,npc[n].controllerID,0.066,&Mmat);} void draw_bandmember2(int a){// a is bandmember #location f;// bandmember location for frustum cullint rad;// rad is bandmember cliprad for frustum cullint ani;// ani is ani # to playint clothtex;// clothtex is the texture for loincloth and brafloat x,y,z;// x y z is the camera relative coordinates of the bandmemberfloat yr;// yr is the y rotation to use for drawing the bandmember// === do frustum cull ===rad=6;f.mx=cm[a].mx;;f.mz=cm[a].mz;;f.x=cm[a].x;;f.z=cm[a].z;;f.y=heightmap(f.mx,f.mz,f.x,f.z);if ((a != cm0) || (cm[a].location != UPATREE)) // dont clip current bandmember when upatree {if (superclip4(&f,rad,animal_cliprng)) { return; } }// === set ani # ===ani=controller_pool[cm[a].controllerID].curani;// === set cloth texture ===// 159 = light hideclothtex=159;// === set world mat ====Mstart();camera_relative_coords(cm[a].mx,cm[a].mz,cm[a].x,cm[a].z,&x,&z);y=heightmap(cm[a].mx,cm[a].mz,cm[a].x,cm[a].z);if ((!cm[a].alive)&&(!cm[a].falling)) {// c deadani a MrotateRADS(1,pi); MrotateRADS(2,1.5f); y+=0.5f; }else { MrotateRADS(0,cm[a].xr); yr=cm[a].yr+pi; if (yr > pi*2.0f) { yr-=pi*2.0f; } MrotateRADS(1,yr); MrotateRADS(2,cm[a].zr); }Mmove(x,y,z);// === draw it ! ====draw_skinmesh_caveman(cm[a].sex,cm[a].hairmeshID,cm[a].skintexID,cm[a].hairtexID,cm[a].eyetexID,clothtex,ani,cm[a].controllerID,0.066,&Mmat);} // called from initprog:init_controller_pool();load_all_skinned_meshes(); // called at program shutdown:deactivate_all_controllers();unload_all_skinned_meshes(); // called when an NPC is added to the simulation:npc[npcID].controllerID=activate_controller(npc[npcID].skinmeshID);set_sm_npc_ani(a,ANI_STAND); // called when an NPC is removed from the simulation:c=npc.controllerID;deactivate_controller(c);
Sign in to follow this