I have this obj files (also tried with other, more 3d models):
Triangle
v 0 0 0
v 0 0.5 0
v 1 0 0
f 1 2 3
I use the following vertexshader:
uniform mat4 projection;
attribute vec4 pos;
void main(void)
{
gl_Position = projection* pos;
}
Super simple. If I run it with just uniform_Projection = identity matrix I see a triangle, 0.5 up and 1 to the right. Seems right.
Now, what I want to do is to use a camera ala gluLookAt aswell as some perspective projection. And this is where I get so confused.
In world coordinates, the triangle is located at the vertex positions above. So lets pick an eye and a lookat point. eye = (0,0,3), lookAt = (0,0,0). Basically we want the eye to be at the origin. So we have to move the world origin to the eye position (lets do it even if it is the identity matrix):
| 1 0 0 0 | | 1 0 0 0 | | 1 0 0 0 |
| 0 1 0 0 | * | 0 1 0 0 | = | 0 1 0 0 |
| 0 0 1 -3| | 0 0 1 0 | | 0 0 1 -3|
| 0 0 0 1 | | 0 0 0 1 | | 0 0 0 1 |
And boom, the triangle is gone.. And all I did was moving the world along the direction the original camera was looking. eye = (0,0,3) still gone.. Super confused :S I have turned off any form of culling etc. Can someone explain to me how this works?
Because later my idea was the following:
v = normalize(lookat-eye)
r = normalize(crossProduct(v, up));
u = crossProduct(r, v);
viewMatrix = |r1 r2 r3 -eye1|
|u1 u2 u3 -eye1|
|v1 v2 v3 -eye1|
|0 0 0 1 |
And as a projection matrix I was thinking either (from my lectures):
projMatrix = |1 0 0 0|
|0 1 0 0|
|0 0 1 0|
|0 0 -1/d 1|
Or this link: gluPerspective was removed in OpenGL 3.1, any replacements? Can't say I quite understand any of them right now.
Well to me it seems I don't understand some key parts of how the coordinate systems works.