Hi there!

I have just started to use GLSL and i currently have general problems in understanding matrix-operations. It’s years ago, when i had to work with matrices. So i have a newbie question concerning gl_ModelViewProjectionMatrix.

Background:

My idea (or some kind of experiment) is, to use the vertex-shader as “object-generator” - which is more flexible than static C-code. A huge part already works fine.

In the C-part of my program, i just generate a flat rectangle with x and y between 0 and 1 (with variable resolution) and z=0. In the vertex-shader i use x and y as sources to generate objects like ie. simply a torus.

Also normal-vectors are already calculated correct by the shader.

My problem is the object-positioning. For C-generated objects, i used “gl_Position = ftransform()”, which i cant use in this case.

Using gl_ModelViewProjectionMatrix i get correct rotations but - somehow - translations are lost. So my torus can be rotated by calling glRotatef() in the C-part of the program, but glTranslatef() doesn’t have any effect.

Here is the relevant vertex-shader-code (some function are shortened):

```
varying vec4 Vertex;
varying vec3 Normal;
vec4 rotateX (vec3 v, float a) {...}
vec4 rotateY (vec3 v, float a) {...}
vec4 rotateZ (vec3 v, float a) {...}
vec3 NormalVec(vec4 p, vec4 vX, vec4 vY) {...}
vec4 Torus(vec2 pos) {
vec4 v = vec4 (0.0, 0.0, 0.1, 0.0);
v = rotateY (v, pos.y * 2.0) + vec3(0.0, 0.0, 0.25);
v = rotateX (v, pos.x * 2.0);
return v;
}
void main () {
vec4 t1 = Torus(vec2(gl_Vertex));
vec4 t2 = Torus(vec2(gl_Vertex) + vec2(0.0, 0.01));
vec4 t3 = Torus(vec2(gl_Vertex) + vec2(0.01, 0.0));
Normal = NormalVec(t1, t2, t3);
t1 = t1 * gl_ModelViewProjectionMatrix;
Vertex = vec4(t1.x, t1.y, t1.z, 1);
gl_Position = Vertex;
}
```

Anyone knows why tranlations are lost??

Regards,

Frank