Harry
Member
|
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 |
|
Zervox
Member
|
RE: Camera movement
problem with the time countdown or the return path?
|
|
08-11-2010 01:53 PM |
|
Harry
Member
|
RE: Camera movement
With both 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 |
|
Zervox
Member
|
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 |
|
Harry
Member
|
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 |
|
Driklyn
Member
|
RE: Camera movement
(08-11-2010 02:26 PM)Harry Wrote: With both 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 |
|
Harry
Member
|
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 |
|
Zervox
Member
|
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 |
|
Harry
Member
|
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 |
|
Zervox
Member
|
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 |
|
Harry
Member
|
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 |
|
Zervox
Member
|
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 |
|
Harry
Member
|
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 |
|
Zervox
Member
|
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 |
|
Harry
Member
|
|
08-13-2010 11:42 AM |
|