Need help porting open gl to direct x shader code


The coordinate system is the problem :( . I want to get the angle between the camera and the quad. Then rotate it (works) and show a different texture depending on the viewing angle. In open gl it works but the texture are wrong in direct x.
 
I worked around this in hurrican using the CML library it has API that creates the matrix needed either for either coordinate system, maybe this works for you too.

Edit:

So i was going from D3D to OpenGL and i used:

cml::matrix_orthographic_RH( matProj, 0.0f, (float)SCREENWIDTH, (float)SCREENHEIGHT, 0.0f, 0.0f, 1.0f, cml::z_clip_neg_one );

 

http://cmldev.net/?p=189

 

I think you would want to use something like matrix_perspective_LH
 
Last edited by a moderator:
do you have any screenshots at hand? it'd be easier to actually SEE whats wrong than looking at the code :)

just guessing, dont know atm but you might want to try to use the transpose of the rotMatrixZ? (swap row with column, but i think you know that?)
 
Last edited by a moderator:
Yes I already change the matrix. The first step is, to create a quad rotates toward the camera. Like a tree image which faces always the player.

The second step is to show a image from back of the tree when the players sees the back of the tree. And a picture of the front of the tree when the player sees the front.

To archive this I have 16x4 images in one texture, calculate which image I want to display on the quad and show it. open gl no problem.

Direct X shows one image, then 2 images at once, then 4 and so on.
 
hm ... are you using the correct vertices to calculate the angle? and are you writing the correct UVs ? you know usually opengl has Y-up and directx Z-up ... and when you start to see more it means that on one corner, you're not calculating the angle correctly letting teh TexCoord0.x/y at 0.
 
Last edited by a moderator:
I dont have the source code I can just use the shader code. In open gl the object center is 0,0,0, the same in direct x or? the rotation of the object works, but the calculation of the image i want to show is not. I can't print the angle and other debug infos :( . Maybe somewhere in the calculation from sin and cos to 360° is something wrong. Do you a formular to calc a degree from sin and cos?
 
Back
Top