Hot answers tagged

10

You should probably use glm::angleAxis() (documentation here): glm::quat rot = glm::angleAxis(glm::radians(90.f), glm::vec3(0.f, 1.f, 0.f));


9

Place your camera target at the center of the arc rotation (That's usually where you want the camera to look anyway). Then simply transform the camera's position around the target with a rotation that uses the appropriate axis. pseudo code: //some angle & some other angle = only the amount you want the camera to rotate since last frame. //pitch ...


9

The "union" there says that these are three different ways of viewing the same memory. So the x component of the first struct occupies the same bytes of memory as the r component of the second struct, and so on. The three different versions just create different aliases by which you can refer to the vector's components - depending on whether you're viewing ...


7

This may be a winding issue. Are you sure that the texture coordinates are parsed in the right sense of rotation? However, this how you should debug you program. Draw in wire frame mode to find out how the rectangle is composed out of two triangles. The OpenGL command for this is glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);. Use a texture with a gradient ...


6

Rotation/scaling is around the origin. To both scale/rotate around a pivot, you apply a negative translation to move the pivot point to the origin, apply your scale and rotate, and then move your pivot point back. mat4 result = glm::translate(-pivot) * glm::scale(..) * glm::rotate(..) * glm::translate(pivot) * ...


6

Easy way of building the rotation matrix: Start with an identity matrix Translate the matrix by -centre of the object Rotate the matrix by the desired amount Translate the matrix by centre of the object Use the resulting matrix to transform the object that you desire to rotate


5

Your first method is the correct one. According to the OpenGL FAQ: The translation components occupy the 13th, 14th, and 15th elements of the 16-element matrix It can also be seen in the glm source code (from matrix_transform.inl): inline detail::tmat4x4<T> translate /*...*/ { detail::tmat4x4<T> Result(m); Result[3] = m[0] * v[0] + m[...


5

Because the lookAt function is to position the camera to look at an object (not for an object to look at another object) and the way 3D cameras work is that mathematically they move the entire world the opposite way and the screen stays at the origin. So because the matrix is intended for a camera and 3d cameras work "backward" you need to inverse the ...


4

Local versus world is just a matter of the order in which you compose transforms. For instance, when using row-vector math, multiplying the current local-to-world transform by a new transform on the left will perform the new transform in local space, since it will be equivalent to doing the new transform followed by the old local-to-world transform. ...


4

You need to read the error message more carefully: In file included from jni/src/GLIncludes.h:41:0, from jni/androidLauncher.cpp:4: jni/src/glm/glm.hpp:86:18: fatal error: limits: No such file or directory As you can see, the glm.hpp header is found. It's limits that is not found, because by default the NDK uses a stripped-down C++ runtime ...


4

GLM's rotation function uses Euler's rotation theorem, which implies that any rotation or sequence of rotations of a rigid body in a three-dimensional space is equivalent to a pure rotation about a single fixed axis. However consecutive calls to GLMs rotate function just multiply the rotation so rotating a rigid body by Yaw, Pitch, Roll is as simple as this:...


4

user1118321's answer will provide you the correct answer, though it is more general than necessary. Since we're dealing with a right triangle, the easiest solution is to use the definition of the tangent function: tan(α) = A / B Substituting half the height of the screen, the z coordinate of the camera, and half the vertical field of view gets us: tan(22....


4

One way is to disable GL_DEPTH_TEST for rendering 2D stuff. So draw everything of the 3D world like normal, then disable depth testing and then draw your UI at last. Another approach would make use of the depth test by setting the z-component of the vertices for the 2D stuff to 0 (and the near plane in the prohection matrix to something greater than 0) to ...


3

the glm::quat(float, float, float, float); constructor doesn't do what you think it does. It sets the values directly. The values of the quaternion (w, x, y, z) are in order: the cosine of half the angle, the sine of half the angle times the x coordinate of the normalized rotation axis, and the same for the y and z components. So instead you want to use ...


3

Short answer: To store position, use a single vec3. To store rotation, use a quaternion and normalize it after every multiplication or after every n (1-1000) multiplications. You shall only use mat4s when it comes to drawing or transforming lots of vertices: Convert vec3+quaternion pair to mat4 and pass it to your shader or use it to transform vertices ...


3

You get the error because there is no operator*= for vec4 that takes a matrix as a parameter. It then tries to convert the matrix to a float, but just can't. To work around this, you should try to not use the operator*= and write it all in the long form: Off = Off * Util::createTransform(offset); Also, as pointed out in the comments to the OP, what you ...


3

From http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/ qx = ax * sin(angle/2) qy = ay * sin(angle/2) qz = az * sin(angle/2) qw = cos(angle/2) But since your vector represents the rotation, and is not the axis of rotation, we need to compute the angle. Your axis of rotation is just 0,1,0 angle = atan2( vector.x, vector.z ...


3

If you have the normal of the collision triangle, then you can do a dot product with a normal pointing up (0, 1, 0), the result will be related to the angle of the surface (0 when is completety vertical, 1 when it's completely flat, and in between) That should be really all, you check that against a threshold to determine if you want the ellipsoid to slide ...


2

Answer: Thanks for your help guys. I just kept track and updated the position and heading variable separately from the view matrix. glm::vec3 m_position; glm::vec3 m_direction; ... // speed is usually 0.1f or something small like that void camera::rotate(float amount, glm::vec3& axis) { m_direction = glm::rotate(m_direction, amount * m_speed, ...


2

Thanks to @DaleyPaley I was able to figure this out. The problem lay in my code to figure out the camera vectors Right, Up, and Back. I was just using some code that I found online, and once I started showing the actual camera placement and vectors from the perspective of a hardcoded camera, I could tell that the vectors being produced by Right, Up, and Back ...


2

Just set 'the view matrix' to identity and then translate to like -6.0 on the z axis. You are not using lookAt() correctly. The first paramater is the position you are at (the camera) and the second is where you look at.


2

Well if I understand well as @user8363 explained in the comments, your problem is that you are making one direction for all the particles, which makes the particles move in that direction. If you want the particles to accelerate toward the point you need to make a direction vector for each particle. For instance: foreach particle: acc = particle - ...


2

I've done it by using a mix of Lighthouse3D tutorial, which I got by following the tip of @concept3d. My previous Frustum Culling routine was execute in about 12~16ms using Clip Space approach, but extracting planes from camera, I can execute it in 1~2ms....So, the peformance boost is awesome. Here is my final code. Whenever my rotation/position changes, I ...


2

First thing I see is that you shouldn't read the quaternion in reverse order. Also you shouldn't use glm::mix, use glm::slerp instead. And here is how I construct the bone transform: mat = glm::mat4_cast( currentrotation ); mat[0][0] *= currentscale.x; mat[1][0] *= currentscale.x; mat[2][0] *= currentscale.x; mat[0][1] *= currentscale.y; mat[1][1] *= ...


2

The problem is solved. I changed glUniformMatrix4fv(m_WVPLocation, 1, GL_TRUE, &PVMMat[0][0]); to: glUniformMatrix4fv(m_WVPLocation, 1, GL_FALSE, &PVMMat[0][0]); and: glFrontFace(GL_CW); to: glFrontFace(GL_CCW);


2

Your camera (and every object with a transform) has its own local space axes, which will usually not be the same as the world axes. Transforming around the world-space axis will give a different result than transforming around a local-space axis. Cameras typically need to work with both. You usually want to rotate a camera horizontally around "world up" ...


2

Okay. Seems like you just want a single light-camera. But there are many different approaches. Like using multiple frustum splits (which means multiple light-cameras), which is called "Cascaded Shadow Mapping". Even the way you construct the frustum of your light-camera to encompass the main camera's frustum can be done in various ways. First some useful ...


2

historically billboards matrix just copy the camera view matrix, and replace the last row with their own world position. the scale can be world-fixed if you want trees or hard stuff. But it can also be screen-fixed for halo effects, in which case you need to scale using the euclidian distance. this can be done in the vertex shader rather than on CPU as an ...


2

Check out the Law of Cosines. It allows you to calculate any side or angle in a triangle if you have the opposite 2 angles or sides. Or alternately, use the law of sines (described at the bottom of the above link). In your case, you know that vertical field of view is 45 degrees and that the base side you want is the height of the screen. You can think of ...


Only top voted, non community-wiki answers of a minimum length are eligible