LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Lotho on June 15, 2014, 11:31:47

Title: Slight error using gluLookat
Post by: Lotho on June 15, 2014, 11:31:47
I've recently started programming with lwjgl.
I've built a house and now I'm trying to render a view looking straight onto the center of the roof, but with current configuration it's slightly off.



As you can see in the image the edges on the roof aren't perfetly straight which would be the case if I was looking straight to the center from a point on the roof normal vector. I'm using gluLookAt to get the view, using the following code:

gluLookAt(house.getRoofCenter().x + house.getRoofNormal().x * 0.25f,
        house.getRoofCenter().y + house.getRoofNormal().y * 0.25f,
        house.getRoofCenter().z + house.getRoofNormal().z * 0.25f,
                        house.getRoofCenter().x, house.getRoofCenter().y, house.getRoofCenter().z, 0.0f, 1.0f, 0.0f);


And for the normals:
Vector3f.sub(p2, p1, a);
Vector3f.sub(p3, p1, b);
Vector3f.cross(a, b, c);
roofNormal = new Vector3f(-c.x, -c.y, -c.z);


and center:
roofCenter = new Vector3f((p3.x + p1.x) / 2, (p3.y + p1.y) / 2, (p3.z + p1.z) / 2);

My question is: Is this due to errors in the rendering methods or is my math off?
Any suggestions for solutions?