/**
* Moves the camera around a 3d object.
* This method accepts x,y orbiting rotation, a zoom level,
* and a panning coordinate.
*
* @param model model to point camera at
* @param x x rotation
* @param y y rotation
* @param zoom zoom level
* @param mx x panning offset
* @param my y panning offset
*/
public void moveCameraAroundModel(Object3D model,float x, float y,float zoom,float mx,float my,RenderPane renderPane)
{
Camera camera = renderPane.camera;
SimpleVector center = model.getTransformedCenter();
SimpleVector oldCamPos = camera.getPosition();
SimpleVector oldestCamPos = new SimpleVector(oldCamPos);
oldCamPos.scalarMul(4f);
SimpleVector camPos = new SimpleVector(center);
Matrix cameraRotation = model.getRotationMatrix().cloneMatrix();
cameraRotation.rotateX(x);
cameraRotation.rotateY(y);
SimpleVector zOffset = cameraRotation.getZAxis();
zOffset.scalarMul(zoom);
camPos.add(zOffset);
camPos.add(oldCamPos);
camPos.scalarMul(0.2f);
SimpleVector delta = camPos.calcSub(oldestCamPos);
float len = delta.length();
if (len != 0)
camera.moveCamera(delta.normalize(), len);
center.add(new SimpleVector(mx,my,0));
camera.lookAt(center);
// camera.moveCamera(new SimpleVector(mx,my,0), 1f);
}
public void moveCameraToSide(float zoom,float mx,float my,RenderPane renderPane)
{
Camera camera = renderPane.camera;
SimpleVector center = EditorPane.defaultInstance.model.getTransformedCenter();
camera.setPosition(center);
camera.moveCamera(new SimpleVector(zoom,0,0),1f);
camera.lookAt(center);
//camera.moveCamera(new SimpleVector(0,mx,my),1f);
}
public void moveCameraToTop(float zoom,float mx,float my,RenderPane renderPane)
{
Camera camera = renderPane.camera;
SimpleVector center = EditorPane.defaultInstance.model.getTransformedCenter();
camera.setPosition(center);
camera.moveCamera(new SimpleVector(0,zoom,0),1f);
camera.lookAt(center);
//camera.moveCamera(new SimpleVector(mx,0,my),1f);
}
public void moveCameraToRear(float zoom,float mx,float my,RenderPane renderPane)
{
Camera camera = renderPane.camera;
SimpleVector center = EditorPane.defaultInstance.model.getTransformedCenter();
camera.setPosition(center);
camera.moveCamera(new SimpleVector(0,0,zoom),1f);
camera.lookAt(center);
//camera.moveCamera(new SimpleVector(mx,my,0),1f);
}
/**
* Draws a small rectangle other the vertex closest to the
* mouse cursor.
*
* @param g
* @param renderPane
*/
public void drawNearestVertex(Graphics g,RenderPane renderPane)
{
MouseMapper mouseMapper = renderPane.mouseMapper;
SimpleVector vect = getClosestVertex(
mouseMapper.getMouseX(),
mouseMapper.getMouseY(),
renderPane);
if(vect == null)
return;
SimpleVector vect2D = Interact2D.project3D2D(
world.getCamera(),renderPane.frameBuffer,vect);
if(vect2D == null)
return;
g.setColor(Color.green);
g.fillRect((int)vect2D.x-2, (int)vect2D.y-2, 4,4);
}
/**
* Draws the 3d cursor into place on a graphics context.
*
* @param g
* @param frameBuffer
*/
public void draw3DCursor(Graphics g,RenderPane renderPane)
{
SimpleVector vect = EditorPane.defaultInstance.cursor3D;
SimpleVector vect2 = EditorPane.defaultInstance.cursor3D2;
if(vect == null || vect2 == null)
return;
Camera camera = renderPane.camera;
FrameBuffer frameBuffer = renderPane.frameBuffer;
SimpleVector vect2D = Interact2D.project3D2D(camera,frameBuffer,vect);
SimpleVector vect2D2 = Interact2D.project3D2D(camera,frameBuffer,vect2);
if(vect2D == null || vect2D2 == null)
return;
g.setColor(Color.white);
g.drawRect((int)vect2D.x-2, (int)vect2D.y-2, 4,4);
g.drawRect((int)vect2D.x-4, (int)vect2D.y-4, 8,8);
MouseMapper mouseMapper = renderPane.mouseMapper;
int mouseX = mouseMapper.getMouseX();
int mouseY = mouseMapper.getMouseY();
g.drawLine(mouseX,mouseY, (int)vect2D2.x, (int)vect2D2.y);
g.drawRect((int)vect2D2.x-4, (int)vect2D2.y-4, 8,8);
}
/**
* Draws the bone structure of the skeleton onto
* a graphics context.
*
* @param g
*/
public void drawSkeleton(Graphics g,RenderPane renderPane)
{
SimpleSkeleton skeleton = EditorPane.defaultInstance.skeleton;
if(skeleton == null)
return;
List<SimpleBone> bones = skeleton.getBones();
drawBones(g,bones,renderPane);
}
private void drawBones(Graphics g,List<SimpleBone> bones,RenderPane renderPane)
{
for(SimpleBone bone : bones)
{
drawBone(g,bone,renderPane);
drawBones(g,bone.getChildren(),renderPane);
}
}
/**
* Draws a single bone, using the pivot, and
* end point vectors.
*
* @param g
* @param bone
*/
Color color = new Color(0x4d,0xef,0x92);
private void drawBone(Graphics g,SimpleBone bone,RenderPane renderPane)
{
Graphics2D g2 = (Graphics2D)g;
Stroke strokeOld = g2.getStroke();
g2.setStroke(new BasicStroke(5.0f, // Line width
BasicStroke.CAP_ROUND, // End-cap style
BasicStroke.JOIN_ROUND)); // Vertex join style
g2.setColor(color);
Camera camera = renderPane.camera;
FrameBuffer frameBuffer = renderPane.frameBuffer;
SimpleVector pivot2D = Interact2D.project3D2D(camera,frameBuffer,bone.getPivot());
SimpleVector endPoint2D = Interact2D.project3D2D(camera,frameBuffer,bone.getEndPoint());
if(pivot2D == null || endPoint2D == null)
return;
g.drawLine((int)pivot2D.x,(int)pivot2D.y,(int)endPoint2D.x,(int)endPoint2D.y);
if(((Bone)bone).endPointSelected())
g2.setColor(Color.orange);
else
g2.setColor(Color.gray);
g2.drawOval((int)endPoint2D.x-6,(int)endPoint2D.y-6, 11, 11);
if(bone.isRoot()){
if(((Bone)bone).pivotSelected() )
g2.setColor(Color.orange);
else
g2.setColor(Color.gray);
g2.drawOval((int)pivot2D.x-6,(int)pivot2D.y-6, 11, 11);
}
g2.setStroke(strokeOld);
}
/**
* Draws a background onto the framebuffer of a renderpane.
*
* @param renderFactory
*/
public void drawBackground(RenderPane renderPane)
{
FrameBuffer frameBuffer = renderPane.frameBuffer;
int width = frameBuffer.getOutputWidth();
int height = frameBuffer.getOutputHeight();
Graphics g = frameBuffer.getGraphics();
//Draw base colour.
if(EditorPane.defaultInstance.selectedRenderPane == renderPane)
g.setColor(new Color(0x00,0x25,0x0a));
else
g.setColor(new Color(0x00,0x14,0x09));
g.fillRect(0,0,width,height);
g.setColor(new Color(0x00,0x35,0x0e));
//Draw the vertical lines.
int i = 0,num = (width / 32) + 1;
while(i<num)
{
g.drawLine(i * 32,0, i * 32,height);
i++;
}
//Draw the horizontal lines.
i = 0; num = (height / 32) + 1;
while(i<num)
{
g.drawLine(0,i * 32, width,i * 32);
i++;
}
//Draw origin crosshair
g.setColor(Color.GRAY);
g.drawLine(width/2, height/2-5, width/2, height/2+5);
g.drawLine(width/2-5, height/2, width/2+5, height/2);
}
Thats everything:)