hi there
again i have a problem. my application looks like this:
now i want that the user can view the whole scene from directly above the terrain. that means the camera should be in a perpendicular angle to the terrain. this works more or less with:
private void updateCameraPosition() {
System.out.println(chaser.getCamera().getLocation());
chaser.getCamera().setLocation(new Vector3f(TERRAIN_X/2,300,TERRAIN_Y/2));
chaser.getCamera().setDirection(new Vector3f(0,-1,0));
System.out.println(chaser.getCamera().getLocation());
}
somehow i mixed up y and z angles i think ... but on the second screenshot one can see that it is really working:
expect for the pillars which are not displayed. can someone explain me why?? thx!
do they have BoundingBoxes?
mulova
November 4, 2008, 12:05am
4
Use Camera.lookAt() instead of Camera.setDirection().
When you change direction, you should adjust up vector together.
thx i changed the code into this:
System.out.println(chaser.getCamera().getLocation());
chaser.getCamera().setLocation(new Vector3f(TERRAIN_X/2,300,TERRAIN_Y/2));
chaser.getCamera().lookAt(new Vector3f(0,-1,0), new Vector3f(0,1,0));
System.out.println(chaser.getCamera().getLocation());
now the pillars are visible, but i'm not looking at the center of the terrain, but to the point where the axis cross each other (0,0,0) i think
i also tried it with:
System.out.println(chaser.getCamera().getLocation());
chaser.getCamera().setLocation(new Vector3f(TERRAIN_X/2,300,TERRAIN_Y/2));
chaser.getCamera().lookAt(new Vector3f((TERRAIN_X/2,300,TERRAIN_Y/2)), new Vector3f(0,1,0));
System.out.println(chaser.getCamera().getLocation());
but then i can't see the terrain at all. any hints?
doens't really anybody knows an answer??
mulova
November 7, 2008, 1:31am
8
Direction, Up, Left vector should always be orthogonal.
You used up vector as UNIT_Y. That's wrong.
You can set up vector to UNIT_Y only when the direction vector is on y=0 plane
(in other words, directionVector.y = 0)
@mulova : thx i didn't know that. but whats the better solution?
mulova
November 10, 2008, 12:28am
11
I can't understand your last post becase of the lack of my english.
I will just say about my solution about camera rotation.
When I rotate camera, I get Quaternion for rotating cam direction
And multiply it to up vector.
extracting Quaternion for cam direction is from Game Programming Gems
/**
*
@param start
* normalized vector
@param end
* normalized vector
@param store
@return
*/
public static Quaternion getRotationNormalized0(final Vector3f start, final Vector3f end, final Quaternion store) {
Vector3f temp = new Vector3f();
// Game Programming Gems
start.cross(end, temp);
final float d = start.dot(end);
if (d == -1) {
store.fromAngleAxis(FastMath.PI, Vector3f.UNIT_Y);
} else {
final float s = FastMath.sqrt((1 + d) * 2);
store.x = temp.x / s;
store.y = temp.y / s;
store.z = temp.z / s;
store.w = s / 2f;
}
return store;
}