Page 2 of 6 FirstFirst 1234 ... LastLast
Results 11 to 20 of 56

Thread: OpenGL 3.x Rotation Problem

  1. #11

    Re: OpenGL 3.x Rotation Problem

    Sorry, but the code proposed by you doesn't not seem to work. It doesn't even display the triangle.

  2. #12

    Re: OpenGL 3.x Rotation Problem

    How about:
    Code:
    ModelView := MatrixMultiply(MatrixMultiply(ProjMat, ModelView2), Cam);

  3. #13

    Re: OpenGL 3.x Rotation Problem

    Nope, it's still the same. In both cases nothing's even displayed.

  4. #14

    Re: OpenGL 3.x Rotation Problem

    I noticed that there is a problem with the math I'm using to create the matrices. I noticed that when I tried to transpose the matrix using glUniform and my custom-build function. They produced different results.

    Does anyone have any decent Pascal math library with matrix functions (I'd also like to have functions for calculating transformation matrices included)?

  5. #15

    Re: OpenGL 3.x Rotation Problem

    I just took a look at your transformation matrix code. It seems some of the signs are wrong when you calculate the rotation matrix. I'll take a look later when I'm drunk enough to understand this matrix stuff
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  6. #16

    Re: OpenGL 3.x Rotation Problem

    This is the matrix that I calculated. It might be that it's for a righthand coordinate system though. That might be why
    Code:
    [              cos(ty)*cos(tz),             -cos(ty)*sin(tz),     sin(ty),0]
    [ cos(tx)*sin(tz) + cos(tz)*sin(tx)*sin(ty), cos(tx)*cos(tz) - sin(tx)*sin(ty)*sin(tz), -cos(ty)*sin(tx),0]
    [ sin(tx)*sin(tz) - cos(tx)*cos(tz)*sin(ty), cos(tz)*sin(tx) + cos(tx)*sin(ty)*sin(tz), cos(tx)*cos(ty),0]
    [0,0,0,1]
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  7. #17

    Re: OpenGL 3.x Rotation Problem

    Thanks. I did the corrections.

    But it's still the same. I even tried changing a little the rendering code:
    [code=delphi]
    { .: MatrixLookAt :. }
    function MatrixLookAt(const From, At, Up: TVector): TMatrix;
    var
    xAxis, yAxis, zAxis: TVector;
    begin
    zAxis := VectorSubtract(From, At);
    zAxis := VectorNormalize(zAxis);
    xAxis := VectorCrossProduct(Up, zAxis);
    xAxis := VectorNormalize(xAxis);
    yAxis := VectorCrossProduct(zAxis, xAxis);

    with Result do
    begin
    _11 := xAxis.X;
    _12 := yAxis.X;
    _13 := zAxis.X;
    _14 := 0.0;

    _21 := xAxis.Y;
    _22 := yAxis.Y;
    _23 := zAxis.Y;
    _24 := 0.0;

    _31 := xAxis.Z;
    _32 := yAxis.Z;
    _33 := zAxis.Z;
    _34 := 0.0;

    _41 := VectorDotProduct(VectorScale(xAxis, -1.0), At);
    _42 := VectorDotProduct(VectorScale(yAxis, -1.0), At);
    _43 := VectorDotProduct(VectorScale(zAxis, -1.0), At);
    _44 := 1.0;
    end;
    end;

    { .: TMainForm.Render :. }
    procedure TMainForm.Render;
    var
    ProjMat, Cam, ModelView, Model: TMatrix;
    begin
    glViewport(0, 0, ClientWidth, ClientHeight);
    glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);

    // Projection update
    if (ClientHeight <= 0) then
    ClientHeight := 1;
    ProjMat := MatrixProjection(40.0, ClientWidth / ClientHeight, 0.1, 1000.0);

    // Camera transformations
    Cam := MatrixLookAt(VectorNegate(Camera.Pos), VectorCreate(0.0, 0.0, -1.0),
    VectorCreate(0.0, 1.0, 0.0));
    Model := MatrixTransform(VectorCreate(0.0, 0.0, 0.0),
    VectorCreate(0.0, TriangleRot, 0.0), VectorUniform(0.5));
    ModelView := MatrixIdentity;
    ModelView := MatrixMultiply(MatrixMultiply(Model, Cam), ProjMat);

    // Update the shader
    glUniformMatrix4fv(glGetUniformLocation(ShaderMana ger.GLSLPrograms['minimal'].
    ProgramHandle, 'mvpmatrix'), 1, ByteBool(GL_FALSE), @ModelView);

    // Render the triangle
    glBindVertexArray(TriangleVAO);
    glDrawArrays(GL_TRIANGLES, 0, 3);
    glBindVertexArray(0);
    end;
    [/code]
    The new code displays the triangle, but the translation doesn't work correctly. When I translate the triangle with an arrow key, it doesn't change its position. Once I strafe and then try to move it forward, it suddenly accelerates. Clearly it's a problem with the matrix I pass to the shader, but where is the bug hidden? The function was taken from LEAF2 engine - I hoped it was a good one.

  8. #18

    Re: OpenGL 3.x Rotation Problem

    The LookAt function is definitely off. Was doing my Matrix lib today based on GLScene and tested this on the way. Lib itself works perfectly when i rotate object with mouse with my functions. It's when i set camera with this lookAt it doesn't go to right place.

    [pascal]// This doesn't work
    cam:=MatrixLookAt(Vector(0,0,-3),Vector(0,0,0),Vector(0,1,0));

    // This works
    cam:=NewMatrix;
    TranslateMatrix(cam,Vector(0,0,-3));[/pascal]

    Edit: I also used your matrix multiplication function so it means they are read same way GLScene made 1 line for each 16 array elements, 2 x for loop is more compact.

  9. #19

    Re: OpenGL 3.x Rotation Problem

    Hm, okay. Thanks for your feedback.

    So you suggest using normal transformation functions instead of LookAt, right? But this approach doesn't work, either. The first snippet I posted contained the MatrixTransform function. It was wrong at first, but JSoftware provided us with a new matrix and I modified the code. Nevertheless, the effect is still far from what's desired.

    Maybe it's something wrong with the shader? Maybe I'm looking for a bug in a wrong place?

  10. #20

    Re: OpenGL 3.x Rotation Problem

    Hi Brainer,
    A while ago I was fiddling around with creating software OpenGL routines (for my gp2x handheld), and I DID get something basic working.

    I could emulate exactly how OpenGL did its rendering with regards to transformations.

    I have a unit you could look at which includes all my OpenGL transformations, etc. but it is 1307 lines long...

    Is it ok if I post it here?

    Perhaps it may help you with your matrix issues...

    cheers,
    Paul

Page 2 of 6 FirstFirst 1234 ... 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
  •