Kevin
Member
|
Creating animations in code
Hi,
I want to add a helicopter to my game, which rotors are rotating.
So I added a skelton to my heli model, and weight painted it.
Now I created a Helicopter class in my game, the model is shown correctly, and the skeleton, too (if I draw it).
But if I want to rotate the rotor0 nothing happens...
Where do I have to manipulate the bone, in update or in animate?
Code:
bool Helicopter::update() {
EE::AxisRoll rotor=cskel.getBone("rotor0").rot;
rotor.axis.y += Tm.d() * 5.0f;
cskel.updateMatrix(MatrixIdentity)
.updateVelocities();
return __super::update();
}
regards,
Kevin
|
|
12-28-2009 12:22 AM |
|
menajev
Member
|
RE: Creating animations in code
You make new AxisRoll:
EE::AxisRoll rotor=cskel.getBone("rotor0").rot
You should use reference:
EE::AxisRoll &rotor=cskel.getBone("rotor0").rot
(I use references seldom, could be bug in this code, but you should get around)
|
|
12-28-2009 11:33 AM |
|
Kevin
Member
|
RE: Creating animations in code
(12-28-2009 11:33 AM)menajev Wrote: You make new AxisRoll:
EE::AxisRoll rotor=cskel.getBone("rotor0").rot
You should use reference:
EE::AxisRoll &rotor=cskel.getBone("rotor0").rot
(I use references seldom, could be bug in this code, but you should get around)
It doesn't work either (that was what I had written before I changed it to this)...
I forgot to mention, that the helicopter is a Game::Chr.
Any other suggestions?
|
|
12-28-2009 12:27 PM |
|
Chris
Member
|
RE: Creating animations in code
Can't you do the same as in the Manual Editing animation tutorial?
Code:
Bool Update()
{
// set animations
{
cskel.clear().animate(L"../data/anim/walk.anim",Tm.time());
Orient &head=cskel.getBone("head").orn;
head*=Matrix3().setRotateZ(Tm.time()*100.0f);
cskel.updateMatrix(MatrixIdentity) // update all matrixes
.updateVelocities(); // update all bone velocities
}
return true;
}
Change head to the blades bone.
|
|
12-28-2009 12:50 PM |
|
Kevin
Member
|
RE: Creating animations in code
Thanks for you help, but that's what I tested first -> it didn't worked...
There is not much code in my Helicopter class yet so I'll post it:
Helicopter.h
Code:
struct Helicopter : Game::Chr
{
Helicopter(Str routeName) {
route = Game::World.getWaypoint(routeName);
mesh = Meshs("obj/vehicle/blackhawk/0.mesh");
cskel.create("obj/vehicle/blackhawk/0.skel", 1);
}
bool update();
void draw();
//Members:
Game::Waypoint* route; //The route the heli will be flying
};
Helicopter.cpp
Code:
#include "stdafx.h"
#include "Helicopter.h"
bool Helicopter::update() {
Orient &rotor=cskel.getBone("rotor0").orn;
rotor*=Matrix3().setRotateZ(Tm.time()*100.0f);
cskel.updateMatrix(MatrixIdentity) // update all matrixes
.updateVelocities(); // update all bone velocities
return __super::update();
}
void Helicopter::draw() {
__super::draw();
cskel.draw(GREEN);
}
Do I have to create some sort of idle animation for the heli?
//Edit: After creating the idle animation (where nothing happens) it works!
(This post was last modified: 12-28-2009 01:23 PM by Kevin.)
|
|
12-28-2009 01:11 PM |
|
menajev
Member
|
RE: Creating animations in code
Quote://Edit: After creating the idle animation (where nothing happens) it works!
Probaly in __super::update(); there is cskel.clear() code.
I'm not sure, but i think there is somewhere some Bool variable which defines, if skeleton should be cleared.
|
|
12-28-2009 01:33 PM |
|