Moving model in 3d opengl

I want to move my model on a flat surface (y=0) using keyboard buttons but I have the following problem:

I managed to make him revolve around his Y axis, but now i need to make it move in the direction he is facing. How to detect and calculate the displacement to construct a proper translation matrix?

Here is the code attached because something is not going well...

    this.mouseMv = MatrixMath.lookAt(this.eyeX,this.eyeY,this.eyeZ,,this.up);
    Mat4 translate = MatrixMath.translate(this.position);
    this.mouseMv = this.mouseMv.mul(translate);
    this.mouseMv = this.mouseMv.mul(MatrixMath.rotationX(-90.0f));
    this.mouseMv = this.mouseMv.mul(MatrixMath.translate(this.position);
    this.mouseMv = this.mouseMv.mul(this.mouseAngle);

    modeling.setUniformMatrix("model_view", this.mouseMv);
    String part = "models/catbody.sgf";
    Mat4 original = this.mouseMv;
        for (Map.Entry<String, VertexBufferObject> entry : vboHashMap.entrySet()) {
            String key = entry.getKey();
            gl.glDrawArrays(GL3.GL_TRIANGLES, 0, SGFLoader.getNumVertices(key));

So the forward vector is the (8,9,10) vector from my mouseMv matrix. Now to make the model move forward the direction he is facing i should translate the mouseMv by translation matrix with the corresponding forward vector?


If you have the angle in which your model is facing, you can just use a really simple sine and cosine calculation. pseudo code: newx = oldx + (cos(angle)*speed); newz = oldz + (sin(angle)*speed); Your angle has to be in radians (divide by 180 and multiply by pi if it is in degrees) if you use sin() and cos() in math.h

It's hard to see how you move your object as no source code has been provided. But I suppose you already use matrices for rotation. So you just need to rotate the matrix then translate it along the matrix new direction which is forward vector. Now, the question how to calculate a forward vector I will leave for you to solve as this one is trivial.

But in cases you are still confused here is a clue:

Need Your Help

Text box getting cleared beacause of update panel

c# html textbox updatepanel

I've have one table, in that table within one I've one and within that , I've update panel whose update mode is set to conditional. Within this update panel I've another table. The table contains 3...

Parse plain text with Restkit

iphone ios ipad parsing restkit

I get a response for a RestKit GET request that is just a number. It's not a JSON, not HTML, not XML. Just a plain number. For example, when I view source, here's what I see:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.