Almost Done, Still Stuck on Node Movement Interpolation
Almost Done, Still Stuck on Node Movement Interpolation
hello again. I am almost done with my scene: I have a 3rd-person camera(I used the TCam code), I can put down more than 1 mesh, and I have keyboard response. However, the one thing I do not have so far is smoothing out node movement, like from the Ch.4 example.
That's where I'm totally stuck. I have tried: createFlyStraightAnimator (crashed the program on start when I got it to compile), Speed= Distance* Time (can't figure out how to initialize Time, I have the Class, but the compiler keeps b***ing on me about something with variables when I put in the variable time), and I even experimented a little with Bitplane's equation:
vector3df oldposition = ship->getPosition();
vector3df newposition;
newposition = oldposition + whatever;
ship->setPosition(newposition); .
My version of his code:
vector3df moveForward = Arwing->getPosition();
moveForward.X += 2.0f;
vector3df newposition;
newposition = moveForward;
Arwing->setPosition(newposition);
I skipped on the 'oldposition + whatever' cuz Dev-CPP kept telling me 'no match for operator 'operator +' in 'moveforward + 2.0e+0'. I also have no idea what to add, though the math stuff is catching on.
I'm out of ideas here. If there are any other ways to do the same thing, tell me so, or if I'm doing something wrong with my current code, tell me so, I'll be very very grateful.[/u]
That's where I'm totally stuck. I have tried: createFlyStraightAnimator (crashed the program on start when I got it to compile), Speed= Distance* Time (can't figure out how to initialize Time, I have the Class, but the compiler keeps b***ing on me about something with variables when I put in the variable time), and I even experimented a little with Bitplane's equation:
vector3df oldposition = ship->getPosition();
vector3df newposition;
newposition = oldposition + whatever;
ship->setPosition(newposition); .
My version of his code:
vector3df moveForward = Arwing->getPosition();
moveForward.X += 2.0f;
vector3df newposition;
newposition = moveForward;
Arwing->setPosition(newposition);
I skipped on the 'oldposition + whatever' cuz Dev-CPP kept telling me 'no match for operator 'operator +' in 'moveforward + 2.0e+0'. I also have no idea what to add, though the math stuff is catching on.
I'm out of ideas here. If there are any other ways to do the same thing, tell me so, or if I'm doing something wrong with my current code, tell me so, I'll be very very grateful.[/u]
If you have not looked at the source for CSceneNodeAnimatorFlyStraight, you might want to. As you know, it does exactly what you want.
Unless you need some additional behavior, the first thing that I'd try to do would be to figure out why you couldn't get the fly straight animator working. Obviously using pre-existing code is much easier to do than to write your own from scratch.
Unless you handle time, the characters will move at different speeds based on the frame rate. This is a bad thing. What you want to do is specify the velocity that the character is moving and apply elapsed time to get the distance moved...
This is the simplest way to get the distance based on velocity and time, called Euler integration. There are many other methods, but this one usually works for simple systems.
Travis
Unless you need some additional behavior, the first thing that I'd try to do would be to figure out why you couldn't get the fly straight animator working. Obviously using pre-existing code is much easier to do than to write your own from scratch.
Unless you handle time, the characters will move at different speeds based on the frame rate. This is a bad thing. What you want to do is specify the velocity that the character is moving and apply elapsed time to get the distance moved...
Code: Select all
// calculate the elapsed time in fractional seconds since last call
irr::u32 Now = Device->getTimer()->getTime();
irr::f32 Time = (Now - Then) / 1000.f;
Then = Now;
core::vector3df Velocity(10.f, 0.f, 0.f); // meters per second or m/s
core::vector3df Position = Arwing->getPosition();
core::vector3df Delta = Velocity * Time; // m/s * s = m
Position += (Velocity * Time); // update your position
Airwing->setPosition(Position);
Travis
In order to know how much time has elapsed, you need to know when you started and the current time. In my sample code, Now is the current time and Then is the start time.
It needs to be set to Device->getTimer()->getTime() before you execute the movement code for the first time, probably in the constructor for whatever class this code goes into.
Again, I'm going to try to encourage you to try to figure out the CSceneNodeAnimatorFlyStraight class. It seems to do what you need.
Travis
It needs to be set to Device->getTimer()->getTime() before you execute the movement code for the first time, probably in the constructor for whatever class this code goes into.
Again, I'm going to try to encourage you to try to figure out the CSceneNodeAnimatorFlyStraight class. It seems to do what you need.
Travis
OK, I've just tried out making a utility library from your suggestion, the CSceneNodeAnimatorFlyStraight Class. I copied and pasted what was online from the Irrlicht-Spintz documentation site, and put it into Dev-Cpp. However, I'm having some trouble here: I have also tried my hand at making a couple other custom utility libraries by changing around "ISceneManager" and "ISceneNodeAnimator" in order to include CSceneNodeAnimatorFlyStraight. I saved them in separate files, of course(in fear of messing up the original files), and included them at the top of my file like so:
#include "CSceneNodeAnimatorFlyStraight.h"
#include <ISceneNodeAnimator_Custom.h>
#include <ISceneManager_Custom.h>
Samples of of my code, with errors:
ISceneNodeAnimator_Custom* smgr=0;
*error: expected constructor, destructor, or type conversion before '*' token, expected `,' or `;' before '*' token
ISceneNodeAnimator_Custom* anim = smgr->CSceneNodeAnimatorFlyStraight(Arwing->
getAbsolutePosition(), moveForward, 1000, false, Now);
*error: `ISceneNodeAnimator_Custom' undeclared (first use this function), 'ISceneManager' has no member named 'CSceneNodeAnimatorFlyStraight'
I think I'm starting to catch onto this customized libraries thing a bit, but I don't know what I'm doing wrong here. I also took a good look at the CSceneNodeAnimatorFlyStraight code, and I like its parameters.
Any other suggestions, or solutions?
#include "CSceneNodeAnimatorFlyStraight.h"
#include <ISceneNodeAnimator_Custom.h>
#include <ISceneManager_Custom.h>
Samples of of my code, with errors:
ISceneNodeAnimator_Custom* smgr=0;
*error: expected constructor, destructor, or type conversion before '*' token, expected `,' or `;' before '*' token
ISceneNodeAnimator_Custom* anim = smgr->CSceneNodeAnimatorFlyStraight(Arwing->
getAbsolutePosition(), moveForward, 1000, false, Now);
*error: `ISceneNodeAnimator_Custom' undeclared (first use this function), 'ISceneManager' has no member named 'CSceneNodeAnimatorFlyStraight'
I think I'm starting to catch onto this customized libraries thing a bit, but I don't know what I'm doing wrong here. I also took a good look at the CSceneNodeAnimatorFlyStraight code, and I like its parameters.
Any other suggestions, or solutions?
The flystraight animator is easy to implement.
The first vector is the start point, the second is the stop point, and the last numbers is the speed, and the bool is for looping.
Code: Select all
scene::ISceneNodeAnimator* anim;
scene::IAnimatedMeshSceneNode* node;
node = smgr->addAnimatedMeshSceneNode(
smgr->getMesh("media/elev.dmf"));
node->setPosition(core::vector3df(0.0f,-50.0f,50.0f));
node->setMaterialFlag(video::EMF_LIGHTING, false); // disable dynamic lighting
node->getMaterial(0).Shininess = 20.0f; // set size of specular highlights
anim = smgr->createFlyStraightAnimator(vector3df(0.0f,0.0f,50.0f),
vector3df (0.0f,-1090.0f,50.0f),100000, false);
node->addAnimator(anim);
anim->drop();
Last edited by MikeR on Tue Jan 24, 2006 3:38 am, edited 1 time in total.
If it exists in the real world, it can be created in 3d
Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
Alright, I have just tried out the 'createFlySceneNodeAnimator' thingy again in my IEvent Receiver(Keless's tutorial). The code is mostly compiled, save for an error below:
*include files, other Irrlicht stuff*
scene::ISceneNodeAnimator* smgr=0; //get Scene Manager before game loop
scene::ISceneNodeAnimator* flyto; //hopefully fly the Arwing
*IEvent Receiver would be right here, this code below*
case KEY_KEY_W: {
irr::u32 Time = device->getTimer()->getTime(); //initialize time
vector3df moveForward = Arwing->getAbsolutePosition();
moveForward.X += 2.0f;
flyto = smgr->createFlyStraightAnimator(
Arwing->getAbsolutePosition(), moveForward, Time, false);
Arwing->addAnimator(flyto);
flyto->drop(); }
Error: 'class irr::scene::ISceneNodeAnimator' has no member named 'createFlyStraightAnimator'
don't know what I'm doing wrong here...I just looked in the ISceneNodeAnimator's library, didn't find anything about the 'createFlyStraightAnimator', although tutorials have it featured...what to do now, since I'm giving this code another shot?
*include files, other Irrlicht stuff*
scene::ISceneNodeAnimator* smgr=0; //get Scene Manager before game loop
scene::ISceneNodeAnimator* flyto; //hopefully fly the Arwing
*IEvent Receiver would be right here, this code below*
case KEY_KEY_W: {
irr::u32 Time = device->getTimer()->getTime(); //initialize time
vector3df moveForward = Arwing->getAbsolutePosition();
moveForward.X += 2.0f;
flyto = smgr->createFlyStraightAnimator(
Arwing->getAbsolutePosition(), moveForward, Time, false);
Arwing->addAnimator(flyto);
flyto->drop(); }
Error: 'class irr::scene::ISceneNodeAnimator' has no member named 'createFlyStraightAnimator'
don't know what I'm doing wrong here...I just looked in the ISceneNodeAnimator's library, didn't find anything about the 'createFlyStraightAnimator', although tutorials have it featured...what to do now, since I'm giving this code another shot?