picking node by relative cursor position

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
zzino
Posts: 7
Joined: Fri Feb 27, 2004 6:44 am
Location: Toronto

picking node by relative cursor position

Post by zzino »

This may sounds weird, but I am trying to pick up node
by cursor's relative position.

To understand my question, you might need to know what I am doing.

I implemented my camera in 2 mode..
1) walking(move front/back/strafe)
and panning(look up/down,turn left/right)
--> this is simply FPS mode without keyboard.

2) drag and drop mode
(you can pick up some stuff and move)
--> disabled FPS mode(Camera will be in the same position)

# Note: I cannot use keyboard, so I am switching two mode by clicking
mouse RButton. and my cursor is not locked in the middle of the screen.

OK!!!! Here goes my question.
Let's say...there is an object(box) in the room(bigger box).


it will look like this..
--------------------------------------
^
room


____ x <--- mouse pointer
|___|\
|___| |
|___|/

^
object(box)
--------------------------------------

Can I detect if mouse cursor is on the object..??

This is how I navigate and pan only with mouse.

Code: Select all

               // navigate and pan by mouse(cursor) position

	//  +----------------------+
	//  |   |      10      |   |
	//  |---+--------------+---|
	//  |   |  1 | 2  | 3  |   |
	//  |   |--------------|   |
	//  | 11|  4 | 5  | 6  | 12|
	//  |   |--------------|   |
	//  |   |  7 | 8  | 9  |   |
	//  |---+--------------+---|
	//  |   |      13      |   |
	//  +----------------------+
	//  navigation  (area 1~9)
                //  1 : move_forward + strafe_left
	//  2 : move_forward
	//  3 : move_forward + strafe_right
	//  4 : strafe_left
	//  5 : stop
	//  6 : strafe_right
	//  7 : move_backward + strafe_left
	//  8 : move_backward 
	//  9 : move_backward + strafe_right
	//  panning (area 10 ~ 13)
	//  10 / 13 : look up /down (until 90 degree and come back after panning mode)
	//  11 / 12 : turn left / right (it will turn and stay) 
Thanks
Yesterday is history.
Tomorrow is a mystery.
Today is a gift. That's why it's called the "present."
zzino
Posts: 7
Joined: Fri Feb 27, 2004 6:44 am
Location: Toronto

I think I found the answer from this forum

Post by zzino »

getRayFromScreenCoordinates may do this job..

there was almost same question in this forum.

Thanks
Yesterday is history.
Tomorrow is a mystery.
Today is a gift. That's why it's called the "present."
Mercior
Posts: 100
Joined: Tue Feb 24, 2004 1:53 am
Location: UK
Contact:

Post by Mercior »

Theres an even better function to help you!

Code: Select all

if (event.EventType == irr::EET_MOUSE_INPUT_EVENT && event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
	{
		ISceneNode *hax = smgr->getSceneCollisionManager()->getSceneNodeFromScreenCoordinatesBB(core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y));
		if (hax)
                                 do something.......
Mercior
Posts: 100
Joined: Tue Feb 24, 2004 1:53 am
Location: UK
Contact:

Post by Mercior »

Small note: I think you will have to assign a triangle selector to each scene node that you want to be "clickable".. a bounding box one would probably be best for your situation.
zzino
Posts: 7
Joined: Fri Feb 27, 2004 6:44 am
Location: Toronto

Thanks for your advices

Post by zzino »

Thanks for your help!

I have finished picking up a node and I made it move using this code

Code: Select all

//picking up some node
selectedSceneNode = 
     smgr->getSceneCollisionManager()->getSceneNodeFromScreenCoordinatesBB(cursorPosition);

//move object 
selectedSceneNode->setPosition(newPosition);
Now,
(1) I want to drag an object(node) accross the screen using mouse.
---> so I need to know what is the newPosition.

Code: Select all

//let's say this is the room
----------------------------------------
\
 \
  \___________________________
   |
   |     
   |                dragging
   |     [ x ] ----------------> [ x ]
   |     ^                           ^
   |     old position             new position
   |
   |
-----------------------------------------
//  x    <---- mouse pointer
// [  ]  <--- object


(2) Could anyone give me advice about how to detect collision between two objects?
(Billiards and 3D pong would be a good example to explain my question.)

Thank you for help!
Yesterday is history.
Tomorrow is a mystery.
Today is a gift. That's why it's called the "present."
Serg Nechaeff
Posts: 162
Joined: Wed Nov 26, 2003 5:24 pm
Location: Europe

Post by Serg Nechaeff »

Code: Select all

Billiards and 3D pong would be a good example to explain my question
i was checking the distance between the centers of the pong balls, so there is no need to involve expensive collision detection techniques.
http://www.javazing.com
P-III-950, WinXP, GeForce FX5600 128 MB ForceWare 52.16, DX9, Eclipse IDE, JRE 1.6
zzino
Posts: 7
Joined: Fri Feb 27, 2004 6:44 am
Location: Toronto

oh...maybe I made wrong example

Post by zzino »

Thanks for your reply!

I think pong and billiards were not a good example.
In my game objects doesn't have same size or shape.

Let's imagine a room with book shelf and table.
in the book shelf, there are some books.
on the floor, there are some balles and toys.
there might be some stuffs on the table as well.

I want them to be picked up by mouse and will be moved by mouse dragging.
if you release object on the air it will drop on the floor.
(with gravity, little bit of bouncing back would be better for reality)

any advice will be appriciate.
Thanks
Yesterday is history.
Tomorrow is a mystery.
Today is a gift. That's why it's called the "present."
Mercior
Posts: 100
Joined: Tue Feb 24, 2004 1:53 am
Location: UK
Contact:

Post by Mercior »

You'll probably find its faster & better looking to use a physics SDK that try to code box-mesh collision and the appropriate response yourself.

Try my newton tutorial: http://www.mercior.com/tut-newton.shtml
Post Reply