xzessmedia
Member
|
Subclassed from Game.Obj >> No Update
Hello,
maybe this is something lame, but i can't find where the problem is..
i subclassed Game.obj but my actor don't show any movement..
do you see where the problem is?
Code:
class GameObject : public Game.Obj
{
GameObject();
~GameObject();
virtual void create(Game::ObjParams &obj);
virtual Bool update(); // update, return false when object wants to be deleted, and true if wants to exist
uint drawPrepare();
void drawShadow();
SkelPoint GetMeshSlot( cchar8 *name);
Vec GetMeshSlotVec(cchar8 *name);
Vec CorrectSlotPosition(Matrix m,Vec slotpos);
Vec pos ( ) { return _matrix.pos ;} // get position
Matrix matrix ( ) { return _matrix ;} // get matrix
Matrix matrixscaled( ) { return _matrixscaled ;} // get matrix
void pos (C Vec &pos ) { _matrix.pos = pos; _matrixscaled.pos = pos; } // set position
void matrix(C Matrix &matrix) { _matrix = matrix; _matrixscaled = _matrix; _matrixscaled.scaleOrn(scale); } // set matrix, for most classes 'matrix' should be normalized
int GetObjectID() { return objectid; }
bool Alive() { return isAlive; }
bool Visible() { return isVisible; }
Actor* GetActor() { return &actor; }
PhysBodyPtr* GetPhysBody() { return &phys; }
MeshPtr* GetMesh() { return &mesh; }
Game::ObjParams* GetObjParams() { return &objdata; }
protected:
int objectid;
byte objectstate;
Matrix _matrix;
Matrix _matrixscaled;
Vec scale;
MeshPtr mesh;
MaterialPtr material;
PhysBodyPtr phys;
Actor actor;
flt angle;
flt speed;
Game::ObjParams objdata;
bool isAlive;
bool isVisible;
bool isShadow;
bool isGravity;
}
GameObject::GameObject()
{
isAlive = true;
isVisible = true;
isShadow = true;
isGravity = true;
}
GameObject::~GameObject()
{
}
void GameObject::create(Game::ObjParams &obj)
{
//super.create(obj);
T.objectid = 0;
objdata = obj;
scale = obj.scale3();
mesh = obj.mesh();
material = obj.material();
phys = obj.phys();
_matrix = obj.matrixFinal().normalize();
_matrixscaled = _matrix;
_matrixscaled.scaleOrn(scale);
angle = Angle(obj.matrixFinal().z.xz())-PI_2;
speed = 0;
if(phys)
{
actor.create(*phys, 0, scale).matrix(_matrix);
actor.obj(this);
}
}
bool GameObject::update()
{
actor.addTorque(Vec(5, 0, 0));
return isAlive;
}
uint GameObject::drawPrepare()
{
if(mesh && isVisible==true && Frustum(mesh->box, _matrixscaled))
{
MaterialLock = material();
mesh->draw(_matrixscaled);
MaterialLock = NULL;
}
return NULL;
}
void GameObject::drawShadow()
{
if(mesh && isShadow==true && Frustum(mesh->box, _matrixscaled))
{
MaterialLock = material();
mesh->drawShadow(_matrixscaled);
MaterialLock = NULL;
}
}
Vec GameObject::GetMeshSlotVec(cchar8 *name)
{
return CorrectSlotPosition(matrix(),mesh->skeleton()->getPoint(name).pos);
}
SkelPoint GameObject::GetMeshSlot( cchar8 *name)
{
return mesh->skeleton()->getPoint(name);
}
Vec GameObject::CorrectSlotPosition(Matrix m,Vec slotpos)
{
Vec ofs=Cam.matrix.z*(D.particlesSoft() ? 0 : -0.1);
return slotpos*m+ofs;
}
The GameObject::Update gets called, so the problem must be with the actor or something..
(This post was last modified: 02-12-2014 08:40 AM by xzessmedia.)
|
|
02-12-2014 08:22 AM |
|
rstralberg
Member
|
RE: Subclassed from Game.Obj >> No Update
I have no experience (yet) with the Esenthel API, but looking at your class declaration one thing strucks me.
Your constructor, destructor and some other methods below are private. Without knowing the special Esenthel things , this would make it impossible to create an instance of the GameObject. You could try with adding the public keyword before the constructor.
(This post was last modified: 02-12-2014 09:35 AM by rstralberg.)
|
|
02-12-2014 08:44 AM |
|
cat555
Member
|
RE: Subclassed from Game.Obj >> No Update
Hi, try to get the position from actor.. for example:
Code:
UInt drawPrepare ()
{
Matrix m = MatrixIdentity;
m.pos = this.actor.pos();
if(this.mesh && Frustum(mesh->box, m))
{
this.mesh->draw(m);
}
return NULL;
}
|
|
02-12-2014 11:27 AM |
|
xzessmedia
Member
|
RE: Subclassed from Game.Obj >> No Update
thank you guys, i did as you preferred, but still no update.. anymore ideas?
|
|
02-12-2014 02:13 PM |
|
Rubeus
Member
|
RE: Subclassed from Game.Obj >> No Update
You are drawing using _matrixScaled. You need to use the actor's matrix. The actor has it's own matrix that is updated by the physics engine. The one you are using in your class is never modified. cvieira was on the right track, but since you are only adding torque, it doesn't change the position.
|
|
02-12-2014 03:03 PM |
|
xzessmedia
Member
|
RE: Subclassed from Game.Obj >> No Update
thanks for any help... still no luck... this is what i have actually:
Code:
class GameObject : public Game.Obj
{
public:
GameObject();
~GameObject();
virtual void create(Game::ObjParams &obj);
virtual Bool update(); // update, return false when object wants to be deleted, and true if wants to exist
uint drawPrepare();
void drawShadow();
SkelPoint GetMeshSlot( cchar8 *name);
Vec GetMeshSlotVec(cchar8 *name);
Vec CorrectSlotPosition(Matrix m,Vec slotpos);
Vec pos ( ) { return _matrix.pos ;} // get position
Matrix matrix ( ) { return _matrix ;} // get matrix
Matrix matrixscaled( ) { return _matrixscaled ;} // get matrix
void pos (C Vec &pos ) { _matrix.pos = pos; _matrixscaled.pos = pos; } // set position
void matrix(C Matrix &matrix) { _matrix = matrix; _matrixscaled = _matrix; _matrixscaled.scaleOrn(scale); } // set matrix, for most classes 'matrix' should be normalized
int GetObjectID() { return objectid; }
bool Alive() { return isAlive; }
bool Visible() { return isVisible; }
Actor* GetActor() { return &actor; }
PhysBodyPtr* GetPhysBody() { return &phys; }
MeshPtr* GetMesh() { return &mesh; }
Game::ObjParams* GetObjParams() { return &objdata; }
protected:
int objectid;
byte objectstate;
Matrix _matrix;
Matrix _matrixscaled;
Vec scale;
MeshPtr mesh;
MaterialPtr material;
PhysBodyPtr phys;
Actor actor;
flt angle;
flt speed;
Game::ObjParams objdata;
bool isAlive;
bool isVisible;
bool isShadow;
bool isGravity;
}
GameObject::GameObject()
{
isAlive = true;
isVisible = true;
isShadow = true;
isGravity = true;
}
GameObject::~GameObject()
{
}
void GameObject::create(Game::ObjParams &obj)
{
//super.create(obj);
T.objectid = 0;
objdata = obj;
scale = obj.scale3();
mesh = obj.mesh();
material = obj.material();
phys = obj.phys();
_matrix = obj.matrixFinal().normalize();
_matrixscaled = _matrix;
_matrixscaled.scaleOrn(scale);
angle = Angle(obj.matrixFinal().z.xz())-PI_2;
speed = 0;
if(phys)
{
actor.create(*phys, 0, scale).matrix(_matrix);
actor.obj(this);
actor.group(AG_DEFAULT);
}
}
bool GameObject::update()
{
actor.addTorque(Vec(0, 10, 0));
return isAlive;
}
uint GameObject::drawPrepare()
{
if(mesh && isVisible==true && Frustum(mesh->box, actor.matrix()))
{
MaterialLock = material();
mesh->draw(actor.matrix());
MaterialLock = NULL;
}
return NULL;
}
void GameObject::drawShadow()
{
if(mesh && isShadow==true && Frustum(mesh->box, actor.matrix()))
{
MaterialLock = material();
mesh->drawShadow(actor.matrix());
MaterialLock = NULL;
}
}
Vec GameObject::GetMeshSlotVec(cchar8 *name)
{
return CorrectSlotPosition(matrix(),mesh->skeleton()->getPoint(name).pos);
}
SkelPoint GameObject::GetMeshSlot( cchar8 *name)
{
return mesh->skeleton()->getPoint(name);
}
Vec GameObject::CorrectSlotPosition(Matrix m,Vec slotpos)
{
Vec ofs=Cam.matrix.z*(D.particlesSoft() ? 0 : -0.1);
return slotpos*m+ofs;
}
|
|
02-12-2014 04:14 PM |
|
cat555
Member
|
RE: Subclassed from Game.Obj >> No Update
Well, maybe it's a silly question, but are you sure that your physics object is dynamic (density > 0.0)?
|
|
02-12-2014 04:33 PM |
|
xzessmedia
Member
|
RE: Subclassed from Game.Obj >> No Update
ok got the problem, you were right...
Code:
actor.create(*phys, 0, scale, true);
changed to
actor.create(*phys, 1, scale, false);
Thank you all for your nice support!
(This post was last modified: 02-12-2014 05:31 PM by xzessmedia.)
|
|
02-12-2014 04:50 PM |
|