Sign in to follow this  
mcguile25

Map Editor question -- moving objects with mouse

Recommended Posts

I'm working on a map editor for my 3D game and I've got a quick question. I've got picking working so my meshes get highlighted once the mouse hovers over the mesh. So that's all good. Next I've got object activation working so when you click the highlighted mesh, it gets "activated" and you can then place the mesh elsewhere in the world by clicking somewhere in the world. Now that's where my question comes. Right now I'm using D3DXVec3Unproject to unproject the current mouse location and then (for simplicity's sake) placing the object at this location. This works fine, but it places the model directly in the user's face. Not sure how else to explain what's going on. I know this isn't how I should be placing objects on mouseclick -- is there a better way? I know I'm on the right path with D3DXVec3Unproject, but I know I'm missing a step to make the object moving more accurate.

Share this post


Link to post
Share on other sites
Yes. I'm just brainstorming here. I'd like to theoretically place objects on top of any other objects, say, for example, placing a crate on top of a crate, or placing a barrel on top of a high cliff (that's not on the ground terrain). So I think I have to find where the activated object intersects with another object (and highlight that new object so the user knows where it will be going once they click)?

Share this post


Link to post
Share on other sites
What you could do is this. Draw the users currently selected mesh or object or whatever at the position of the mouse, exactly where it would be placed if the user painted it right then and there. Also, make the object very transparent so the user can see behind and around the area where the object will be placed. This will provide a preview of where the object will be placed in the scene before they actually click the mouse and do it.

Now to determine where the object would be placed at any given time is to do like you said:

1) Create your picking ray.
2) Determine where it intersects the terrain.
3) Find out what object(s) the ray intersects.
4) Sort the objects (if mutliple) by distance to the camera.
5) Determine if the object were placed on top of the highest intersected object would intersect with any other object (this could happen depending on the camera's position).
6) Draw the current object on top of the highest of all the objects considered.

You also may need to implement some simple physics to determine of the object can be placed on top another object in certain way (i.e. more than half of the object is hanging off an edge, this would cause it to fall provided it had a consistant density).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this