3DzzD Tutorial | ||
03/03 - Basic how to control camera with mouse |
Scene overview :
|
About :
|
Root
DefaultLight DefaultCamera CUBE.3DS Camera01 CUBE |
This sample show how to rotate camera using the mouse.
change the mouse pointer... this.getScene3DRender().getRender3D().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); once loading done, move camera to put object on field of view r.getScene3D().getCurrentCamera3D().getPosition().setZ(-200); define new attributes to store camera properties double rotateX; double rotateY; double cameraZ; get direct input interface to read from mouse IDirectInput di=r.getRender3D().getDirectInput(); finally control rotation using mouse (with first button pressed) if(!di.isMouseB1()) { rotateX=r.getScene3D().getMesh3DByName("CUBE").getRotation().getX(); rotateY=r.getScene3D().getMesh3DByName("CUBE").getRotation().getY(); } else { r.getScene3D().getMesh3DByName("CUBE").getRotation().setX(rotateX+((di.getMouseY()-di.getMouseDragY())*Math.PI/200)); r.getScene3D().getMesh3DByName("CUBE").getRotation().setY(rotateY+((di.getMouseX()-di.getMouseDragX())*Math.PI/200)); } control Z translation using mouse move (with third button pressed) if(!di.isMouseB3()) { cameraZ=r.getScene3D().getCurrentCamera3D().getPosition().getZ(); } else { double distY=di.getMouseY()-di.getMouseDragY(); r.getScene3D().getCurrentCamera3D().getPosition().setZ(cameraZ+distY); } |
Compilation :
|
Runtime :
|
to compile this sample, ensure that you have java SDK properly installed and use the following command line
javac -target 1.1 -d . -classpath LIB/dzzd.jar for windows users click on the provided make file make.bat |
you can run the demo by opening the provided HTML index file on your browser
index.html to add this demo in your own web site, copy/paste the following HTML source code. <APPLET code="Sample.class" archive="LIB/dzzd.jar" width="676" height="380" MAYSCRIPT> </APPLET> |
Links :
|
|
to download this sample source code:
Sample.java to download the full tutorial package, including API and Javadoc : API25112006.ZIP for last news and last demos please visit 3DzzD web site : http://dzzd.net/ to ask and talk with other users please visit the forum: http://www.tdt3d.com/forum.php?action=vtopic&forum=25 |