Vector Math and Irrlicht help needed

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
i-Silver
Posts: 3
Joined: Mon Mar 22, 2004 9:27 am

Vector Math and Irrlicht help needed

Post by i-Silver »

I'm trying to make a tech demo for a yet unannounced project I'm doing in Irrlicht. I'm having difficulties with using vector mathematics in Irrlicht. Specifically, I can't just ADD to the magnitude of a vector2d<T>. I mean, does that mean I have to copy the vector, normalize, then multiply by the amount I want, then add it? Or should I just crunch the math by myself, and work on the x and y components of the vector2d<T>?

Basically, I'm trying to make spaceships fly in zero-g environments. I want every hit of a key to give it more acceleration. Right now, the only thing I'm using for the movement direction and speed is a single vector. Is that wise or not? I mean, it'll be a lot less to serialize :)
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

I dont know if I understand your problem right but normaly its totaly ok to use one vector for direction and speed of movement of object since it is a vector. Of course you need position of object in space, which is origin of that vector.

I think best is to vork on xyz coordinates of vector.

here are some functions I use to control object which is changing its position and direction in x/z coordinates excluding y ...like car on flat surface.

Code: Select all

void playerObject::turn_right()
{
   vector3df r = node->getRotation();
   r.Y = r.Y + turnrate;
   node->setRotation(r);
}

void playerObject::turn_left()
{
   vector3df r = node->getRotation();
   r.Y = r.Y - turnrate;
   node->setRotation(r);
}

void playerObject::move(float distance)
{
   vector3df r = node->getRotation();
   vector3df v = node->getPosition();
   v.X = v.X + sin(r.Y*0.01745) * distance;
   v.Z = v.Z + cos(r.Y*0.01745) * distance;
   node->setPosition(v);
}
Guest

Post by Guest »

Thanks. Definitely helped.
Post Reply