Page 6 of 6 FirstFirst ... 456
Results 51 to 56 of 56

Thread: OpenGL 3.x Rotation Problem

  1. #51

    Re: OpenGL 3.x Rotation Problem

    What i'd do is very quick way (strafing):
    1) Read X-vector from camera matrix
    2) Normalize, and multiply the vector by amount you want to move sideways
    3) Translate camera by this vector to strafe

    If you need to move it forward or backwards, read Z-vector instead. This will naturally work for movement like space ship also, totally free angles.

    Any questions?

  2. #52

    Re: OpenGL 3.x Rotation Problem

    But will this work for a third-person camera?

    As you can see, I'm looking for solutions regarding a third-person camera. I've done it for a first-person one.

  3. #53

    Re: OpenGL 3.x Rotation Problem

    Yes it will work (in worst case you would get inverted vectors in which case all you would do is negate the movement amount), however when it comes to moving and camera, moving should be based on character. You can place camera on character's eyes or behind afterwards. Character on a common FPS game that's on land doesn't need a matrix. You need only position and direction vectors from which you can easily calculate movement.

    I mean, what if you want to tint camera sideways to simulate earthquake or something, then strafing based on camera matrix wouldn't go along with what character is doing, or if you look up, then he would suddenly not move forward quite the right direction...

    Edit2: Ew, i think that's what you were trying to do all along...

    Maybe try like this
    [pascal]ctThirdPerson:
    begin
    Target.Move(AFactor);
    Position := Vec3Subtract(Target.Position, AFactor);
    // Reduce position by direction character is facing to whatever vector...
    end;[/pascal]

  4. #54

    Re: OpenGL 3.x Rotation Problem

    I tried to make the third-person mode work on quaternions. Here's what I got:
    [code=delphi]
    ctThirdPerson:
    if Assigned(FTarget) then
    begin
    FTarget.Move(AFactor);

    Q := QuaternionFromEuler(Rotation);
    Q1 := Quaternion(0.0, 0.0, 2.0, 5.0); // desired distance from the target
    Q2 := QuaternionMultiply(QuaternionConjugate(Q),
    QuaternionMultiply(Q1, Q));

    Offset := Vec3(Q2.X, Q2.Y, Q2.Z);
    NewPos := Vec3Add(Offset, FTarget.Position);

    Position := NewPos;
    end;
    [/code]
    But this code doesn't work, because the camera moves, while the target object remains stationery, even though there's a line that "commands" him to move.

    Any suggestions?

    EDIT
    I haven't tried your code, User137 yet. First, I wanna see if it's possible to do on quaternions. The code I'm using is taken from another source, where it works.

    EDIT2
    Here's another code I found (in C#):
    Code:
          Matrix transform = Matrix.Identity;
          transform.Forward = ChaseDirection;
          transform.Up = Up;
          transform.Right = Vector3.Cross(Up, ChaseDirection);
    
          // Calculate desired camera properties in world space
          desiredPosition = ChasePosition +
            Vector3.TransformNormal(DesiredPositionOffset, transform);
          lookAt = ChasePosition +
            Vector3.TransformNormal(LookAtOffset, transform);
    I could use it if I knew which array fields correspond to forward, up, and right vectors. I saw a nice diagram somewhere, but can't find it now. Can someone tell me where these vectors are?
    EDIT3
    haha, I found the picture: http://www.songho.ca/opengl/files/gl_anglestoaxes01.png

  5. #55

    Re: OpenGL 3.x Rotation Problem

    Ok, time for a BUMP.

    I got the third person camera working, but there's still one thing I can't work out. I mean, mouse looking in the third person mode. The code I'm using works perfectly in the first person mode, but when it's used with the latter, it produces an effect like, well, a "barrel roll"? Here's a picture for a better look at the situation:


    And of course, the code:
    [code=delphi]
    procedure TBrainCamera.MouseLook(const CursorX, CursorY: Integer);
    var
    DeltaX, DeltaY: Single;
    R: TBrainEuler;
    begin
    if (CursorX = CenterX) and (CursorY = CenterY) then
    exit;

    DeltaX := CenterX - CursorX;
    DeltaY := CenterY - CursorY;

    R := Rotation; // for convenience
    R.Yaw := R.Yaw - DeltaX * FMouseSmooth;

    if FInvert then
    R.Pitch := R.Pitch - DeltaY * FMouseSmooth
    else
    R.Pitch := R.Pitch + DeltaY * FMouseSmooth;

    if (R.Pitch < FMinAngle) then
    R.Pitch := FMinAngle;
    if (R.Pitch > FMaxAngle) then
    R.Pitch := FMaxAngle;

    Rotation := R;

    if (FCamType = ctThirdPerson) and (Assigned(FTarget)) then
    FTarget.Rotation := Euler(FTarget.Rotation.Pitch, R.Yaw,
    FTarget.Rotation.Roll);

    SetCursorPos(CenterX, CenterY);

    UpdateNeeded := True;
    UpdateInvNeeded := True;
    end;
    [/code]

    Does anyone have a slightest clue what is wrong there?

  6. #56

    Re: OpenGL 3.x Rotation Problem

    I solved the problem, which wasn't in the mouse looking code, but in matrix calculations. Well, the camera seems to be working well now. You can see the code here.

    If you encounter any bugs, please let me know.

Page 6 of 6 FirstFirst ... 456

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
  •