PDA

View Full Version : Getting XZ Coords in VS for Textur



DerTherion
10-31-2010, 08:10 AM
hello @all,

i got an hopefully simple question.

ok, how to describe the problem:

i render an object and need inside the
vertexshader the X and Z Position
including transformation and rotation.

For example an chessboard.. if you move an box
over the board ,the top of the box got the same texture(coords)
like the chessboard direct under the box (the sides dosn't matter)

gl_Vertex.xz ... perfect..but only tranformation and Rotation is missing

gl_Position = gl_ModelViewProjectionMatrix * gl_Pos;
gl_Position.xz = ->brings me strange results

what can i do?

david_f_knight
10-31-2010, 12:43 PM
You didn't describe what you mean by "strange results," so you make anyone trying to answer your question have to guess what your problem is.

You used the phrase "including transformation and rotation" in your fourth paragraph (and essentially again in the sixth paragraph). What do you mean by transformation? Do you really mean translation? Rotation is a transformation. So is perspective projection.

I'm guessing what you don't like is the projection transform which you have applied to your computation of gl_Position. If you want a version of your X and Z coordinates but without the perspective transformation applied to them, then separate your modelview and projection transforms, and save the X and Z coordinates between your application of them.

DerTherion
11-01-2010, 09:40 AM
at moment i do this:

java/jogl2

...
gl.glPushMatrix();
gl.glTranslatef(tree_x[i]-view_map_x,tree_y[i],tree_z[i]-view_map_z);

// submit the 2d rotation matrix of the object

gl.glUniform1fARB(rx1 , (float) (1*Math.sin((tree_r1[i]+90+(itest1*90))*3.141593/180)) );
gl.glUniform1fARB(rz1 , (float) (1*Math.cos((tree_r1[i]+90+(itest1*90))*3.141593/180)) );
gl.glUniform1fARB(rx2 , (float) (1*Math.sin((tree_r1[i]+0+(itest1*90))*3.141593/180)) );
gl.glUniform1fARB(rz2 , (float) (1*Math.cos((tree_r1[i]+0+(itest1*90))*3.141593/180)) );

//submit the transform position in space
gl.glUniform1fARB(po_x , tree_x[i]-view_map_x);
gl.glUniform1fARB(po_z , tree_z[i]-view_map_z);

gl.glRotatef(tree_r1[i],0,1,0);
int iii=2000+tree_a[i];
gl.glCallList(iii);
gl.glPopMatrix();
...

-------------------

vs:
...
"po.x=((gl_Pos.x*rx1)+(gl_Pos.z*rx2))+po_x;\n" +
"po.y=((gl_Pos.x*rz1)+(gl_Pos.z*rz2))+po_z;\n" +

"gl_TexCoord[3].xy= vec2(po.xy-posi_start)*posi_vv;\n" +
...

its a bit dirty and i think not
the best for a good performance, but its working
(the problem could be when i want to rotate the
object at X/Z Axis)

could be cool if i could get the object data
including rotation and tranform inside
the vs direct