four questions associated with camera-enemy interaction

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
Elazul
Posts: 38
Joined: Fri Mar 23, 2007 4:47 pm

four questions associated with camera-enemy interaction

Post by Elazul »

1- I know through the tutorials, that the code to collide with an enemy using a normal fps camera is basically using this
core::line3d<f32> line;
line.start = camera->getPosition();
line.end = line.start + (camera->getTarget() - line.start).normalize() * 1000.0f;
thing is, my virtual lines start from a cursor on screen, so how would i modify that, so that the line starts or passes through the cursor point on screen?

2- i was wondering if this equation would be right for an enemy Aggro radius:
aggro_distance =30
current distance =| |enemyposition| - |playerposition| |
if (current_distance<=aggro_distance)
enemy attacks player
3- is there an equation like camera->getposition(); that returns the position of an enemy(model) ? and if so, what variable type does it return?

4- assuming i'm going to be projecting a lazer beam effect from the cursor point, to the model, assuming i'm going to use a bitmap texture or so, how would i scale it to make it grow smaller the further it goes and while i'm at it, make it not draw past the model it collides with?

thanks in advance.
thanks in advance.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

1. You can use the ISceneCollisionManager::getRayFromScreenCoordinates() method along with the ICursorControl::getPosition() functions to get a line from the camera through the mouse cursor.

2. You need to use the absolute position of both scene nodes and the vector3d<T>::getDistanceFrom() or even better getDistanceFromSQ() method.

Code: Select all

static const f32 aggroDistanceSQ = 30.f * 30.f;

f32 seperationSQ = enemy->getAbsolutePosition().getDistanceFromSQ( player->getAbsolutePosition() );
if (seperationSQ < aggroDistanceSQ)
{
  // attack!
}
3. Yes, node->getAbsolutePosition() returns the 3d position of node as a vector3df.

4. You don't need to scale it at all. You just need to display the billboard or particle system at the intersection point of the ray and the scene node. I believe that the collision example does this already.


Travis
Elazul
Posts: 38
Joined: Fri Mar 23, 2007 4:47 pm

Post by Elazul »

thanks

1- the main problem with point number 1 is i have 2 cursors on screen, not one....

4- so i should make a thin lazer line as a billboard?

btw, is it at all possible to explain to me how to make a custom camera using a custom event handler (not irrlicht based) , no one seems to know...
Elazul
Posts: 38
Joined: Fri Mar 23, 2007 4:47 pm

Post by Elazul »

1. You can use the ISceneCollisionManager::getRayFromScreenCoordinates() method along with the ICursorControl::getPosition() functions to get a line from the camera through the mouse cursor.
i tried using the following code :
core::line3d<f32> line;
core::position2df RightMousePosition(RvX,RvY);
line.start = camera->getPosition();
line.end = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(RightMousePosition,camera);
and it keeps telling me that it cannot convert parameter 1 from vector2df to vector2d<t> which is kinda giving me a headache, what the hell should i be typecasting RightMousePosition as then?

edit:

when i change the above code to :

core::line3d<f32> line;
core::position2d<s32> RightMousePosition(rightX,rightY);
line.start = camera->getPosition();
line.end = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(RightMousePosition,camera);
it now gives me an error that there is no operand "=" for this data type....
please, i need ANY help on this.

i'm assuming once i get it, it should be very very easy to calculate collision using the same exact code in the tutorials, right?
vitek wrote: 4. You don't need to scale it at all. You just need to display the billboard or particle system at the intersection point of the ray and the scene node. I believe that the collision example does this already.


Travis
so what if i want to project a lazer beam from for example the bottom left corner of the screen to the point that the cursor is aiming at?
mehwoot
Posts: 7
Joined: Tue Jul 17, 2007 7:54 am

Post by mehwoot »

core::line3d<f32> line;
core::position2d<s32> RightMousePosition(rightX,rightY);
line.start = camera->getPosition();
line.end = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(RightMousePosition,camera);
It worked for me using
core::line3d<f32> line = device->getSceneManager()->getSceneCollisionManager()->getRayFromScreenCoordinates(
position2d<s32>(event.MouseInput.X, event.MouseInput.Y), camera);
You need to use position2d<s32>, and also getRayFromScreenCoordinates returns a line, not a vector point.
Post Reply