positioning camera

Previous topic - Next topic

Richard Rae

I can do this in other languages but am having difficulty with GLBasic.How can I place the camera at another objects position.Please don't berate me if this is easy =D.Loaded with cold at the moment  :sick:


Kitty Hello

you have the position of your object in x,y,z -> then you draw your objct with x_movement x,y,z; x_drawobj.
before that, make x_make3d ...; x_camera camera_pos_x, camera_pos_y, camera_pos_z,   object_x, object_y, object_z

then the camera is looking at the object.

Richard Rae

Not quite what I wanted.I want the camera to be at the same position as the object.This would be a dummy object that I would position in an orbit around 0,0,0.The camera would then look at 0,0,0.

Moru

X_CAMERA x_pos, y_pos, z_pos, x_look_at, y_look_at, z_look_at

This is the camera, if you want it to be placed at the position of the object you have at 1, 5, 1 then you just need to set x_pos, y_pos and z_pos to 1, 5, 1. First three parameters are the location of the camera, the last three is where you want the camera to look. If your object is moving around, then you need to set the camera to the same position as the object. Did I understand you correctly?

Richard Rae

#4
Can get the camera to go to the object position and look at it.The only problem is that if you try and rotate the camera around the object it works ok  around the x,z coordinates but flips and oscillates around the z,y and x,y coordinates.Anyway to do this? If you try the following code you will see what I mean.Is there anyway you can make the camera go completely round the axis?
Code (glbasic) Select
ang=0

WHILE(TRUE)

X_MAKE3D 1,1000,45


IF ang=360 THEN ang=0

X_CAMERA 0,y,z,0,0,0
y=SIN(ang)*200
z=COS(ang)*200
INC ang,1

X_DRAWAXES 0,0,0


SHOWSCREEN

WEND
/code]


MrTAToad

#5
Code (glbasic) Select
[code=glbasic]Try the following :

ang=0

WHILE(TRUE)

X_MAKE3D 1,1000,45


IF ang>359.0 THEN ang=0

IF ang>=90.0 AND ang<=270.0
   X_CAMERAUP 0,-1,0
ELSE
   X_CAMERAUP 0,1,0
ENDIF

X_CAMERA 0,y,z,0,0,0
y=SIN(ang)*200
z=COS(ang)*200
  INC ang,1
DEBUG ang+"\n"

X_DRAWAXES 0,0,0


SHOWSCREEN
// KEYWAIT


WEND[/code]

There seems to be a range between 90 and around 270 that you need to flip the camera.

MrTAToad

It does as look as though Gernot's suggestion of moving all the cubes would be best in this case.

It would get rid of the flickering at the two start and end ranges, and hopefully there shouldn't be much of a speed hit either.

Kitty Hello

never a speed hit.
http://www.glbasic.com/forum/index.php?topic=573.0 Take that for the euler angles of your cube.