Mesh outline

Blitz3D Forums/Blitz3D Programming/Mesh outline

Moraldi(Posted 2007) [#1]
Hi,
Is there any QUICK way to detect if mouse lies inside an entity's outline?

Thanks


Ross C(Posted 2007) [#2]
Well, you COULD do constant CameraPick(), and check to see if it returns the mesh your after. Could be costly though. If you only do a camerapick every other frame that might help, or only when the mouse button is clicked.


Moraldi(Posted 2007) [#3]
Sorry, but I forgot to mention I want to avoid using any picking functions


Naughty Alien(Posted 2007) [#4]
maybe if you using some physics lib and do picking, it can help without performance loss, while checking every frame..


Moraldi(Posted 2007) [#5]
Thanks guys


Matty(Posted 2007) [#6]
Yes there is:hide all objects other than the entity in question, make it a certain color other than black, render the scene without displaying it and read the pixel color at the mouse coords. You will need to copy the backbuffer to an image or texture to do this.


Ross C(Posted 2007) [#7]
Ok, here goes... Now, don't see any reason why this shouldn't work.

Hide everything in your scene except your entity you want to check. Colour it pure red. Make the sure the backround is pure black. Render the scene. Copy the scene to an IMAGE.

Then, you can either:

Check the mousex and y position on the image, and see if it's a red pixel underneath, or

Do an imageoverlap call, using the 2d commands. Make sure the mask for the image is set to RGB(0,0,0). This should be fairly quick to check. Only slow part is the copyrect. Since your copying to an image, you can't use the VRAM flag. I'm not 100% sure, but i don't think you can.


Moraldi(Posted 2007) [#8]
Very clever, but I have to try both to see if these methods are slow. Consider that I have to do this when the mouse button licked


big10p(Posted 2007) [#9]
Why can't you use a pick? A single pick every time the mouse is clicked isn't going to represent any serious kind of bottleneck, surely?


Ross C(Posted 2007) [#10]
Yeah i agree with Big10p. It's by far the easiest way and as big10p says it's not going to cost you any CPU time, just doing a pick when the mouse is clicked. That's what camerapick is designed for really :o)


Moraldi(Posted 2007) [#11]
I have several meshes laying on a 3D world. I want to have a 3D cursor over any selected mesh and move them with the mouse. Because Blitz3D does not provide any method to 'unproject' 2D mouse coordinates to 3D space I need to find a way when dragging a mesh from a 3D cursor handle to move the mesh exactly where the mouse points. The only way to do this is to have a plane making picks on as the mouse moving. But what happens when the selected mesh is being moving behind another?
Answer:
My linepick action on the plane is broken from the front mesh
Note all meshes are pickable also because I want to select them any time...
That's why I decided to find another way to select meshes without need to make them pickable


Ross C(Posted 2007) [#12]
What i did in my editor, was to record the movement of the mouse and apply it to the mesh, based on how close the camera was to the mesh. Works very well :o)

Also, why not just use a 2d cursor?


Moraldi(Posted 2007) [#13]
I read an excellent example from BlitzsSupport:
http://www.blitzbasic.com/codearcs/codearcs.php?code=379
but unfortunately the code above works perfect only when the mesh is moving along the X and Y axes of the camera.
DirectX provides a very useful function to 'unproject' 2D screen coordinates to 3D and I think in the next version/update of Blitz3D it would be a very useful addition.
In other words I would like to have a function to cast a ray from any point on screen and give me 3D coordinates of its intersection with a plane in any distance and orientation specified be me.

About the 3D cursor: Because if you use a 2D cursor how to move the mesh in the third direction?


jhocking(Posted 2007) [#14]
Years ago I wrote a function based on that one from the code archives that moves an object on the ground plane instead of a plane parallel to the camera. Lemme see if I can dig that up...

ADDITION: Here's the function I wrote
;Positions an entity in 3D from given 2D coordinates
Function PositionEntityFrom2D(usecam,entity,x2d#,y2d#,height#=0,camZoom#=1)
	gw=GraphicsWidth()
	gh=GraphicsHeight()
	x#=-((gw/2)-x2d)
	y#=(gh/2)-y2d
	parent=GetParent(entity)
	EntityParent entity,usecam
	z#=Abs(EntityZ(entity))
	div#=(gw/(2/camzoom))/z
	x=x/div
	y=y/div
	
;z distance determined by a straight line from camera, through xyz coordinates, to height
	TFormPoint x,y,z,usecam,0
	y3d#=height
	x3d#=TFormedX()
	z3d#=TFormedZ()
	EntityParent entity,parent
	PositionEntity entity,x3d,y3d,z3d
End Function


That still doesn't get you movement along any arbitrary plane, just the ground, but it wouldn't be hard to modify this function to do what you want. In particular, note that TFormPoint (which is the real heart of this calculation) is transforming from the camera's coordinate system to the world. I think if you pass in a different plane as one of the parameters for the function, you can transform from the camera's coordinate system to that plane.


Moraldi(Posted 2007) [#15]
Thanks jhocking. I will test your code and If I have something better then I 'll let you know!