Placing model based on mouse position
Placing model based on mouse position
I have looked through the search, as well as the documentation and simply can't figure out a method to placing a model based on the the mouse coordinates. Can anyone explain a simple way of determining the mouse coordinates and placing a model based on those coordinates?
sample
Getting a mouse position on 2D
Code: Select all
position2d<s32> mouse_pos = Device->getCursorControl()->getPosition();
Ok, so if thats a way as to obtaining the 2d coordinates how can I take the x and y position from their? This is how I assume I would place the model so far:
Or is their another way to determine the coordinates? What I'm trying to achieve is moving the model through the mouse coordinates while the left mouse button is down, once it is lifted the model will be placed at that position.
Code: Select all
position2d<s32> mouse_pos = device->getCursorControl()->getPosition();
Model->setPosition(vector3df(?, ?, ?));
-
renegadeandy
- Posts: 122
- Joined: Sun May 25, 2008 11:14 pm
- Location: Scotland
- Contact:
thats what I have been doing for a while now , look for my threads in this Beginners help forum - most are relevant!
you want to basically :
sent out a ray from your mouses position
set the objects position on the intersection of the ray and terrain model
Check out the collision detection example to find out how to do the collision & ray stuff.
you want to basically :
sent out a ray from your mouses position
set the objects position on the intersection of the ray and terrain model
Check out the collision detection example to find out how to do the collision & ray stuff.
Game development blog: http://www.valleyattack.upsetpc.com/
-
Jgoldnight
- Posts: 31
- Joined: Thu Jun 07, 2007 6:23 pm
- Location: New York
- Contact:
If you set the object's position as the intersection between the ray and terrain, all your objects will be placed along the terrain, which is restrictive.
My current algorithm includes setting the selected object as a child of the camera (when the left mouse is held down), thus, allowing the selected node to move along with the mouse (accounting for both translation and rotation). The problem that I am finding is that when you release the mouse button, the obvious thing to simulate "releasing" the node, would be to remove the parent-child relationship. Unfortunately, Irrlicht's implementation of setParent() involves removing the calling node from the scene completely. I am still thinking of how to bypass this handicap (besides modifying the engine).
In short, this method will give the effect of moving a node around the world, but the releasing code needs to be reworked.
Hope it helps.
My current algorithm includes setting the selected object as a child of the camera (when the left mouse is held down), thus, allowing the selected node to move along with the mouse (accounting for both translation and rotation). The problem that I am finding is that when you release the mouse button, the obvious thing to simulate "releasing" the node, would be to remove the parent-child relationship. Unfortunately, Irrlicht's implementation of setParent() involves removing the calling node from the scene completely. I am still thinking of how to bypass this handicap (besides modifying the engine).
In short, this method will give the effect of moving a node around the world, but the releasing code needs to be reworked.
Hope it helps.
Computer scientist by day...
http://www.mrjoelkemp.com
http://www.mrjoelkemp.com
This is quite possibly what he wants.Jgoldnight wrote:If you set the object's position as the intersection between the ray and terrain, all your objects will be placed along the terrain, which is restrictive.
This will happen only if you call node->setParent(0) or if the parent pointer you pass to setParent() is a pointer to a node that is not in the scene graph.Unfortunately, Irrlicht's implementation of setParent() involves removing the calling node from the scene completely. I am still thinking of how to bypass this handicap (besides modifying the engine).
One option you have is to reparent the scene node to the root scene node. Unless some other parent node is specified, a scene node is a child of the scene graphs root scene node. You can get that scene node from the scene managers getRootSceneNode() method. So you could write node->setParent (smgr->getRootSceneNode()) to make node a child of the root scene node. The other solution, which could be considered to be more robust, would be to cache a pointer to the node parent before you call setParent() the first time. Then, when you are done moving the node you would set the parent back to the previous parent.
One problem that you will run into here is that when you reparent a node, it changes the nodes absolute transformation. So you need to modify its relative transformation to make the node appear in the same place after reparenting it.
Travis
-
Jgoldnight
- Posts: 31
- Joined: Thu Jun 07, 2007 6:23 pm
- Location: New York
- Contact: