About Store Forum Documentation Contact



Post Reply 
Camera movement
Author Message
Zervox Offline
Member

Post: #16
RE: Camera movement
Care to post the exact code your using again?
(This post was last modified: 08-19-2010 11:53 PM by Zervox.)
08-19-2010 11:52 PM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #17
RE: Camera movement
Yea sure:

PHP Code:
/*************************************************/
#include "stdafx.h"
#include "Main.h"
/**************************************************/
Flt CamTppDist       ,
CamTppCustom     ,
CamTppCustomYaw  ,
CamTppCustomPitch,
camPitchInterp;
Vec head;

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)|IndexToFlag(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,1);
            
CamTppCustomPitchplr.angle.y;
        }

        
Clamp(CamTppCustomPitch, -PI_4,PI_4);

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

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

        
// camera position
        
{
            
camPitchInterp LerpAngle(camPitchInterpCam.pitch/2.0f,Time.d()*3);

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

            
head*=plr.cskel.scale   ();

            
Matrix3 look_matrixlook_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.fracCam.yawCam.pitch0ball.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();
            }
        }
        if(
Cam.pitch 0.1f)
        {
            
head =plr.cskel.skeleton()->getPoint("Head").pos+Vec(0,camPitchInterp,0// calculate behind and above head position relative to body bone
                
-plr.cskel.skeleton()->getBone ("Body").pos;
        }
        else
        {
            
head =plr.cskel.skeleton()->getPoint("Head").pos+Vec(0,-camPitchInterp,0// calculate behind and above head position relative to body bone
                
-plr.cskel.skeleton()->getBone ("Body").pos;
        }

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

        
Cam.updateVelocities();
        
Cam.set();

    }else
    {
        
CamHandle(0.1f,1000,(zoom?CAMH_ZOOM:0)|(Ms.b(0)?CAMH_MOVE_XZ:Ms.b(1)?CAMH_MOVE:CAMH_ROT));
    }

}
/*****************************************/ 

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

Post: #18
RE: Camera movement
Strange, I cant get any jitter effect :S
08-20-2010 12:10 AM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #19
RE: Camera movement
weird i use this in Player.cpp

PHP Code:
Flt  max=DegToRad(900)*Time.d(),
                    
dx =Ms.dir_ds.x*1.7,
                    
dy =Ms.dir_ds.y*1.7*Ms.inv();
                
Clamp(angle.y, -PI_4,PI_4);
                
angle.x-=Mid(dx,-max,max);
                
angle.y+=Mid(dy,-max,max); 

Ugh i am a total idiot. This works i had to use clamp after the angle is set... lame me. Need more coffee!! smile
PHP Code:
Flt  max=DegToRad(900)*Time.d(),
        
dx =Ms.dir_ds.x*1.7,
        
dy =Ms.dir_ds.y*1.7*Ms.inv();
                
        
angle.x-=Mid(dx,-max,max);
        
angle.y+=Mid(dy,-max,max);
        
Clamp(angle.y, -PI_4,PI_4); 

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

Post: #20
RE: Camera movement
I found this helped alot on the case,
the reason is most likely you should make.

You should add the same limitation to the player related pitching code, (y axis?)
or prevent the code to run, something like
if(angle.y >= 0.xxf) to prevent it from constantly running.

Code:
Flt  max=DegToRad(900)*Time.d(),dx =Ms.dir_ds.x*1.7,dy =Ms.dir_ds.y*1.7*Ms.inv();
                Clamp(angle.y, -PI_4,PI_4);
                angle.x-=LerpAngle(Cam.yaw,dx,Time.d()*20);
                angle.y+=LerpAngle(Cam.pitch,dy,Time.d()*20);

atleast make this not constantly run just because of mouse movement
Code:
angle.y+=LerpAngle(Cam.pitch,dy,Time.d()*20);

EDIT: Ah, yeah. : P missed that myself wink
(This post was last modified: 08-20-2010 12:45 AM by Zervox.)
08-20-2010 12:37 AM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #21
RE: Camera movement
Quote:if(angle.y >= 0.xxf) to prevent it from constantly running.

Yes i tried this aswell but it wasnt working cause the Clamp func. But this not a problem anymore.

But limiting the angle speed is OK. But dont u think its kinda slow for a third person game?

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

Post: #22
RE: Camera movement
Yeah, sorry, not a master of optimized handling : P
08-20-2010 12:50 AM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #23
RE: Camera movement
hehe no problem im trying myself aswell to make to most of it wink

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

Post: #24
RE: Camera movement
Btw a zoom/aim would be nice too, only problem is when i edit the x and z the camera is not in sync with the player... thats cause the camera point is on player but when its changed its not correct anymore.

Any idea?

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

Post: #25
RE: Camera movement
thats because the code I gave you references Cam.yaw, the base Cam function mostly, so I think you would perhaps use two different Cam function copies,

like

Code:
Flt CamTppDist       ,
CamTppCustom     ,
CamTppCustomYaw  ,
CamTppCustomPitch,
camPitchInterp;

Flt CamTppDist       ,
Cam2TppCustom     ,
Cam2TppCustomYaw  ,
Cam2TppCustomPitch,
cam2PitchInterp;

and in the physics sweep function, you reference the custom cam variables.
this way you dont have to overwrite the Cam.yaw but base the customs on it

or
Code:
Camera      Custcam1;
Camera      Custcam2;
and make them ref the Cam.yaw etc as base values.

I believe this would be easiest, but perhaps the most unoptimized.


Now directly regarding your problem, are you resetting the Cam variables?
(This post was last modified: 08-20-2010 02:18 AM by Zervox.)
08-20-2010 02:17 AM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #26
RE: Camera movement
Well what do u mean by resetting it?

I use this to change only height atm but need x/z aswell for the zoom.

PHP Code:
camPitchInterp LerpAngle(camPitchInterpCam.pitch/2.0f,Time.d()*3);

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

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

Post: #27
RE: Camera movement
I am not sure what I meant, was just looking at the
Cam.yaw =CamTppCustomYaw;
Cam.pitch=CamTppCustomPitch;

and I am not sure if Cam.yaw and pitch,dist/y or z needs to be set back to original, that or +='s will change them all the time.

Anyways I am also very drowzy, haven't slept in 37 hours : p so I better call it a night before my start to do headspins, I aint surprised if I don't make any sense at the moment, will take a closer look at this tomorrow.
08-20-2010 02:46 AM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #28
RE: Camera movement
hehe your are crazy 37 hours is way too long :O

But anyway i can use distance; only problem is you can't go negative.

Having 2 camera's can work but only problem is if you need more then 1 e.g different camera stands this is not gonna work aswell.

So i believe only choice is to change the current camera, maybe change the radius?

Need to think about this 1 tho...

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

Post: #29
RE: Camera movement
Hmm, I dont know if you solved this.
But in some cases I know of some sets two points, one that is the player and a forward point some distance from the player, which the camera will use as reference point when zooming, and if you have a target system, the camera will zoom to target location.

Also you got
Code:
if(zoom)
{
   D.viewFov (DegToRad(30),FOV_Y);
//or
   D.viewFov (DegToRad(30),FOV_X);
}
Should be possible to do a lerp or smooth motion while activating and return it back when not zooming. : )
(This post was last modified: 08-22-2010 10:19 PM by Zervox.)
08-22-2010 10:15 PM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #30
RE: Camera movement
Yes this works indeed haven't though about this one thnx smile

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