Jump to content

  • Log In with Google      Sign In   
  • Create Account


We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Member Since 05 Jul 2009
Offline Last Active Dec 11 2014 01:46 PM

Posts I've Made

In Topic: GLSL vec4 multiplication not working?

24 June 2013 - 11:25 PM

gDebugger also shows that your transformMatrix is full of zeros. Does that have something to do with your problem?


Interesting...I didn't notice that! The issue was I was assigning my other two uniforms BEFORE calling glUseProgram. So "color" was conflicting with the handle of "transform matrix." Thanks for your help.

In Topic: Why is this a function on distance and not angle?

21 January 2013 - 08:55 PM

Yup, looks like you've messed that up. http://en.wikipedia.org/wiki/Spherical_coordinate_system
glm::vec3 dir = glm::vec3( cos(x) * cos(y), sin(x) * cos(y), sin(y) ); // note i swapped cos/sin on Y from what the wiki states so that y=0 is down and y=pi is straight up

forward = dir * speed;

I have seen that wiki article and have tried implementing it, but it doesn't work properly. It's pretty strange but when I call translateForward(), the camera moves to the left of the direction the camera is facing, and will only move vertically if the camera is facing down the Z axis. What I posted was me fiddling around until it worked as I expected it to :\.

On second thought, the way I keep track of the position is working fine because when I rotate the camera using this method:
void FreeLookCamera::rotate(const glm::vec3 &vec) {
    mRotation += vec;

    mViewMatrix = glm::rotate(glm::mat4(1.f), mRotation.z, glm::vec3(0.f, 0.f, 1.f));
    mViewMatrix = glm::rotate(mViewMatrix, mRotation.x, glm::vec3(1.f, 0.f, 0.f));
    mViewMatrix = glm::rotate(mViewMatrix, mRotation.y, glm::vec3(0.f, 1.f, 0.f));
    mViewMatrix = glm::translate(mViewMatrix, mPosition);

I start with a blank matrix, and apply the translation at the end based on the position I've accumulated in translateForward and the camera doesn't jump around at all.

I think math just hates my existence lol

In Topic: Why is this a function on distance and not angle?

14 January 2013 - 03:05 PM

Or, just use the built in function that does the same thing:
objectMat = glm::LookAt(objectPos, camPos, camUp);

I've tried that, but still get strange results. If there isn't anything wrong with the method I posted above and using lookAt, then the only other thing it could be is how I'm tracking the position of the camera.
void FreeLookCamera::translateForward(float distance) {
    glm::vec3 forward;

    forward.x = -distance * glm::sin(glm::radians(mRotation.y)) - glm::sin(glm::radians(mRotation.x));
    forward.y = distance * glm::sin(glm::radians(mRotation.x));
    forward.z = distance * glm::cos(glm::radians(mRotation.y)); - glm::sin(glm::radians(mRotation.x)); 

    mPosition += forward;

    mViewMatrix = glm::translate(mViewMatrix, forward);

In Topic: Moving camera in direction of rotation

05 January 2013 - 04:45 PM

Alrighty, I got it guys thanks.

In Topic: Moving camera in direction of rotation

05 January 2013 - 04:58 AM

The reason why I added them is because after those angles, the movement would not go in the correct direction. For example: if my camera was rotated to the left (-yaw) and I moved the camera forward and backward it would work fine. However if I rotated the camera to the right(+yaw) would not work properly, so I figured that the formula had to change depending on which quadrant I was working in. I did notice in my time searching for an answer that none of the examples people have posted do not have conditions and work like what Columbo posted. Are those conditions then just hiding a problem somewhere else in my math?
I'm not at the computer with my code on it at the moment, so I can't post my matrix code...but it's setup very similarly to this guide: http://openglbook.com/the-book/chapter-4-entering-the-third-dimension/


So I commented out all of the conditions so I was only left with
y = std::sin(mRotation.x) * distance;
x = std::sin(mRotation.y) * distance;
z = std::cos(mRotation.y) * distance;

and the movement does work fine on the horizontal plane. However, if I face directly up or directly down (as in, looking down the y axis) the camera moves on the horizontal plane (x and z) when it should be restricted to moving vertically.

EDIT #2:

Okay, instead of using the translation method I had before, I did this:
    mTransformationMatrix = Matrix4f::getIdentityMatrix();
    mTransformationMatrix.translateMatrix(0.f, 0.f, mPosition.z += 1.f*distance);

And it sorta works how I want it to. I'm rotating the camera around a center point. Doesn't feel like I'm flying around.

EDIT #3: I have no idea what I'm doing tongue.png
void ITransformable::translate(const Vector3f &vec) {
    mPosition += vec;

    mTransformationMatrix = Matrix4f::getIdentityMatrix();

Matrix functions:
        void rotate(float x, float y, float z) {
            Matrix4f xRotation = getIdentityMatrix();
            Matrix4f yRotation = getIdentityMatrix();
            Matrix4f zRotation = getIdentityMatrix();

            float cos = std::cos(x);
            float sin = std::sin(x);
            xRotation[5] = cos;
            xRotation[6] = -sin;
            xRotation[9] = sin;
            xRotation[10] = cos;

            cos = std::cos(y);
            sin = std::sin(y);
            yRotation[0] = cos;
            yRotation[2] = sin;
            yRotation[8] = -sin;
            yRotation[10] = cos;

            cos = std::cos(z);
            sin = std::sin(z);
            zRotation[0] = cos;
            zRotation[1] = -sin;
            zRotation[4] = sin;
            zRotation[5] = cos;

            Matrix4f r = xRotation * yRotation * zRotation;
            const float *result = ((*this)*r).getValues();
            memcpy(mValues, result, sizeof(float)*16);
        void translateMatrix(float x, float y, float z) {
            Matrix4f translation = getIdentityMatrix();

            translation[12] = x;
            translation[13] = y;
            translation[14] = z;
            /*translation[3] = x;
            translation[7] = y;
            translation[11] = z;*/

            const float *result = ((*this)*translation).getValues();
            memcpy(mValues, result, sizeof(float)*16);