Hello there.
Im tryng to make a normal camera, focusing its view on a physical object. The camera moves as the physical object moves. The physical object moves changes directions as camera rotates, with this :
[java]if (IO.left) {
mapControl.getDude().getWalkDir().addLocal(camLeft);
} else
if (IO.right) {
mapControl.getDude().getWalkDir().addLocal(camLeft.negate());
}[/java]
Now, the ‘glitch’ ive seen is, whenever i rotate the camera when im moving the character, it gets glitchy and it seems it doesnt render right, gets a little laggy, or the object a little bit out of center.
The tricky part is: the camera has aceleration for rotation.
This is my camera class code:
[java]/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package theDungeon;
import com.jme3.input.ChaseCamera;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;
import com.jme3.scene.CameraNode;
import com.jme3.scene.Node;
import com.jme3.scene.control.CameraControl.ControlDirection;
/**
*
-
@author Ziden
*/
public class RoundCamera {
private final CameraNode camNode;
private final int camDistance = 20;
private float angle;
private Character target;
public RoundCamera(Camera cam, Character dude) {
camNode = new CameraNode("CamNode", cam);
camNode.setControlDir(ControlDirection.SpatialToCamera);
camNode.setLocalTranslation(new Vector3f(camDistance/3, camDistance, camDistance/3));
dude.getModel().attachChild(camNode);
camNode.lookAt(dude.getModel().getLocalTranslation(), Vector3f.UNIT_Y);
target = dude;
changeAngle();
}
private float angleAceleration = 0;
private final float maxSpeed = 0.05f;
public void acelerate(int dir) {
if(dir==9 && angleAceleration < maxSpeed) {
angleAceleration+=0.001f;
System.out.println("OI");
}
else if(dir==7 && angleAceleration > -maxSpeed)
angleAceleration-=0.001f;
changeAngle();
}
public void deacelerate() {
if(angleAceleration!=0) {
if(angleAceleration > 0) {
angleAceleration -= 0.001f;
if(angleAceleration<0) angleAceleration = 0;
}
else if(angleAceleration < 0) {
angleAceleration+=0.001f;
if(angleAceleration > 0) angleAceleration = 0;
}
changeAngle();
}
}
public void changeAngle() {
angle += angleAceleration;
// formula da bola
angle %= FastMath.TWO_PI;
camNode.setLocalTranslation(FastMath.cos(angle) * camDistance, camDistance, FastMath.sin(angle) *camDistance);
camNode.lookAt(target.getControl().getPhysicsLocation(), Vector3f.UNIT_Y);
}
}
[/java]
Am i doing something wrong ? It seems so simple to me but it doesnt work right
I think now ive may be in the wrong way. Ive tryed to use ChaseCamera but i couldnt change how it worked to fit the way i intend to. It rotates right, does everything right, but generates that laggy render.
Thank you alot for your time and patience, and for any help for soure
PS : My computer is a very good one so he aint the problem, 2gb video card.