moving object away from camera (or model)?
moving object away from camera (or model)?
hi,
i was surprised to see that there doesn't seem to be a function for simply moving an object "forward" (that is, in the direction it's facing - in my case, a bullet away from the camera). can anyone help? thanks!
i was surprised to see that there doesn't seem to be a function for simply moving an object "forward" (that is, in the direction it's facing - in my case, a bullet away from the camera). can anyone help? thanks!
-
- Posts: 118
- Joined: Thu Sep 18, 2003 10:05 pm
- Location: switzerland
thanks very much for the reply, but i'm still having problems getting the projectiles to move correctly. since it's easiest (with this engine) to move objects relative to their parent, i was thinking maybe an array of "dummy" nodes would work...that is, have them attached to the camera, and the projectiles attached to the dummy. then when the user shoots, detach the dummy so it stays where it was fired from, allowing me to simply move the projectile away from it. i've tried for awhile now, though, and i can't get it to work...any help is appreciated!
Another method would be to store the firing origin and use that as the start point of the line.
EG:
User presses shoot
storecurrent position of camera, and cameratarget
move projectile along the stored line coords
I think that would work..
This is what I use to store the position when I want to switch between camera locations..
EG:
User presses shoot
storecurrent position of camera, and cameratarget
move projectile along the stored line coords
I think that would work..
Code: Select all
cameraline.start = camera->getPosition();
cameraline.end = cameraline.start + (camera->getTarget()->cameraline.start).normalize() * 1000.0f;
....
Project Admin -
http://shadowrunonline.sourceforge.net
------------------------------------
There are 10 kinds of people, those that understand binary and those that don't.
http://shadowrunonline.sourceforge.net
------------------------------------
There are 10 kinds of people, those that understand binary and those that don't.
-
- Posts: 118
- Joined: Thu Sep 18, 2003 10:05 pm
- Location: switzerland
Niko has implemented a shooting function in his TechDemo
just look at the function
cool, he uses animators to make the movement.
cheers
Gorgon Z.
just look at the function
Code: Select all
CDemo::shoot();
cheers
Gorgon Z.
thanks for all the help...i'm now using the code from the techdemo (with animators), and now i'm just trying to tweak it by having the projectiles shoot from the gun model and not the middle of the screen...from what i've read,
should create a node that moves/rotates with the camera, and stays 10 units to the right, 4 units up, and 1 unit in front of the camera. it seems to be doing this, but when i change the beginning of the line i want the bullet to follow from the camera's position to the dummy node's position:
the bullets actually fly from the place i started on the level at the camera ( no matter where i go). is this a bug? it seems like strange behavior to me..
thanks again!
Code: Select all
static scene::ISceneNode *dummy = smgr->addTestSceneNode(1.0f,camera,-1,core::vector3df(10.0f,4.0f,1.0f));
Code: Select all
core::vector3df start = dummy->getPosition();
core::vector3df end = (camera->getTarget() - start);
end.normalize();
end = start + (end * camera->getFarValue());
thanks again!
-
- Posts: 118
- Joined: Thu Sep 18, 2003 10:05 pm
- Location: switzerland
I reckon the problem is that getPosition returns the relative position to the parent node ( the camera). if you take the position from the camera then the relative position is equal to the absolute one, because your camera is located at the root of the scenetree. You might try to use
cheers
GZ
Code: Select all
start=dummy->getAbsolutePosition();
dir=(camera->getTarget() - camera->getPosition()).normalize();
end=start + dir * camera->getFarValue();
GZ
Could anyone explain how to do this?Gorgon Zola wrote:direction away from camera:
vector3df vAway=camer->getTarget()-camera->getPosition();
if you want to have away direction from a normal scenenode you'll have to
define a away/forward vector in the model coordinate system and transform it with the transformation matrix of the node.
cheers
How do you
1. Define away/forward vector. I presume it's something like vector3df.set(0,0, -100) (assuming away is -100 units away on the z axis)?
2. transform it with the transformation matrix of the node? This I have no clue to how to do. Add the vector to the object's GetPosition ()?
Thanks
-
- Posts: 118
- Joined: Thu Sep 18, 2003 10:05 pm
- Location: switzerland
Sorry if I was a little vague, well, here's a more detailed explenation:t wrote: Could anyone explain how to do this?
defining the forward vector for your model is independent of irrlicht. you'll have to remember it some where in your game's Entity class:t wrote: 1. Define away/forward vector. I presume it's something like vector3df.set(0,0, -100) (assuming away is -100 units away on the z axis)?
Code: Select all
class IEntity {
public:
ISceneNode theNode;
vector3df forward;
// forward points to the direction where Your game character is looking
// I presume that the mesh of the character is initially facing towards
// position (0,0,-1) , 'looking into the camera'
vector3df getForwardDirection();
};
We want to know the direction where the character is facing to. To optain this, we'll have to transform the vector 'forward' the same way the scenenode that represents the character was transformed.t wrote: 2. transform it with the transformation matrix of the node? This I have no clue to how to do. Add the vector to the object's GetPosition ()?
Code: Select all
vector3df IEntity::getForwardDirection(){
core::matrix4 mat=theNode->AbsoluteTransformation();
return mat.translateVect(forward);
}
hope this is clearer
cheers
gorgon zola
Thanks for the response!
What is the very final step?
Also, in
it is returning a matrix but the function is defined to return a vector3df. Which should it return?
And finally, how do I apply this returned value to the entity?
Something like thiS: ?
[/code]
What is the very final step?
Also, in
Code: Select all
vector3df IEntity::getForwardDirection(){
core::matrix4 mat=theNode->AbsoluteTransformation();
return mat.translateVect(forward);
}
And finally, how do I apply this returned value to the entity?
Something like thiS: ?
Code: Select all
pos = pos + getForwardDirection(shipnode);
shipnode->setPosition(pos);
-
- Posts: 118
- Joined: Thu Sep 18, 2003 10:05 pm
- Location: switzerland
Sorry, some time I should really get some sleep
the function should return a vector, and the matrix should transform it and not 'translate' , ok the code should look something like this....
of course this is not optimal, because generating a new vector every time
you want to update the node position slows things down.
your last step look good.
the function should return a vector, and the matrix should transform it and not 'translate' , ok the code should look something like this....
Code: Select all
vector3df IEntity::getForwardDirection(){
matrix4 mat=theNode->getAbsoluteTransformation();
vector3df out;
mat.transformVect(pos,out);
return out;
}
you want to update the node position slows things down.
your last step look good.