Page 3 of 6 FirstFirst 12345 ... LastLast
Results 21 to 30 of 56

Thread: OpenGL 3.x Rotation Problem

  1. #21

    Re: OpenGL 3.x Rotation Problem

    Sure, but you may consider using http://pastebin.com/

  2. #22

    Re: OpenGL 3.x Rotation Problem

    Done!

    http://pastebin.com/ff5a251c

    enjoy, and I hope it helps

    BTW, it isn't a COMPLETE implementation, but it does points, lines, triangles (wireframe) only...

    cheers,
    Paul
    Games:
    Seafox


    Pages:
    Syntax Error Software itch.io page

    Online Chess
    http://gameknot.com/#paul_nicholls

  3. #23

    Re: OpenGL 3.x Rotation Problem

    Whoa, looks great. Thanks a bunch, Paul!

    I'll see if I can make something out of this.

  4. #24

    Re: OpenGL 3.x Rotation Problem

    @Paul: Your openGL emulation code looks very interesting. Great job!

    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  5. #25

    Re: OpenGL 3.x Rotation Problem

    Finally, after weeks of struggling, the code works!

    And here is a step-by-step guide:
    1.First of all, I disposed of all my matrix code and rewrote it. Here are the functions you will need to compile the code: http://www.nopaste.pl/Source/mhc.txt
    2.Use the following shaders: http://www.nopaste.pl/Source/mhd.txt
    3.Your rendering code should look like this:
    [code=delphi]
    procedure TMainForm.RenderWorld;
    var
    Model, View, Proj, MVP: TBrainMatrix;
    begin
    // Clear the frame buffer
    glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);

    // Compute the model-view-projection matrix
    Proj := Mat4CreatePerspective(60.0, ClientWidth / ClientHeight, 0.1, 1000.0);
    Model := Mat4Translate(Mat4CreateRotationEuler(ModelRotatio n), Vec3Negate(ModelPosition));
    View := Mat4Translate(Mat4CreateRotationEuler(CameraRotati on), Vec3Negate(CameraPosition));
    View := Mat4Inverse(View);

    MVP := Mat4Multiply(Model, Mat4Multiply(View, Proj));

    // Update the shader
    glUniformMatrix4fv(ShaderManager.ActiveProgram.Get UniformLocation('mvpmatrix'),
    1, False, @MVP);

    // Rendering code here...
    end;
    [/code]

    I hope it saves someone almost two weeks of cursing.

  6. #26

    Re: OpenGL 3.x Rotation Problem

    Great job.

    I wonder though why you need to invert the view matrix.

    I definitly need to dust off my knowledge about linear algebra. I still have the "3D Math primer for graphics and gamedevelopment" book, which needs to be studied lol.

    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  7. #27

    Re: OpenGL 3.x Rotation Problem

    Quote Originally Posted by Brainer
    Finally, after weeks of struggling, the code works!

    And here is a step-by-step guide:
    1.First of all, I disposed of all my matrix code and rewrote it. Here are the functions you will need to compile the code: http://www.nopaste.pl/Source/mhc.txt
    2.Use the following shaders: http://www.nopaste.pl/Source/mhd.txt
    3.Your rendering code should look like this:
    [code=delphi]
    procedure TMainForm.RenderWorld;
    var
    Model, View, Proj, MVP: TBrainMatrix;
    begin
    // Clear the frame buffer
    glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);

    // Compute the model-view-projection matrix
    Proj := Mat4CreatePerspective(60.0, ClientWidth / ClientHeight, 0.1, 1000.0);
    Model := Mat4Translate(Mat4CreateRotationEuler(ModelRotatio n), Vec3Negate(ModelPosition));
    View := Mat4Translate(Mat4CreateRotationEuler(CameraRotati on), Vec3Negate(CameraPosition));
    View := Mat4Inverse(View);

    MVP := Mat4Multiply(Model, Mat4Multiply(View, Proj));

    // Update the shader
    glUniformMatrix4fv(ShaderManager.ActiveProgram.Get UniformLocation('mvpmatrix'),
    1, False, @MVP);

    // Rendering code here...
    end;
    [/code]

    I hope it saves someone almost two weeks of cursing.
    Was my code helpful to you getting this working?

    I hope so LOL

    cheers,
    Paul
    Games:
    Seafox


    Pages:
    Syntax Error Software itch.io page

    Online Chess
    http://gameknot.com/#paul_nicholls

  8. #28

    Re: OpenGL 3.x Rotation Problem

    Quote Originally Posted by paul_nicholls
    Was my code helpful to you getting this working?
    Nope, Paul, but I'm glad you tried to help. I really appreciate that.

    @chronozphere
    Take a look at the quote:
    Creating the view matrix
    The view matrix transforms the world coordinates system into the coordinate system of the camera. In other words, after applying the view matrix transform the coordinates will be relative to the camera and not the origin of the world. If we think of the camera as one of the objects in the world we can see that the view matrix is actually an inverse transform of the camera's world matrix. By inverting the world matrix used to place the camera in the world we get the view matrix.
    Full article is here: http://www.programmersheaven.com/2/world-view

  9. #29

    Re: OpenGL 3.x Rotation Problem

    I used http://www.gamedev.net/community/for...opic_id=468539 to create LookAt function but i'm still not getting results that i need:
    [pascal]function LookAt(const eye, target, up: TVector): TMatrix;
    var x,y,z,p: TVector;
    begin
    z:=invert(norm(VectorSub(target,eye)));
    x:=norm(crossproduct(norm(up),z));
    y:=crossproduct(z,x);
    p:=vector(-dot(eye,x),-dot(eye,y),-dot(eye,z));
    result:=CreateMatrix(x,y,z,p);
    end;[/pascal]
    It is short and "simple" but yet it's not working right. I have tried to visualize the matrix vectors in 2D plane but it's hella confusing... And i've tested and tested the math behind tool functions but they should all work correctly. They are used in numerous other 3D functions which behave right, including MatrixToSurface() that is another kind of LookAt formed of pos and normal on a plane, RayTriangleIntersect(), RaySphereIntersect().

    This is how it's i've debugged the matrix: http://i49.tinypic.com/fbc9oj.png
    Red dot is Eye vector and white is its Invert. Yellow dot is Target vector. Green represent LookAt matrix returned and line drawn is Z-rotation vector of it.

    Basically.. i was able with the same functions to point the ship with my mouse and draw another smaller ship on surface of it where cursor ray first crossed, perfectly aligned with the triangle on the point, yet LookAt doesn't work.

    Edit2: Getting a little closer, but its upside down and is not directly following target or eye pos http://i45.tinypic.com/2nly2id.png
    I drew the matrix-Z vector from eye pos aswell. It's green line that should hit yellow sphere for it to be correct.

  10. #30

    Re: OpenGL 3.x Rotation Problem

    Doh, error was in my own CreateMatrix().. it was built wrong sided.

    It was your code Brainer that worked first though

    I replaced
    [pascal]_41 := Dot(Scale(xAxis, -1.0), From);
    _42 := Dot(Scale(yAxis, -1.0), From);
    _43 := Dot(Scale(zAxis, -1.0), From);[/pascal]
    with
    [pascal]_41 := Dot(Scale(xAxis, -1.0), At);
    _42 := Dot(Scale(yAxis, -1.0), At);
    _43 := Dot(Scale(zAxis, -1.0), At);[/pascal]
    And it worked straight away.

    My function optimized is now:
    [pascal]function LookAt(const eye, target, up: TVector): TMatrix;
    var x,y,z,p: TVector;
    begin
    z:=norm(VectorSub(eye,target));
    x:=norm(crossproduct(up,z));
    y:=crossproduct(z,x);
    p:=vector(-dot(eye,x),-dot(eye,y),-dot(eye,z));
    result:=CreateMatrix(x,y,z,p);
    end;[/pascal]

Page 3 of 6 FirstFirst 12345 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •