1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
package com.didigame.acariaempire.battle;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.View;
import javax.media.j3d.ViewPlatform;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
import com.sun.j3d.utils.behaviors.keyboard.KeyNavigatorBehavior;
import com.sun.j3d.utils.behaviors.mouse.MouseBehavior;
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import com.sun.j3d.utils.behaviors.mouse.MouseTranslate;
import com.sun.j3d.utils.behaviors.mouse.MouseZoom;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.universe.ViewingPlatform;
public class BattleCamera {
private BattleView battleView;
private Point3d centerPosition;
private Point3d currentPosition;
public BattleCamera( BattleView battleView )
{
this.battleView = battleView;
//Set camera max distance
double cameraDepth = 2 * battleView.getSceneDepth();
View view = battleView.getUniverse().getViewer().getView();
view.setBackClipDistance( cameraDepth );
centerPosition = new Point3d( battleView.getSceneWidth() / 2.0, 150, battleView.getSceneDepth() / 2.0 );
currentPosition = new Point3d( 0, 0, 0 );
initKeyCatcher();
initMouseCatcher();
initialPosition();
}
private void initKeyCatcher() {...}
public void initMouseCatcher() {...}
private void initialPosition()
{
ViewPlatform viewPf = battleView.getUniverse().getViewingPlatform().getViewPlatform();
viewPf.setViewAttachPolicy( View.NOMINAL_SCREEN );
walkAroundCenter( 0.0,300.0, 0.0 );
}
private void setCameraPosition( double x, double y, double z )
{
ViewingPlatform viewingPf = battleView.getUniverse().getViewingPlatform();
TransformGroup vpGroup = viewingPf.getMultiTransformGroup().getTransformGroup(0);
Transform3D vpTranslation = new Transform3D();
vpTranslation.setTranslation( new Vector3d( x, y, z ) );
vpGroup.setTransform(vpTranslation);
currentPosition = new Point3d( x, y, z );
}
private void rotateCamera( )
{
ViewingPlatform viewingPf = battleView.getUniverse().getViewingPlatform();
TransformGroup vpGroup = viewingPf.getMultiTransformGroup().getTransformGroup(1);
Transform3D rotation = new Transform3D();
rotation.lookAt( centerPosition, currentPosition, new Vector3d(0,1,0));
vpGroup.setTransform( rotation );
}
public void walkAroundCenter( double x, double y, double z )
{
//Translation
setCameraPosition( x, y, z );
rotateCamera();
}
} |
Partager