how I setup view matrix? - math

how I setup view matrix so that it works similer to 3ds max. in max if there a object which points to the left and you run over it, it will points to the left, even if you are looking at it from the other side. I want this for my 3d editor. thanks in advance.

You have to extract upward & side vectors from your camera and use them to align an object to a camera's view plane. This way your object will always be faced to the camera.

Related

Finding center coordinate of transformed image in terms of previous coordinate system

Apologies for asking this question, but I'm having trouble getting my head around 2D geometry and transforms (probably due to lack of sleep), can't visualize things in my mind's eye. Please could you help.
I'm using Qt and QTransform, although this is largely irrelevant as this is a mathematical problem. I have an image that takes up the whole viewport, I zoom into the image at a point (zoomPos) that is clicked on. I accomplish this with the following transform:
zoomTransform.translate(zoomPos.x(), zoomPos.y());
zoomTransform.scale(zoomFactor, zoomFactor);
zoomTransform.translate(-zoomPos.x(), -zoomPos.y());
What I wish to calculate are the point coordinates of the center of the scaled (zoomed) image in terms of the original (unscaled) coordinate system. Another way of explaining this is: I wish to calculate the point coordinates of the original image that is the center of the scaled (zoomed) image. I hope that makes sense.
I tried using QTransform::map which maps a point to the coordinate system defined by the transform. I think I have to use an inverted zoomTransform (not sure) and am not sure which coordinates to map from.
Thanks for reading.

How to change the camera rotation in Threejs

I have make a 3D cone with CSS3Renderer and TrackballControl and it works properly.
http://chito.hk/three-test/
But now, I want to modify it to allow user input the values to control the camera rotation rather than using TrackballControl.
http://chito.hk/three-test/index_static.php
But the camera gives no response to the lookAt function. Can anyone tell me which part I am doing wrong?
Add a render(); call after your lookAt.

Calculate angle of view from 2D image

I want to calculate the angle of view (or the field of view) from a photograph, without knowing anything about the camera, as to use that information in a 3D environment.
I have to use trigonometry to solve this (most probably using arctan), but I'm not proficient enough in math ...
Can somebody please help?
Please have a look at this example.
I assume the angle between the line CENTER-LEFT and CENTER-RIGHT is 90° in reality.
I know the distances (in pixels) of point C to the vanishing points VP-left and VP-right.
Furthermore the height of the image is the angle of view in my 3D environment.
Thanks!

Project a grid in screenspace on the world xz plane

I want to project a grid on the xz-plane like shown here:
To do that, I created a vertex grid with x and z range [-1|1]. In the shader I multiply the xz screen coordinate of a vertex with the inverse of the View-Projection matrix. Then I want to adjust the height, depending on the new world xz coordinates and finally I transform these coordinates back to screenspace by multiplying them with the View-Projection matrix.
I dont know why, but I get a very strange plane shown on the screen. Are the mathematical oprations I use correct?
The grid that you initially create, is that in projection space or actual screen co-ords? It sounds like it is in projection space since you only transform it with the inverse of the view-projection matrix to get into world co-ords. I think you need to include the "Window" matrix too i.e. transform them by the inverse of the View-Projection-Window matrix (and similarly on the way back to screen co-ords).
Edit:
I'm probably not understanding exactly what it is you're trying to do so here's some questions back. :)
Are you trying to take the grid that's shown in the screenshot in your question and project that onto world z-x co-ordinates? If so, then why do you start with a grid of z-x values? Also, if you apply an inverse view matrix to those then surely you would end up with a line since the camera looks along z although your second screenshots show that you are getting a plane. I'm a bit confused.

How to rotate a picture using jogl?

Dear Friends,Can anyone tell me how to show one picture in GLCanvas and by using mouse how to rotate a picture in the GLCanvas.I m new to this jogl developement.Can u pls provide me how to do this.If possible provide me some code snippet and some reference site to get a clear idea about jogl developement.
regards,
s.kumaran.
To show an image on GLCanvas , create a polygon using gl.glBegin(GL.GL_POLYGON) and load the texture using the Class TextureIO .Then using the MouseListener in Java Swings ,you can easily control the rotation of the image(i.e,the textured polygon) by simply changing the position of Camera or doing some transformations( "gl.glRotate(angle,x-axis,y-axis,z-axis) in your case") in Model-View matrix .
The easiest way to do this will be to texture a Quad with the picture and then apply affine transforms to that Quad. Rendering this quad will let you see a rotating picture you can do pretty much any transform by shifting the vertices of the Quad.
I'm assuming that you are drawing a 3D scene and want to change it's orientation, rather than having a 2D image which you wish to rotate.
The short answer is that it takes place in two parts. You need to store an orientation of your scene as a 4x4 matrix (homogeneous matrix - search for it if you don't know what that is). You first need to write code that translates a mouse drag into a change of that 4x4 matrix. So when the mouse is dragged up apply an appropriate rotation or whatever to the matrix.
Then you need to redraw the scene, but using the new transformed 4x4 matrix. Use glMatrixMode to specify which matrix (use either GL_PROJECTION or GL_MODELVIEW) and then functions like glMultMatrixf() to manipulate the appropriate matrix.
If that didn't make sense pick up an OpenGL tutorial on how to rotate scenes. OpenGL and JOGL are close enough that methods from OpenGL work in JOGL.

Resources