thothbot / parallax

Cross-platform Java 3D SDK
http://thothbot.github.io
MIT License
84 stars 26 forks source link

Is there a way to convert screen coordinates to world coordinates ? #90

Open andnovar opened 8 years ago

andnovar commented 8 years ago

I was wondering whether AnimatedScene or camera have a way to know the world position once you click on the screen coordinates. Something like this in Unity --> http://docs.unity3d.com/ScriptReference/Camera.ScreenToViewportPoint.html

Thanks in advance

thothbot commented 8 years ago

Hey,

please take a look at https://github.com/thothbot/parallax/blob/master/tests/parallax-tests/src/org/parallax3d/parallax/tests/cases/interactivity/InteractiveVoxelPainter.java

that may help you

andnovar commented 8 years ago

Hey thanks for the quick response. I think perhaps it could be convenient to add this to the API to give the camera a ScreenToViewportPoint method.

andnovar commented 8 years ago

What about if you don't have objects to RayCast or if you want to place it on an empty space ?

thothbot commented 8 years ago

Yeah, ok, lets track the enhancement

thothbot commented 8 years ago

Yeah, in example sent you this code creates a new cube after mouse click

Mesh voxel = new Mesh( cubeGeo, cubeMaterial );
voxel.getPosition().copy( intersect.point ).add( intersect.face.getNormal() );
voxel.getPosition().divide( 50.0 ).floor().multiply( 50.0 ).add( 25.0 );
scene.add( voxel );
andnovar commented 8 years ago

Hi Alex, yes,it does but it needs to intersect something. I am working it around creating an invisible plane to intersect with. I am doing like a 3d editor.

thothbot commented 8 years ago

yep, it is good idea