I wonder how to solve this problem using opengl on android. I have camera with quaternion, which describes its rotation. I want to have an object f.e. Cube will be in the same screen relative position. So, i want to rotate it and translate around camera position using this quaternion. It is something similiar to crosshair in games, but I dont want to use this for overlay, but for drag drop feature for 3D objects.
You are trying to find a point in the direction represented by a quaternion at a given distance. For this, you cannot use quaternion directly like you do for vectors.
You can convert quaternion to matrix and then do the same logic as below.
glm::mat4 rotate = glm::mat4_cast(rotationQuat);
glm::vec4 newPosition = rotate * vector;
Related
I'm trying to render a 3D object (an arrow) and rotate it according to camera rotation in the real world.
I'm thinking of using Camera method : getPose().getRotationQuaternion([]float), transform the qy in degrees and then apply the rotation matrix.
But i can't understand how to use quaternions and if this is the right way to reach my goal.
Thank you.
I have two 4x4 rotation matrices M and N. M is describing my current object attitude in space, and N is a desired object attitude. Now I would like to rotate M matrix towards N, so the object will slowly rotate towards desired position in following iterations. Any idea how to approach this?
If these matrices are not strange which should be the case describing "rotation matrices" you should do this by interpolating their base vectors in polar system.
To examine we want to convert top-left 3x3 matrix to 3 vectors defined by angles and distance. Once this is done you should do a linear interpolation on angles and distances for that top-left 3x3 part while the rest should have a direct cartesian interpolation. From angles and distances you can then convert back to cartesian coordinates.
Naturally there is still work internally like choosing which way to rotate (using closest) and checking there are no edge cases where one base vector rotates into different direction then the other...
I managed to successfully do this in 2D system which is a bit easier but should be no different in 3D.
To note a cartesian interpolation works fairly fine as long as angles are relatively small (<10 degrees to guess) which is most likely not your case at all.
I was inspired by Pokemon GO and wanted to make a simple prototype for learning purposes. I am a total beginner in image processing.
I did a little research on the subject. Here is what I came up with. In order to place any 3D model in the real world, I must know the orientation. Say if I am placing a cube on a table:
1) I need to know the angles $\theta$, $\phi$ and $\alpha$ where $\theta$ is the rotation along the global UP vector, $\phi$ is the rotation along the camera's FORWARD vector and $\alpha$ is rotation along camera's RIGHT vector.
2) Then I have to multiply these three rotation matrices with the object's transform using these Euler angles.
3) The object's position would be at the center point of the surface for protyping.
4) I can find the distance of the surface using android's camera's inbuilt distance estimation using focal length. Then I can scale the object accordingly.
Is there any more straight forward way to do this using OpenCV or am I going in the right track?
in OpenGL ES 1, I have a Rubic cube that consists of 27 smaller cubes. i want a rotation which causes a particular small cube becoming exactly in front of the viewpoint. so i need two vectors. one is the vector that comes from the origin of the object to that particular cube. and another is the vector that comes from origin to the viewpoint. then the cross product of them gives me the axis of the rotation and the dot product gives me the angle.
but i cant convert the (0,0,1) -which is the vector that comes from the origin to the viewpoint in world coordinate- to object coordinates.
how can i do that? how can i convert "world coordinates to object coordinates"?
It's easier to rotate the camera around than it is rotating the object in front of a stationary camera.
You can do what you asked for by placing the camera at the origin (center) of the rubic cube, giving it the opposite direction from the small cube, and than translating z backwards.
I know it doesn't answer the question in the title, but I think it's a simpler solution. (As for your question, I keep world and object coordinates same, and set the object scale as needed when rendering).
i have created a cube. now i want to perform rotation, zooming and panning functions by moving camera. like moving camera far will zoom out and near will zoom in.
please help as i am new in android and openGL-es.
There is no such thing as camera in OpenGL. There are only two transformation matrices: model-view and projection. First you have to setup your projection matrix. You can do that using glFrustum or manually. Read this article about projections.
Then in order to fake the camera behavior you need to use inverse transformation matrix. It means that if you want to move your camera for (0,0,-5) you need to move the whole world for (0,0,5). The same is with rotation and scaling.
You should read the OpenGL Red Book, it is all described there.