N
N
Nikita Markelov2014-06-01 14:12:12
JavaScript
Nikita Markelov, 2014-06-01 14:12:12

Building View and Perspective Matrices for OpenGL

I work with WebGL, I don’t want to use any extraneous libraries, because I do it just for experience in mathematics.
I managed to build a working Perpective matrix, but the trouble is with the View.

this.eye = new Vec3(0,0,0);
      this.up = new Vec3(0,1,0);
      this.at = new Vec3(0,0,1);
      this.lookAt = function(){
        var zaxis = new Vec3(this.at.v.x-this.eye.v.x,this.at.v.y-this.eye.v.y,this.at.v.z-this.eye.v.z).normal();
        var xaxis = this.up.cross(zaxis).normal();
        var yaxis = zaxis.cross(xaxis);
        return new Mat4([
        xaxis.v.x,yaxis.v.x,zaxis.v.x,0,
        xaxis.v.y,yaxis.v.y,zaxis.v.y,0,
        xaxis.v.z,yaxis.v.z,zaxis.v.z,0,
        -xaxis.dot(this.eye),-yaxis.dot(this.eye),-zaxis.dot(this.eye),1
        ]);
      }

It seems to me that everything is logical, but in reality it does not work at all as it should. What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Taratin, 2014-06-01
@Entii

https://code.google.com/p/gl33lessons/wiki/Lesson03 short and to the point

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question