About Store Forum Documentation Contact



Post Reply 
Camera movement
Author Message
Harry Offline
Member

Post: #1
Camera movement
Hello,

I create a camera which is still centered on an object and I can freely rotate it by mouse. After each 3 seconds I want smoothly rotate this camera to default position behind the object. I tried to do it by AdjustValTime but I haven't got any effect. How can I do that?
(This post was last modified: 08-11-2010 01:32 PM by Harry.)
08-11-2010 01:31 PM
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
problem with the time countdown or the return path?
08-11-2010 01:53 PM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #3
RE: Camera movement
With both wink I made some code which countdown the time but I'm not sure is it in 100% ok and inside it I put AdjustValTime but I still can rotate camera and it never changes to default position,

Flt freeCamTime=3;

if((freeCamTime-=Time.d())<=0)
{
Matrix m=Players[0].refCar().actor.matrix();
camPos=m.pos-m.z*(6.7)+Vec(0,2.8,0);
AdjustValTime(desired_camera.matrix.pos,camPos,1);
freeCamTime=3;
}
08-11-2010 02:26 PM
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
I dont know, I believe the timer should work, though I think you should define time in AdjustValTime, you only define pos, target pos and exponent?

pos,target pos,exponent, time



also sometimes you can run
Code:
Bool rotated;
Ms.b(2);
if(Ms.br)
{
   rotated=true;
  freeCamTime-=time.d()
}


if(freeCamTime<=0 && rotated==true)
{

//Code
}else{
freeCamTime=3
rotated=false;
}
(This post was last modified: 08-11-2010 02:43 PM by Zervox.)
08-11-2010 02:34 PM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #5
RE: Camera movement
What exactly is exponent? Maybe I write what exactly I want to obtain:

I want make a vehicle camera like in GTA games. I can rotate it to see car for example from left side or top and if I don't move camera it resets behind the car to see the road.
08-11-2010 03:01 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #6
RE: Camera movement
(08-11-2010 02:26 PM)Harry Wrote:  With both wink I made some code which countdown the time but I'm not sure is it in 100% ok and inside it I put AdjustValTime but I still can rotate camera and it never changes to default position,

Flt freeCamTime=3;

if((freeCamTime-=Time.d())<=0)
{
Matrix m=Players[0].refCar().actor.matrix();
camPos=m.pos-m.z*(6.7)+Vec(0,2.8,0);
AdjustValTime(desired_camera.matrix.pos,camPos,1);
freeCamTime=3;
}

Well, part of the problem is that AdjustValTime is only being called once. It needs to be called multiple times, so something like this...

Code:
Flt freeCamTime=3;
bool defaultCam=false;

if((freeCamTime-=Time.d())<=0) defaultCam=true;

if (defaultCam) {
    Matrix m=Players[0].refCar().actor.matrix();
    camPos=m.pos-m.z*(6.7)+Vec(0,2.8,0)

    AdjustValTime(desired_camera.matrix.pos,camPos,1);

    if (desired_camera.matrix.pos == camPos) {
        freeCamTime=3;
        defaultCam=false;
    }
}

This probably won't work 100% but should get you heading in the right direction; at least, I think so.
08-12-2010 06:13 AM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #7
RE: Camera movement
Now it's called not only once but still nothing changes. I tried to set another values for camPos like Vec(10) and it doesn't work too.
08-12-2010 09:55 AM
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
Could you post the entire camera code?
In this case usually the easiest to do it make a standard cam, and 2 temps.
standard is the preset cam pos,
temp one is the one that is used but references both of them.
temp two would be the rotation for temp one to follow if you rotate the camera.
08-12-2010 11:17 AM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #9
RE: Camera movement
Here s complete code for vehicle camera:

Code:
            if((freeCamTime-=Time.d())<=0)defaultCam=true;

               if(defaultCam)
               {
                   Matrix m=Players[0].refCar().actor.matrix();
                   camPos=Players[0].refCar().matrix().pos+Players[0].refCar().matrix().z*4;
                   AdjustValTime(desired_camera.matrix.pos,camPos,1);

                   if (desired_camera.matrix.pos == camPos)
                   {
                       freeCamTime=3;
                       defaultCam=false;
                   }
               }else
               {
                   desired_camera.yaw  -=Ms.dir_ds.x;  
                   desired_camera.pitch+=Ms.ds.y;      
                   Clamp(desired_camera.pitch,-PI_2,0);
                   desired_camera.setSpherical(Players[0].refCar().matrix().pos,desired_camera.yaw,desired_camera.pitch,0,8);

                
                   Ball ball(0.1f, desired_camera.at);

                  
                   Physics.move(ball, desired_camera.matrix.pos-ball.pos);

                   Cam.setPosDir(ball.pos, desired_camera.matrix.z, desired_camera.matrix.y);
               }
                             
               Cam.updateVelocities().set();
08-12-2010 12: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
looks like it might be because defaultCam is always true.
this always sets it to true.
Code:
if((freeCamTime-=Time.d())<=0)defaultCam=true;


this is run inside the if statement above.
Try setting it after the if(defaultCam) not inside it
Code:
if (desired_camera.matrix.pos == camPos)
{
                       freeCamTime=3;
                       defaultCam=false;
                   }

Code:
if((freeCamTime-=Time.d())<=0)
           {
           defaultCam=true;

               if(defaultCam)
               {
                   Matrix m=Players[0].refCar().actor.matrix();
                   camPos=Players[0].refCar().matrix().pos+Players[0].refCar().matrix().z*4;
                   AdjustValTime(desired_camera.matrix.pos,camPos,1);

                   if (desired_camera.matrix.pos == camPos)
                   {
                       freeCamTime=3;
                       defaultCam=false;
                   }
               }else
               {
                   desired_camera.yaw  -=Ms.dir_ds.x;  
                   desired_camera.pitch+=Ms.ds.y;      
                   Clamp(desired_camera.pitch,-PI_2,0);
                   desired_camera.setSpherical(Players[0].refCar().matrix().pos,desired_camera.yaw,desired_camera.pitch,0,8);

                
                   Ball ball(0.1f, desired_camera.at);

                  
                   Physics.move(ball, desired_camera.matrix.pos-ball.pos);

                   Cam.setPosDir(ball.pos, desired_camera.matrix.z, desired_camera.matrix.y);
               }
                              
               Cam.updateVelocities().set();
              }

that first if will look like this for the compiler because you dont close it
(This post was last modified: 08-12-2010 12:37 PM by Zervox.)
08-12-2010 12:25 PM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #11
RE: Camera movement
I set this after if(defaultCam) but nothing changes. I have free camera around the car and after 3 second it stays in one position and I can't do with it anything. I think that this is as you wrote - defaultCam is always true because if (desired_camera.matrix.pos == camPos) isn't true anytime and I haven't got any movement of camera in AdjustValTime.
(This post was last modified: 08-12-2010 01:06 PM by Harry.)
08-12-2010 01:06 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
try moving the if(defaultCam) out of the if(defaultCamTime) aka set it
Code:
if((freeCamTime-=Time.d())<=0)
{
  defaultCam=true;
}
//
if(defaultCam)
{
}

Also, when I create timers I usually run
Code:
if(desired_camera.matrix.pos == camPos)
{
  Timer=3;
}
if(timer>0)
{
   defaultCam=false
   Timer-=Time.d();
}else{
defaultCam=true;
}

if(defaultCam)
{
  //code
}

Sometimes you can also write Timer functions which can many times help making the code easier to read because they are seperated.

Code:
void classname::CamCountDown(int Timer)
{
    TimeDone = Timer;
    if(TimeDone > 0)
    {
   TimeDone-=Time.d()
     }
     if(TimeDone < 0)
     {
         defaultCam="";
     }
}
(This post was last modified: 08-12-2010 01:38 PM by Zervox.)
08-12-2010 01:29 PM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #13
RE: Camera movement
Ok, I've made a big progress and it almost works as I want. But I have one question. By using Lerp I change camera yaw to -PI_2:

desired_camera.yaw =Lerp(camYaw,-PI_2,Time.d());

but it changes camera yaw in global space. How can I change it according to object?
08-13-2010 10:36 AM
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
you mean like, chaning yaw around the object instead of the camera rotating its yaw by its own location?
08-13-2010 11:30 AM
Find all posts by this user Quote this message in a reply
Harry Offline
Member

Post: #15
RE: Camera movement
http://img594.imageshack.us/i/29476437.jpg/

When car is in this position camera sets good like in image.

http://img828.imageshack.us/i/23422398.jpg/

But here camera yaw is still set to -PI_2 but not according to vehicle rotation to see lke here:

http://img835.imageshack.us/img835/6141/51715627.jpg
08-13-2010 11:42 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply