All - I'm still stuck on this freaking animation. I can't seem to make this work at all. I tried to leverage just the animation tutorial and that didn't work since it doesn't use obj types to get data from the world manager at all.
I decided to just work with the horse files and modify them into a mob file (again using my worm model as a base).
I update all the header files I could find that needed to be updated. Then I created a mob_test.h and .cpp file. No matter what I try, I can't seem to even get the f*ing mob to show up in the game, even though it's in the world editor, and build all etc...
Any clues?
here's my file data:
Code:
/******************************************************************************/
enum OBJ_TYPE // Game Object Type
{
OBJ_STATIC , // static
OBJ_KINEMATIC , // kinematic
OBJ_ITEM , // item
OBJ_CHR , // character
OBJ_MOB , // Mob
OBJ_PLAYER , // player
OBJ_HORSE , // horse
OBJ_VEHICLE , // vehicle
OBJ_DOOR , // door
OBJ_LIGHT_POINT , // point light
OBJ_LIGHT_CONE , // cone light
OBJ_PARTICLES , // particles
OBJ_DECAL , // decal
OBJ_MESH_OVERLAY, // mesh overlay
OBJ_LAMP , // lamp
OBJ_TORCHIERE , // torchiere
OBJ_FIREBALL , // fireball
};
/******************************************************************************/
from game.cpp
Code:
Game::ObjMemx<Static > Statics;
Game::ObjMemx<Kinematic > Kinematics;
Game::ObjMemx<Door > Doors;
Game::ObjMemx<Item > Items;
Game::ObjMemx<Torchiere > Torchieres;
Game::ObjMemx<AI > AIs;
Game::ObjMemx<Player > Players;
Game::ObjMemx<Horse > Horses;
Game::ObjMemx<Mob > Mobs;
Game::ObjMemx<Fireball > Fireballs;
Game::ObjMemx<ObjLightPoint> ObjLightPoints;
mob_test.h:
Code:
/******************************************************************************/
STRUCT(Mob , Game::Obj)
//{
MeshPtr mesh ;
CSkeleton cskel;
Controller ctrl ;
Ragdoll kinematic_ragdoll;
Reference<Chr> rider;
Flt angle,angle_offset;
Flt stand_run,turn;
Vec2 dir;
// manage
virtual void create(Game::ObjParams &obj);
void createKinematicRagdoll();
// get / set
virtual Vec pos ( );
virtual Matrix matrix( );
virtual void pos (C Vec &pos );
virtual void matrix(C Matrix &matrix) {pos(matrix.pos);}
// callbacks
virtual void memoryAddressChanged();
virtual void linkReferences();
// update
virtual Bool update();
// operations
virtual void emitSound(Str name, Flt range=1, Flt volume=1);
// draw
virtual UInt drawPrepare();
virtual void drawShadow ();
// enable / disable
virtual void disable();
virtual void enable();
// io
virtual void save(File &f);
virtual Bool load(File &f);
Mob();
};
/******************************************************************************/
mob_test.cpp:
Code:
/******************************************************************************/
#include "stdafx.h"
#include "Main.h"
/******************************************************************************/
CSkeleton cskel;
/******************************************************************************/
Mob::Mob()
{
angle=0;
angle_offset=0;
stand_run=0;
turn=0;
dir.zero();
}
void Mob::createKinematicRagdoll()
{
kinematic_ragdoll.create (cskel,1,true ) // create the helper ragdoll as kinematic
.group (AG_KINEMATIC_RAGDOLL ) // set desired actor group
.ray (false ) // disable ray-testing
.obj (this ) // set game object owner
.fromSkel(cskel,cskel.vel(),true); // use 'true' for immediate pose setting at creation time, to ensure that the pose will be set immediately, please read comments on 'fromSkel' method for more information about it
}
void Mob::create(Game::ObjParams &obj)
{
mesh=obj.mesh (); //if(!mesh)Exit("Horse doesn't have mesh");
Skeleton *skel=obj.skeleton(); //if(!skel)Exit("Horse doesn't have skel");
PhysBodyPtr phys=obj.phys ();
cskel.create(skel,obj.scale(),obj.matrixFinal());
//cskel.create(Skeletons("../data/obj/chr/critter/worm/worm.skel"));
createKinematicRagdoll();
Flt r=1, h=2;
Vec pos=obj.matrixFinal().pos;
if(phys && phys->parts.elms()>=1 && phys->parts[0].type()==PHYS_SHAPE)
{
r=phys->parts[0].shape.capsule.r;
h=phys->parts[0].shape.capsule.h;
}
ctrl.createCapsule(r,h,pos).actor.obj(this).damping(0.1f).ccd(true);
angle=Angle(obj.matrixFinal().z.xz())-PI_2;
}
/******************************************************************************/
// GET / SET
/******************************************************************************/
Vec Mob::pos ( ) {return cskel.pos ();}
Matrix Mob::matrix( ) {return cskel.matrix();}
void Mob::pos (C Vec &pos) {Vec delta=pos-T.pos(); cskel.move(delta); ctrl.actor.pos(ctrl.actor.pos()+delta);}
/******************************************************************************/
void Mob::emitSound(Str name, Flt range, Flt volume)
{
SoundPlay(name,pos(),range*2.5f,volume);
}
/******************************************************************************/
// CALLBACKS
/******************************************************************************/
void Mob::memoryAddressChanged() {ctrl.actor.obj(this); kinematic_ragdoll.obj(this);}
void Mob::linkReferences () {rider.link();}
/******************************************************************************/
// UPDATE
/******************************************************************************/
Bool Mob::update()
{
Vec2 move;
// animate
Matrix m; m.setRotateY(-angle-angle_offset).move(ctrl.actor.pos());
cskel.clear();
//cskel.animate(L"data/obj/chr/critter/worm/walk.anim", Time.time(),1-stand_run);
cskel.animate(L"data/obj/chr/critter/worm/walk.anim",Time.time());
//cskel.animate(L"data/obj/chr/critter/worm/run.anim" ,dir.y<0 ? -Time.time() : Time.time(), stand_run);
cskel.updateMatrix(m).updateVelocities();
// step sound
if(ctrl.onGround() && stand_run>0.25f && Animations("data/obj/chr/critter/worm/walk.anim")->eventOccured("step",Time.time(),Time.d()))
emitSound(S+"sound/step/material/stone/r"+Random(6)+".wav",1,0.8f);
kinematic_ragdoll.fromSkel(cskel,cskel.vel(),true);
return true;
}
/******************************************************************************/
// ENABLE / DISABLE
/******************************************************************************/
void Mob::disable() {__super::disable(); ctrl.actor.kinematic(true );}
void Mob:: enable() {__super:: enable(); ctrl.actor.kinematic(false);}
/******************************************************************************/
// DRAW
/******************************************************************************/
UInt Mob::drawPrepare()
{
if(mesh)if(Frustum(Ball().setAnimated(mesh->box,cskel)))
{
SetHighlight((Cur.obj==this && Cur.highlight) ? Color(34,85,85) : Color(0,0,0)); mesh->draw(cskel);
SetHighlight( Color(0,0,0));
}
//Meshes("../data/obj/chr/critter/worm/worm.mesh")->draw(cskel);
return 0;
}
void Mob::drawShadow()
{
if(mesh)if(Frustum(Ball().setAnimated(mesh->box,cskel)))mesh->drawShadow(cskel);
}
/******************************************************************************/
// IO
/******************************************************************************/
void Mob::save(File &f)
{
__super::save(f);
f.putStr(mesh.name());
cskel.save(f);
ctrl .save(f);
f<<angle<<angle_offset<<stand_run<<turn<<dir;
kinematic_ragdoll.saveState(f,true);
}
Bool Mob::load(File &f)
{
if(__super::load(f))
{
mesh .require(f.getStr());
cskel.load (f);
ctrl .load (f); ctrl.actor.obj(this);
f>>angle>>angle_offset>>stand_run>>turn>>dir;
createKinematicRagdoll(); if(!kinematic_ragdoll.loadState(f))return false;
return true;
}
return false;
}
/******************************************************************************/
//Bool mtInit()
//{
// cskel.create(Skeletons("../data/obj/chr/critter/worm/worm.skel")); // create controlled skeleton from skel file, with 1.7 meter height
// return true;
//}
///******************************************************************************/
//Bool mtUpdate()
//{
// // set animations
// {
// cskel.clear(); // clear controlled skeleton animation
// cskel.animate(L"../data/obj/chr/critter/worm/walk.anim",Time.time()); // animate with "walk" animation and current time position
// cskel.updateMatrix (MatrixIdentity); // update controlled skeleton animation matrixes
// cskel.updateVelocities( ); // update controlled skeleton bone velocities (this is needed for Motion Blur effect)
// }
//
// return true;
//}
///******************************************************************************/
//void mtRender()
//{
// switch(Renderer())
// {
// case RM_PREPARE:
// {
// Meshes("../data/obj/chr/critter/worm/worm.mesh")->draw(cskel); // get mesh from cache and render it with controlled skeleton matrixes
// }break;
// }
//}
//void mtDraw()
//{
// Renderer(mtRender);
//
// //if(Kb.ctrl()) // when control pressed
// //{
// // if(Renderer.rebuildDepthNeededForDebugDrawing())Renderer.rebuildDepth();
// // SetMatrix(); // restore default matrix
// // cskel.draw(RED); // draw controlled skeleton
// //}
//
// //D.text(0,0.8f,"Hold space to animate");
//}
///******************************************************************************/
... I wish there was a crying smiley ...
Edit: attached is a screenie of the object in the world editor.
update:
It's showing up now, I was missing a reference in Main.h:
BUT - now it's floating in the air around 30 feet up??? and, no animations.
Anyone?