## Camera not looking at the center of the screen

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
deepblu
Gnoblar
Posts: 20
Joined: Wed May 11, 2005 7:02 pm

### Camera not looking at the center of the screen

I'm trying to make a simple billiard simulator, and the camera is always looking at the cue ball before the shot. Of course, the cue ball is always at the center of the screen. After the shot, the position of the camera is fixed in the same position, but you can look at any direction using the mouse. The problem with that, is that the action is always in the middle-up part of the viewport, because the ball always goes in the opposite direction of the looking camara direction. So I want the camera to look at the cue ball, but not to position the ball in the center of the viewport, but in a point below the center of the viewport.

¿There's a easy way to do this without applying mathematics?

SuprChikn
Bugbear
Posts: 863
Joined: Tue Apr 19, 2005 6:10 am
Location: Melbourne, Aus
Contact:
When attaching the camera to the cue ball (with an offset so it's behind and a little above the ball), use the lookAt function to tell it to look a distance in front of the ball.

deepblu
Gnoblar
Posts: 20
Joined: Wed May 11, 2005 7:02 pm
I tried to use the function lookat of the camera, but it don't work. If the camera is above the ball, and I look 50 units far, it works, but if the camera is at table level, it has no effect because the ball is at the center of the screen.

sevensevens
Gnoblar
Posts: 21
Joined: Sat May 07, 2005 4:41 am
You could use just call camera->yaw(current_yaw - some_constant) after you centered the que ball on the screen.

johnhpus
Posts: 1186
Joined: Sat Apr 17, 2004 2:49 am
x 3
You could also attach a SceneNode to the SceneNode that moves your cue ball. Set it's position to some point above the cue ball (where you actually want the view centered) and tell that camera to autotrack that new node. This would allow you to easily adjust the view by moving the "offset node".

deepblu
Gnoblar
Posts: 20
Joined: Wed May 11, 2005 7:02 pm
I'll explain the problem with more clarity to explain what's the final result I need. When the camera always look at some object, the object always is at the center of the screen (O), like this

==================
|..................|...................|
|..................|...................|
|..................|...................|
|========O========|
|..................|...................|
|..................|...................|
|..................|...................|
==================

What i want is that the object remains the object that the camera looks at, but in another position of the screen, exactly in a point below screen center like this:

==================
|..................|...................|
|..................|...................|
|..................|...................|
|..................|...................|
|..................|...................|
|========O========|
|..................|...................|
==================

To achieve this, I can't use yaw nor any other parameter of the camera. I only want to scroll the visible area that I can see.

johnhpus
Posts: 1186
Joined: Sat Apr 17, 2004 2:49 am
x 3
You could also attach a SceneNode to the SceneNode that moves your cue ball. Set it's position to some point above the cue ball (where you actually want the view centered) and tell that camera to autotrack that new node. This would allow you to easily adjust the view by moving the "offset node".

deepblu
Gnoblar
Posts: 20
Joined: Wed May 11, 2005 7:02 pm
That dont work. After a shoot the camera is freelook. If the camera is moved above the ball, the situation wiil be this:

............C
.........../..\
........./......\
......./....S....\
...../..............\
----------O------------

C = The camera
S = The new scene node you talk about
O = Cue ball (The ball the camera always look at)

As you can see, the ball appears in the center of the screen, because the new scene node is between the camera and the object ball

johnhpus
Posts: 1186
Joined: Sat Apr 17, 2004 2:49 am
x 3
position of the camera is fixed in the same position,
Forgive me if I misunderstand.

I'm not saying that Camera would be attached to the second node. The second node would be attached to the node that moves the ball. It's only purpose is that it you can tell your camera to "autotrack" this new node. The basic effect of this would be that rather than centering the view on the ball, you can use this new SceneNode to control where the camera looks. Because the new node is attached to the billiard node, it will follow it and I think give the effect your looking for.

I can't do the little ascii pictures, so here's some paintbrush for you:

But yeah, not trying to be unfriendly quoting my post like that. Just thought that you had glossed over it because I do believe it's the solution to your problem.

deepblu
Gnoblar
Posts: 20
Joined: Wed May 11, 2005 7:02 pm
Is a good idea, but doesn't work. I'll try to explain with a picture

The scene node you talk about is the big red point, as is placed above the ball.

Here you can see that when the camera is in position 1 your idea works.

But when the camera is moved a little above the ball (camera in position 2) the ball begins to appear near the center of the screen.

Finally if you put the camera above the New SceneNode, it is looking directly too to the ball.

What I want, is what i show in the image below

The camera always is looking at the white ball, but the ball is not at the center of the screen C, is ALWAYS in the point N of the screen, no matter where the camera is.

johnhpus
Posts: 1186
Joined: Sat Apr 17, 2004 2:49 am
x 3
I see exactly what you mean now. In the future I'll remember to trust people when they say that I'm not getting it. Sorry that you had to go to such effort to get me to shut up

SpannerMan
Posts: 446
Joined: Fri May 02, 2003 10:05 am
Location: UK
Contact:
Im sure you could attach your camera to a tree of nodes to get the effect you want.

Code: Select all

``````
<  +          (C)
|
|
+------+ (N)
``````
So there are three nodes (the +). Your camera is attached to the last node, directed towards C. The first node is at N (the position of your ball).
If you apply your rotations to the first node at N, then that will act as your pivot point and your camera will always be looking just above it.

monster
OGRE Community Helper
Posts: 1098
Joined: Mon Sep 22, 2003 2:40 am
Location: Melbourne, Australia
Contact:
¿There's a easy way to do this without applying mathematics?
No, sorry, there's no easy way and you're probably going to have to use maths!

The cueball will be offset on the screen based on the camera's position relative to it, and where the camera's actually looking. The camera won't be looking directly at the cueball, otherwise the cueball will be in the center of the screen. And then what I imagine you want is that when you move the mouse (or whatever) you want the whole scene to move around the cueball. That's how I've seen other pool games work; the cueball always stays where it is and the rest of the scene moves relative to it.

You can either do this with fancy maths, inverse transforms and the like, or you can do it by reorganising the scene-graph depending on what viewing mode you're in . Normally everything will just be a child of the root, but when you're in this "view" mode you'll move the rest of the scene so that it sits under a child of the cueball's node, then you can easily rotate it realtive to the cueball. Ogre will do all the fancy maths for you, but it'll amount to the same thing. When the player takes the shot and you go back to "free look" mode, you take all the scene nodes out from under the cueball and put them back in at the root of the scene graph.

I hope that makes some sort of sense.

deepblu
Gnoblar
Posts: 20
Joined: Wed May 11, 2005 7:02 pm
The is a problem when attaching a camera to a concrete scene node. The problem is that when the camera is at different distances from the cueball, the cueball is not fixed in a point of the screen. It only works if the ball is always at the same distance of the camera. Indeed happens the same with the fovY parameter of the camera.