OgreODE Ball character and camera!
-
- OGRE Expert User
- Posts: 1422
- Joined: Sat May 22, 2004 5:28 am
- Location: Bucharest
- x 8
OgreODE Ball character and camera!
What would be the better way to implement a camera using Ogre and OgreODE having as the main character (the cammera is looking at) a Ball that is rolling!?
if anyone has suggestions is more then welcome!
i implemented 2 possibilities till now and none is truly satisfying!
1. the camera follows the ball from behind all the time, but cause of the physical interactions, when the ball is hitting objects is also changing the direction suddenly...in this case the camera is just jumping from place to place trying to position behind the ball
2. the camera is fixed on a side of the ball (behind the ball as a starting point)...and is following the ball from that side all the time...only when the player is running the ball into a direction more than a fixed period of time, the camera will change position into another fixed position! this implementation is no good since the controls for the ball must be fixed (left, right, fwd, bcwd) and the movement of the ball is not a natural one...also the camera is having only fixed positions from which the player can see the world.
it seems to me the first choice is better used with non-physical objects, that will not receive feedback from the environment and the second is just a thing i come up with in crisys!
what everyone thinks!?
if anyone has suggestions is more then welcome!
i implemented 2 possibilities till now and none is truly satisfying!
1. the camera follows the ball from behind all the time, but cause of the physical interactions, when the ball is hitting objects is also changing the direction suddenly...in this case the camera is just jumping from place to place trying to position behind the ball
2. the camera is fixed on a side of the ball (behind the ball as a starting point)...and is following the ball from that side all the time...only when the player is running the ball into a direction more than a fixed period of time, the camera will change position into another fixed position! this implementation is no good since the controls for the ball must be fixed (left, right, fwd, bcwd) and the movement of the ball is not a natural one...also the camera is having only fixed positions from which the player can see the world.
it seems to me the first choice is better used with non-physical objects, that will not receive feedback from the environment and the second is just a thing i come up with in crisys!
what everyone thinks!?
-
- OGRE Retired Moderator
- Posts: 4011
- Joined: Fri Sep 19, 2003 6:28 pm
- Location: Burgos, Spain
- x 2
I worked a little in a camera system I went to use for an adventure game I planned some time ago. It worked really great for any viewpoint and movement. What I did, was calculating a full 3rd/1st person camera positions, what represented the position you are talking about (always in the same position relative to the node you were tracking). BUT the real camera, the one that actually renders the scene from, just tried to reach that position. For that, a frame listener, the actual position, the target position, and a "tightness" factor were used to calculate the next camera position. With a tightness factor of 0, the camera won't try to reach the ideal position, and with a factor of 1, it instantly reached the actual position. For instance, a tightness factor of 1 could be used for 1st person camera, while a factor of approximately 0.5 was used for chasing 3rd person camera so when the character turns, the camera doesn't move quickly, giving a smooth effect.
The way to calculate the next position was calculating the vector from the starting position and the ideal position, then modulating it with the factor (obtaining a vector between the full translation and the null translation), and then adding (translating) that vector to the current position
I will try to write a tutorial that shows this, as many people ask about 3rd person camera systems
The way to calculate the next position was calculating the vector from the starting position and the ideal position, then modulating it with the factor (obtaining a vector between the full translation and the null translation), and then adding (translating) that vector to the current position

I will try to write a tutorial that shows this, as many people ask about 3rd person camera systems

-
- Greenskin
- Posts: 145
- Joined: Wed Jan 19, 2005 4:36 am
- Location: Arica, Chile
-
- OGRE Retired Moderator
- Posts: 4011
- Joined: Fri Sep 19, 2003 6:28 pm
- Location: Burgos, Spain
- x 2
-
- Halfling
- Posts: 58
- Joined: Thu Feb 10, 2005 10:35 pm
- Location: Arcachon, France
I wrote a little demo with ogre ODE and a ball, the camera was centred on the ball
and right-cliking + moving the mouse was controling the position from where i where seeing the ball i also added a zoom feature with teh mouse wheel and the ball mouvement were controled by keys relatively to the camera direction and i also made terrain colision so teh camera never get under it.
to make the camera follow the ball, i used a very simple code, eatch frame, i take the ball pos and i compare it with the last frame ball position, calculate a deplacement vector and then move the camera with it, it works very well.
and right-cliking + moving the mouse was controling the position from where i where seeing the ball i also added a zoom feature with teh mouse wheel and the ball mouvement were controled by keys relatively to the camera direction and i also made terrain colision so teh camera never get under it.
to make the camera follow the ball, i used a very simple code, eatch frame, i take the ball pos and i compare it with the last frame ball position, calculate a deplacement vector and then move the camera with it, it works very well.
-
- OGRE Expert User
- Posts: 1422
- Joined: Sat May 22, 2004 5:28 am
- Location: Bucharest
- x 8
-
- OGRE Expert User
- Posts: 1422
- Joined: Sat May 22, 2004 5:28 am
- Location: Bucharest
- x 8
i've done it! i t has some problems, cause the camera is not keeping track with the ball when it has great speed (cause i didnt calculate the intermediate positions regarding its speed, but i'll do that) but is working nice! when is over, i'll post the code here since there maybe other ppl in need of this!
-
- OGRE Expert User
- Posts: 1422
- Joined: Sat May 22, 2004 5:28 am
- Location: Bucharest
- x 8
-
- Halfling
- Posts: 58
- Joined: Thu Feb 10, 2005 10:35 pm
- Location: Arcachon, France
Oh sorry, didn't saw your post but i think now you don't need the code anymore?
For the controls, I have a button to roll forward, back, left and right to move the ball, i use a torque with a direction calculated from the camera orientation and the ball or it would be hard to control the ball after rotating the camera, I used some bits of code from a monster demo.
yes i know i use the 'right' vector to go forward but it's a torque so..
and then i use right * 50 to go back, forward * 50 to go left and forward * -50 to go right
and I dont know what is teh probleme with high speed, to make the camera not keeping track you must go really fast
what i do is :
and i allready did
when i created the scene
(balln is the ball node, ballnod a vector3, and ballb is the ODE bodie for the ball)[/code]
For the controls, I have a button to roll forward, back, left and right to move the ball, i use a torque with a direction calculated from the camera orientation and the ball or it would be hard to control the ball after rotating the camera, I used some bits of code from a monster demo.
Code: Select all
Vector3 right = mCamera->getRight();
Vector3 forward = right.crossProduct(Vector3::UNIT_Y);
//to go forward
if(mInputDevice->isKeyDown(KC_I))
{
ballb->wake();
ballb->addTorque(right * (-50));
}
and then i use right * 50 to go back, forward * 50 to go left and forward * -50 to go right
and I dont know what is teh probleme with high speed, to make the camera not keeping track you must go really fast
what i do is :
Code: Select all
Vector3 mov = balln->getPosition() - ballnod;
ballnod = balln->getPosition();
mCamera->move(mov);
Code: Select all
ballnod = balln->getPosition();
(balln is the ball node, ballnod a vector3, and ballb is the ODE bodie for the ball)[/code]
-
- OGRE Expert User
- Posts: 1422
- Joined: Sat May 22, 2004 5:28 am
- Location: Bucharest
- x 8
But what happens to your ball when trying to move back?
here, when i move back, i can do that for only small distances, then the back direction becomes front once i moved. if i still keep the back button pressed, the ball will change direction again and again! so i cannot have a continuous back movement!
here, when i move back, i can do that for only small distances, then the back direction becomes front once i moved. if i still keep the back button pressed, the ball will change direction again and again! so i cannot have a continuous back movement!
-
- Halfling
- Posts: 58
- Joined: Thu Feb 10, 2005 10:35 pm
- Location: Arcachon, France
that's because the camera rotates maybe?
I had this probleme when teh camera was orientated with the ball orientation,
but my camera just translates as the ball translates but dont inherit rotation (or i would just have created the camera as a child of the ball)
rotation is only performed from the mouse
I had this probleme when teh camera was orientated with the ball orientation,
but my camera just translates as the ball translates but dont inherit rotation (or i would just have created the camera as a child of the ball)
rotation is only performed from the mouse
-
- OGRE Expert User
- Posts: 1422
- Joined: Sat May 22, 2004 5:28 am
- Location: Bucharest
- x 8
-
- Halfling
- Posts: 58
- Joined: Thu Feb 10, 2005 10:35 pm
- Location: Arcachon, France
if you made the camera following the ball as i told you, you should just remove your code to make the camera allways be behind the ball and it should be ok.
If you want i can send you the code for my little demo you can have a look at it, but i'm not even sure it's working i left it after begining to modifie some things but never finished, tell me an email adress by pm if you want it
If you want i can send you the code for my little demo you can have a look at it, but i'm not even sure it's working i left it after begining to modifie some things but never finished, tell me an email adress by pm if you want it
-
- OGRE Expert User
- Posts: 1422
- Joined: Sat May 22, 2004 5:28 am
- Location: Bucharest
- x 8