About Store Forum Documentation Contact



Post Reply 
Camera movement
Author Message
Dynad Offline
Member

Post: #1
Camera movement
Hey there,

Ive a small problem with the camera. Im trying to make a third person camera over shoulder like Gears of war, Mass effect etc. But when i try to make the camera a bit to the right it rotates on its own axis. But i want that the camera rotates on player axis.

Ive made a simple illustration what i mean.


thnx,
~Dynad


Attached File(s) Image(s)
   

There is always evil somewhere, you just have to look for it properly.
08-19-2010 10:38 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #2
RE: Camera movement
Create two different Cam.at, object rotates around Cam.at

you could set
Code:
Cam.at=pos-Vec(-1,0,0);
Cam.setSpherical(Players[0].pos(), Cam.yaw, Cam.pitch, 0, ball.r);

Pseudo Code
Ok, sorry that code didnt work as I expected. But perhaps you could post your camera code, makes it easier so I dont need to guess your setup? : ) If you want to that is.
(This post was last modified: 08-19-2010 11:13 AM by Zervox.)
08-19-2010 10:56 AM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #3
RE: Camera movement
yea i checked it but it didnt work indeed.

this what i use now atm:

PHP Code:
if(Ms.b(1))
             {
                 
desired_camera.yaw  =Lerp(camYaw, -PI_4,Time.d());
                 
desired_camera.pitch=Lerp(camPitch, -PI_4/2,Time.d());
                 
             } else
             {
                
desired_camera.yaw    Players[0].angle.x;
                
desired_camera.pitch  Players[0].angle.y;
             }
             
Clamp(desired_camera.pitch,-PI_2,PI_2);
             
camYaw  =desired_camera.yaw  ;
             
camPitch=desired_camera.pitch;

             
OrientP &head=Players[0].cskel.getPoint("head"); // obtain player "head" skeleton point (this was created in Mesh Editor)

             
Ball ball(0.001fdesired_camera.at);
             
Physics.move(balldesired_camera.matrix.pos-ball.pos);

             if(
camPitch 0.1f)
             {
                
camPitchInterp LerpAngle(camPitchInterpcamPitch/2.0f,Time.d()*3);
                
camUpInterp Lerp(camUpInterpcamPitch,Time.d()*3);
                
desired_camera.setSpherical(head.pos,desired_camera.yaw,desired_camera.pitch,0,1.5);
             }
             else
             {
                 
camPitchInterp Lerp(camPitchInterpcamPitch/4,Time.d()*3);
                 
camUpInterp Lerp(camUpInterpcamPitch,Time.d()*3);
                 
desired_camera.setSpherical(head.pos,desired_camera.yaw,desired_camera.pitch,0,1.5);
             }

             
Cam.setPosDir(desired_camera.matrix.pos+Vec(0,camPitchInterp,0), desired_camera.matrix.zdesired_camera.matrix.y); 

There is always evil somewhere, you just have to look for it properly.
08-19-2010 11:19 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #4
RE: Camera movement
Code:
{
Vec head =plr.cskel.skeleton()->getPoint("Head").pos+Vec(1,0.18f,-0.05f) -plr.cskel.skeleton()->getBone ("Body").pos;

head*=plr.cskel.scale   ();

Matrix3 look_matrix; look_matrix.setRotateXY(-plr.angle.y,-plr.angle.x); head*=look_matrix;

Vec pos=          plr.stored_pos+head;
pos=Lerp(pos, plr.stored_pos              , 0.5f);
pos=Lerp(pos, plr.stored_pos+Vec(0,0.2f,0),           CamTppCustom);

Cam.at=pos;
}

This atleast locks the camera to be constantly on one side instead of the point rotating around the player.

eg right side of the player.

This line is what does it
Code:
Player &plr         =Players[0];

Vec head =plr.cskel.skeleton()->getPoint("Head").pos+Vec(1,0.18f,-0.05f) -plr.cskel.skeleton()->getBone ("Body").pos;

but from what I understood, is that you want it to look over the shoulder, and when rotating around you want it to focus on the player, or did you just a locked point which didnt rotate around him constantly?

EDIT:

just to explain
Code:
CamTppCustom
Code:
Flt CamTppCustom;

Bool custom=(InvGui.visible()); // custom rotation
AdjustValTime(CamTppCustom,custom,0.001f);
(This post was last modified: 08-19-2010 11:52 AM by Zervox.)
08-19-2010 11:44 AM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #5
RE: Camera movement
Quote:but from what I understood, is that you want it to look over the shoulder, and when rotating around you want it to focus on the player, or did you just a locked point which didnt rotate around him constantly?

Yea i want it to look over the shoulder, and when rotating around i want it to focus on the player.

But this code is made for rpg2 right? did you add this in the camera class?

There is always evil somewhere, you just have to look for it properly.
(This post was last modified: 08-19-2010 12:16 PM by Dynad.)
08-19-2010 12:16 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #6
RE: Camera movement
No, I used RPG2 as reference. Mostly only variable names now is the same throughout all my classes. And yes I add this in the camera class. You can do

Code:
Vec head;

if(Ms.b(1))
{
  // do own rotation code
}else
{
head =plr.cskel.skeleton()->getPoint("Head").pos+Vec(1,0.18f,-0.05f) -plr.cskel.skeleton()->getBone ("Body").pos;

head*=plr.cskel.scale   ();

Matrix3 look_matrix; look_matrix.setRotateXY(-plr.angle.y,-plr.angle.x); head*=look_matrix;

Vec pos=          plr.stored_pos+head;
pos=Lerp(pos, plr.stored_pos              , 0.5f);
pos=Lerp(pos, plr.stored_pos+Vec(0,0.2f,0),           CamTppCustom);

Cam.at=pos;

}

and make a lerp() or maybe adjustTimeVal() between for smooth transition

between your Ms.b(1) code and the else pos values.
(This post was last modified: 08-19-2010 12:24 PM by Zervox.)
08-19-2010 12:23 PM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #7
RE: Camera movement
Ok well i tried it but there is 1 problem tho.. the camera stays fixed in 1 direction. I want when i rotate my character the camera rotates in the direction of the character aswell.

Like:
http://www.youtube.com/watch?v=ugjgEisc-Cs

There is always evil somewhere, you just have to look for it properly.
(This post was last modified: 08-19-2010 12:37 PM by Dynad.)
08-19-2010 12:34 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #8
RE: Camera movement
My code does this atleast. Perhaps you could find a good seperation/mix between the two.

it does got one bug though, my code stops working because I am not done with the physics collision on it.(gets underneath water, or gets to high or low in the Y for some strange reason too.

Its a mess, but thats because I constantly test out things inside the cam class. still got a lot of cleaning up to do.
Code:
/*************************************************/
#include "stdafx.h"
#include "MainCRR.h"
/**************************************************/
Flt CamTppDist       ,
CamTppCustom     ,
CamTppCustomYaw  ,
CamTppCustomPitch;


Flt CameraTimerReset;
Bool CamIsRotated;

/********************************************************/
Camera      cam;
/*************************************************/
void UpdateCamera()
{


    Bool zoom=(Ms.wheel() && (!Gui.wheel() || Gui.wheel()==Gui.desktop()));

    if(Players.elms())
    {
        Player &plr         =Players[0];
        UInt    actor_groups=~(IndexToFlag(AG_CONTROLLER)|IndexToFlag(AG_PLAYER)|IndexToFla​g(AG_ITEM)|IndexToFlag(AG_RAGDOLL)|IndexToFlag(AG_KINEMATIC_RAGDOLL));

        Bool custom=(InvGui.visible()); // custom rotation
        AdjustValTime(CamTppCustom,custom,0.001f);

        if(Ms.b(1)) // rotate
        {

            //Players[0].matrix().angles().y+=Mid(dy,-max,max);
            CamTppCustomYaw  -=Ms.dir_d.x;
            CamTppCustomPitch+=Ms.dir_d.y;
            Ms.freeze();
        }else{
            CamTppCustomYaw =LerpAngle(Cam.yaw,-Players[0].matrix().angles().y,Time.d()*2);
        }

        Clamp(CamTppCustomPitch, -DegToRad(50), -DegToRad(10));



        Cam.yaw  =CamTppCustomYaw;
        Cam.pitch=CamTppCustomPitch;



        {
            if(zoom)CamTppDist*=ScaleFactor(Ms.wheel()*-0.2f);
            Clamp(CamTppDist,2.5f,9.5f);
            Cam.dist=Max(CamTppDist,CamTppCustom);
            if(zoom)CamTppDist=Cam.dist;
        }

        // camera position
        {
            Vec head =plr.cskel.skeleton()->getPoint("Head").pos+Vec(1,0.18f,-0.05f) // calculate behind and above head position relative to body bone
                -plr.cskel.skeleton()->getBone ("Body").pos;
            head*=plr.cskel.scale   ();

            Matrix3 look_matrix; look_matrix.setRotateXY(-plr.angle.y,-plr.angle.x); head*=look_matrix;

            Vec pos=          plr.stored_pos+head;
            pos=Lerp(pos, plr.stored_pos              , 0.5f);
            pos=Lerp(pos, plr.stored_pos+Vec(0,0.2f,0),           CamTppCustom);

            Cam.at=pos;
        }

        // physics collisions
        Ball ball(0.1f,Players[0].stored_pos); // start camera position at stored position
        Vec  move=Cam.at-ball.pos;
        PhysHit phys_hit;
        if(Physics.sweep(ball,move,&phys_hit,actor_groups)) // move toward desired camera center
        {
            // encountered an obstacle
            Cam.setSpherical(ball.pos + move*phys_hit.frac, Cam.yaw, Cam.pitch, 0, ball.r); // we're forced to stop the camera at contact
        }else
        {
            // no obstacle detected
            Cam.setSpherical();
            ball.pos=Cam.at; // set ball at camera focus
            move=Cam.matrix.pos-ball.pos; // set movement from focus to "look from" point
            if(Physics.sweep(ball,move,&phys_hit,actor_groups))
            {
                Cam.dist*=phys_hit.frac;
                Cam.setSpherical();
            }
        }
    }else
    {
        CamHandle(0.1f,1000,(zoom?CAMH_ZOOM:0)|(Ms.b(0)?CAMH_MOVE_XZ:Ms.b(1)?CAMH_M​OVE:CAMH_ROT));
    }

}
/*****************************************/
(This post was last modified: 08-19-2010 12:55 PM by Zervox.)
08-19-2010 12:46 PM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #9
RE: Camera movement
Ok thnx but when i include your camera code. The camera stands still in middle of nowhere and not reacting on player controls. Dunno if its on my side ill report back if some progress is made.

There is always evil somewhere, you just have to look for it properly.
08-19-2010 01:07 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #10
RE: Camera movement
Camera.h
void CameraUpdate();

in your gamestate update()
Code:
UpdateCamera     ();

Also in if you are spawning a long way from the first zone in world

you can use waypoints like this in the init()
Code:
        if(Game::Waypoint *start=Game::World.getWaypoint("start"))
            if(start->points())
            {
                Cam      +=start->point(0).pos;

I did it this way because then I can change a Camera.cpp at anytime and just change which to actually use in the main gameloop.

Also you can set use it for spawn points when loading each map to easily control that the camera isnt suddenly thrown off.
(This post was last modified: 08-19-2010 01:14 PM by Zervox.)
08-19-2010 01:09 PM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #11
RE: Camera movement
Yea i got it working now.

Those 2 werent defined anywhere wink
Cam.updateVelocities();
Cam.set();

Ok what i see now lookup and look down isn't working. I want it to work like a FPS camera but in third person mode. And the moving to left and right is kinda slow maybe that can be tweaked tho.

EDIT:
I think the camera has to work the other way around. Camera is smoothing to new location. But the camera must be fast and the character is rotating some time later. Its kinda weird if you can instant rotate the player and camera is late.

There is always evil somewhere, you just have to look for it properly.
(This post was last modified: 08-19-2010 01:21 PM by Dynad.)
08-19-2010 01:14 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #12
RE: Camera movement
increase the Time.d()*xxx
Code:
CamTppCustomYaw =LerpAngle(Cam.yaw,-Players[0].matrix().angles().y,Time.d()*2);

set this to set a specific range of pitch movement
Code:
Clamp(CamTppCustomPitch, -DegToRad(50), -DegToRad(10));
This makes it rotate to a degree of 120 when rotating down
and 120degrees up when moving the mouse up.

Where 360 is a full rotation around the object
You could remove it for free rotation around
Code:
Clamp(CamTppCustomPitch, -DegToRad(120), DegToRad(120));
(This post was last modified: 08-19-2010 01:20 PM by Zervox.)
08-19-2010 01:16 PM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #13
RE: Camera movement
Well its almost working good only im not satisfied with 1 thing.

The rotation of CamTppCustomPitch; the rotation is going in a circle but isnt it possible to make that circle smaller or better yet keep the camera fixed at his position?

EDIT:
Ok ive changed it to CamTppCustomPitch= plr.angle.y; and its working fine for now.

There is always evil somewhere, you just have to look for it properly.
(This post was last modified: 08-19-2010 07:49 PM by Dynad.)
08-19-2010 07:29 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #14
RE: Camera movement
Glad it worked for you. smile
08-19-2010 11:32 PM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #15
RE: Camera movement
Ive still a small thing tho. When i clamp the camera and the players angles it works OK. But for example the clamp is at pitch 0.8 and -0.8 when i move my mouse continuously UP or Down it gets past 0.8/-0.8 like 0.9 depends how fast you go up and down with the mouse. And it tries to get 0.8 cause of the clamp. But this causes some jitter effect small up and downs trying to match the 0.8.

Is there another way to fix this?

There is always evil somewhere, you just have to look for it properly.
08-19-2010 11:48 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply