a problem of logic with the cursor and a line3D

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
didi

a problem of logic with the cursor and a line3D

Post by didi »

Hello,

in the example TechDemo, we have this code :

Code: Select all

core::vector3df start = camera->getPosition();
core::vector3df end = (camera->getTarget() - start);
end.normalize();
end = start + (end * camera->getFarValue());

core::triangle3df triangle;

core::line3d<f32> line(start, end);
the line, is the line of the camera; but i want a line wich start with the vector3df of a node (it's easy), but the end must with the postion cursor (x,y); how i can make that ?
I want that the line3d begin with the position of the Node, and go with the position of the cursor, and not with the targetCamera..

sorry for my bad english, i am french..
Manakel

Post by Manakel »

Send it to me in french and i'll try to work on it


(French also from Orleans)


PS: mail is woody ####66####g#####tele2.fr

(en enlevant ce qu'il faut ...)
didi

Post by didi »

alors en francais ce sera plus clair lol

Voila dans le code que j' ai montré (tiré de Techdemo), il y a une particule qui est tiré lorsque l' on clique sur la souris. Mais : cette particule part de la position de départ de la camera (start = camera->getPosition()) et continu sa trajectoire en fonction de ce que regarde la camera (camera->getTarget() - start). Or moi je voudrais que :
la particule parte de la position d' un node (node->getPosition()), et se dirige en fonction de la position en X et Y de la souris lorsque le joueur a cliqué.. tu vois ?
en gros je crois k' il faudrais transformé mon position2d du curseur, en vector3df ..
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

There's a function called getVectorFromScreenCoords or something like that, you use that to find a ray going from the cursor out into the world.
justiceforall

Post by justiceforall »

I also have the same problem ,and i don't know how to resolve , who konw how to do it,help me,thanks!
justiceforall

getVectorFromScreenCoords.....

Post by justiceforall »

Tyn wrote:There's a function called getVectorFromScreenCoords or something like that, you use that to find a ray going from the cursor out into the world.
but i cann't find the " getVectorFromScreenCoords or something like that", do u tell me the details.thanks.
Mindl
Posts: 16
Joined: Wed Jun 30, 2004 1:42 am

getRayFromScreenCoordinates

Post by Mindl »

The function you want is the getRayFromScreenCoordinates in the ISceneCollisionManager class. http://irrlicht.sourceforge.net/docu/cl ... er.html#a3
I've yet to work with it, but it creates a line3d which starts just infront of the camera at the coordinates of the mouse to the farValue of the camera.

-Mindl
justiceforall

Re: getRayFromScreenCoordinates

Post by justiceforall »

Mindl wrote:The function you want is the getRayFromScreenCoordinates in the ISceneCollisionManager class. http://irrlicht.sourceforge.net/docu/cl ... er.html#a3
I've yet to work with it, but it creates a line3d which starts just infront of the camera at the coordinates of the mouse to the farValue of the camera.

-Mindl
thanks . but how can i get the postion in game world using this function ?
if you know that , can u tell me the main process to do it?
sorry ,my english is poor, but i like Irrlicht , want to learn more about it .
Zann
Posts: 17
Joined: Sat May 29, 2004 6:25 am

Post by Zann »

Code: Select all

triangle3df colTri;
vector3df colPoint;
line3d<f32> line;
line = m_sceneMgr->getSceneCollisionManager()->getRayFromScreenCoordinates(m_device->getCursorControl()->getPosition(), m_camera);

if(m_sceneMgr->getSceneCollisionManager()->getCollisionPoint(line, m_selector, colPoint, colTri)){

// collision with the selector was found and location put into colpoint
}
That has worked for me. Then just do the same thing with the line going from your character to colPoint to find collisions between them and the spot clicked.
Mindl
Posts: 16
Joined: Wed Jun 30, 2004 1:42 am

Works like a charm

Post by Mindl »

Yep, tried the above out and it works like a charm.

-Mindl
Mindl
Posts: 16
Joined: Wed Jun 30, 2004 1:42 am

Kind of an annoying problem

Post by Mindl »

I've implemented the code for the collision of the ray sent out from the camera where the mouse is located. I've got a plane with a scene node for the sydney model located on it. Then I have a camera behind and above the model looking down at it with about a 45 degree angle. When I choose a spot on the middle and bottom of the screen, the ray collides with a point on the plane right below the mouse pointer. However, when you move the cursor away from the bottom middle to anywhere else on the screen, the spot on the plane where the collision occurs is not located where the mouse cursor is. I did a survey of the pixels verses the change in units at different areas of the screen. Here is some of what I got from doing that. Lets say I have a collison point from a ray that I originated from the mouse coordiantes 1,1. Then I move the mouse to 2,1. With the camera looking down the X axis, this new ray will change the Z position of the colision by 2.4 units. With a Y position of the mouse at 767 the change in units from a previous spot will be only .662 units. The change in the X position of the colision point based on the mouse position is almost proportional to the Z change, but to a smaller extent only 1.113 units near the top of the screen and .467 units at the bottom. The changes are consitent along the horizontal of the screen, so its 2.4 units no matter where on the X the mouse is as long as the Y is 1. I thought it might be caused by having the camera angled the way it is, but when I moved the camera to 90 degrees above the sydney model, the problem was still there, but to a slightly lesser degree.
I've been combating this by having the collison point scaled by a certain amount based on where the cursor is on the screen, but its not very exact and I just doesn't feel right. I hope I didn't confuse anyone with my ramblings, if you need me to describe it better I'll try. Has anyone else encountered and overcome this? If anyone has a more elegant solution to this than I've been trying please let me know. I'll post the code I am using now if anyone needs me too, but I'm at work right now without the code. Any help is appreciated.

:idea: As I was writing this I had a thought about it maybe being my FOV for this camera. But i am at work and can't see how changing the FOV back to the default will effect it.

-Mindl
Post Reply