# Tag Info

12

glm::quat myquaternion = glm::quat(glm::vec3(angle.x, angle.y, angle.z)); Where angle is a glm::vec3 containing pitch, yaw, roll respectively. PS. If in doubt, just go to the headers and look. The definition can be found in glm/gtc/quaternion.hpp: explicit tquat(tvec3<T> const & eulerAngles) { tvec3<T> c = glm::cos(eulerAngle * ...

10

I'm not familiar with GLM, but in the absence of a function to directly convert from eular angles into quaternions, you can use the "rotation around an axis" functions (such as "angleAxis") to it yourself. Here's how (pseudocode): Quaternion QuatAroundX = Quaternion( Vector3(1.0,0.0,0.0), EulerAngle.x ); Quaternion QuatAroundY = Quaternion( Vector3(0.0,1.0,...

6

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 ...

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] + ...

5

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 ...

5

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

4

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) * ...

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++ ...

4

Solution is in wikipedia: http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles using that: sx = sin(x/2); sy = sin(y/2); sz = sin(z/2); cx = cos(x/2); cy = cos(y/2); cz = cos(z/2); q( cx*cy*cz + sx*sy*sz, sx*cy*cz - cx*sy*sz, cx*sy*cz + sx*cy*sz, cx*cy*sz - sx*sy*cz ) // for XYZ application order q( cx*cy*cz - sx*sy*sz, ...

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

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 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

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));

3

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(...

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

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

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

Your top code chunk is: t2 * (t1 * direction * inverse(t1)) * inverse(t2) Your bottom chunk is: t3 * direction * inverse(t3) Given that t3 = t2 * t1 It's (t2 * t1) * direction * inverse(t2 * t1) As far as my knowledge of Quaternion multiplication goes, I don't think t2 * (t1 * direction * inverse(t1)) * inverse(t2) and (t2 * t1) * direction * inverse(...

2

I managed to fix everything through a lot of experimenting. It seems my problem came from my own misunderstanding of quaternions. I was under the impression that they represented a change in angle, when actually they represent an orientation. So my rotation matrix was always a bit strange because I was just pushing seemingly random values into it, ...

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

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

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 ...

2

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 ...

2

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 ...

2

Making a model always face a point is trickier in 3d than it is in 2d: the added dimension makes one wonder "what about the UP?". This here assumes that you want your model to stay vertical as much as possible, and it uses the following coordinate system. // z+ y+ // | / // | / // | / // | / // |/ // ¯¯¯¯¯¯¯¯¯¯¯¯ x+ This also assumes that the '...

1

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);

1

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" ...

1

In V8 you can wrap your own, custom C++ classes expose them to JavaScript and have V8 take care of destructing the instance once the corresponding JS object gets GC'd. But you still have to write your methods in a style like this: Handle<Value> Vector::add(const Arguments& args) { Vector *vector = WrappedClass::unwrap<Vector>(args.This(...

1

Your ray is possibly in view (camera) space. I'm unsure exactly how glm::unproject works. If I'm right, pass its end points through the inverse camera matrix to put then in world space. Remember that a coordinate is expressed in some basis, which for our purposes can be considered a vector space (mathematically there is some difference) or commonly just a ...

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