OgreODE Ball character and camera!

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
User avatar
eugen
OGRE Expert User
OGRE Expert User
Posts: 1422
Joined: Sat May 22, 2004 5:28 am
Location: Bucharest
x 8
Contact:

OgreODE Ball character and camera!

Post by eugen »

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!?
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2
Contact:

Post by Kencho »

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 :)
RoundSparrow
Greenskin
Posts: 145
Joined: Wed Jan 19, 2005 4:36 am
Location: Arica, Chile

Post by RoundSparrow »

Kencho wrote: I will try to write a tutorial that shows this, as many people ask about 3rd person camera systems :)
Awesome. The concept sounds great.
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2
Contact:

Post by Kencho »

It is quite easy and intuitive indeed. I can't put my hands on ogre right now, so I'm kind of outdated, but I'll try to get some minutes each day to work on this ;)
User avatar
Wooden
Halfling
Posts: 58
Joined: Thu Feb 10, 2005 10:35 pm
Location: Arcachon, France
Contact:

Post by Wooden »

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.
User avatar
eugen
OGRE Expert User
OGRE Expert User
Posts: 1422
Joined: Sat May 22, 2004 5:28 am
Location: Bucharest
x 8
Contact:

Post by eugen »

thanks guys! the idea is half implemented for me..i didnt use a deplacement vector as a buffer between the old and the new position...i'l try this!
(can u also put some code of your implementation if is not much trouble :) )
User avatar
eugen
OGRE Expert User
OGRE Expert User
Posts: 1422
Joined: Sat May 22, 2004 5:28 am
Location: Bucharest
x 8
Contact:

Post by eugen »

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!
User avatar
eugen
OGRE Expert User
OGRE Expert User
Posts: 1422
Joined: Sat May 22, 2004 5:28 am
Location: Bucharest
x 8
Contact:

Post by eugen »

What type of control did u use?
do u have a button to roll the ball back? or just front and side? did u use rotations to turn to the left and right side, or apply forces to the ball into that directions?!
User avatar
Wooden
Halfling
Posts: 58
Joined: Thu Feb 10, 2005 10:35 pm
Location: Arcachon, France
Contact:

Post by Wooden »

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.

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));
}
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 :

Code: Select all

Vector3 mov =  balln->getPosition() - ballnod;
ballnod = balln->getPosition();
mCamera->move(mov);
and i allready did

Code: Select all

ballnod = balln->getPosition();
when i created the scene
(balln is the ball node, ballnod a vector3, and ballb is the ODE bodie for the ball)[/code]
User avatar
eugen
OGRE Expert User
OGRE Expert User
Posts: 1422
Joined: Sat May 22, 2004 5:28 am
Location: Bucharest
x 8
Contact:

Post by eugen »

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!
User avatar
Wooden
Halfling
Posts: 58
Joined: Thu Feb 10, 2005 10:35 pm
Location: Arcachon, France
Contact:

Post by Wooden »

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
User avatar
eugen
OGRE Expert User
OGRE Expert User
Posts: 1422
Joined: Sat May 22, 2004 5:28 am
Location: Bucharest
x 8
Contact:

Post by eugen »

oh, i understand now!
here, i have the camera behind the ball all the time...and this gives me so much problems :) (not really, but i have some things i'm not happy with, i hope i'll find fixings for each)
thanks for the informations!
User avatar
Wooden
Halfling
Posts: 58
Joined: Thu Feb 10, 2005 10:35 pm
Location: Arcachon, France
Contact:

Post by Wooden »

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
User avatar
eugen
OGRE Expert User
OGRE Expert User
Posts: 1422
Joined: Sat May 22, 2004 5:28 am
Location: Bucharest
x 8
Contact:

Post by eugen »

i made camera using my own code...
i 'm thinking now that is good to have the camera fixed and only orinet it with the mouse...this will give away alot of problems i have with the camera movement
Post Reply