how do i have camra follow object?

Advanced game related topics
scurrier
Enthusiast
Enthusiast
Posts: 169
Joined: Sat May 03, 2003 4:10 am

how do i have camra follow object?

Post by scurrier »

how do i get the camera to follow and stay in back of object?

anyone know how to do this and how do i make my object move correctly

exmple:
spaceship when i turn how do i make it turn like it's moving not just turn left or right or up or down?


Thanks
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Post by gnasen »

Code: Select all

EnableExplicit

InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()

Add3DArchive("C:\Programme\PureBasic\4.51RC1\Examples\Sources\Data\", #PB_3DArchive_FileSystem)

#CameraSpeed = 5

Global KeyX.f, KeyY.f, MouseX.f, MouseY.f

#screen_width  = 800
#screen_height = 600

OpenWindow(0,0,0,#screen_width, #screen_height, "IN3D")
OpenWindowedScreen(WindowID(0),0,0,#screen_width, #screen_height,0,0,0)
 
LoadMesh(0,"robot.mesh")
LoadTexture(0, "Geebee2.bmp")
CreateMaterial(0, TextureID(0))

CreateEntity(0, MeshID(0), MaterialID(0))
EntityMaterial(0, MaterialID(0))
CreateEntity(1, MeshID(0), MaterialID(0),250,0,0)
EntityMaterial(1, MaterialID(0))

Define theta.f    = 0
Define phi.f      = 0
Define radius.f   = 500

CreateCamera(0, 0, 0, 100, 100)
CameraLocate(0,0,0,800)
RotateCamera(0,0,0,0,#pb_absolute)
   
Define EventID.l

Repeat
  
  Repeat
    EventID = WindowEvent()
    Select EventID
      Case #PB_Event_CloseWindow
        End
    EndSelect
  Until EventID = 0
  
  ExamineKeyboard()
  ExamineMouse()
  
  ClearScreen(RGB(0, 0, 0))
  
  If ExamineKeyboard()
    
    If KeyboardPushed(#PB_Key_Up)
      radius + 10
    ElseIf KeyboardPushed(#PB_Key_Down)
      radius - 10
    EndIf
    
  EndIf
  
  MouseX = -(MouseDeltaX()/10)*#CameraSpeed/2
  MouseY = -(MouseDeltaY()/10)*#CameraSpeed/2
  
  theta + MouseY
  phi   + MouseX
  
  Define x.f,y.f,z.f
  x = radius*Sin(theta * #PI / 180)*Cos(phi * #PI / 180)
  y = radius*Cos(theta * #PI / 180)
  z = radius*Sin(theta * #PI / 180)*Sin(phi * #PI / 180)
  
  CameraLocate(0,x,y,z)
  RotateCamera(0,270-theta,270-phi,0,#pb_absolute)
  
  RenderWorld()
  FlipBuffers() 
  
Until KeyboardPushed(#PB_Key_Escape)

CloseScreen()
ahh, it has been a long day, just wrote this message in german....

Change the path of Add3DArchive() to your own pb folder.
Move camera with mouse, zoom with up/down keys.
I hope it will help you getting started ;)

(it is just a third person cam. To follow your object, you will have to adjust the rotation of the entity)
Last edited by gnasen on Thu Oct 14, 2010 9:23 pm, edited 3 times in total.
pb 5.11
scurrier
Enthusiast
Enthusiast
Posts: 169
Joined: Sat May 03, 2003 4:10 am

Thanks

Post by scurrier »

thanks i will try it and let you know how it works
scurrier
Enthusiast
Enthusiast
Posts: 169
Joined: Sat May 03, 2003 4:10 am

IncludeFile "define.pb"

Post by scurrier »

where do i find this file?
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Post by gnasen »

The files should be in the examples folder of your purebasic installation.
pb 5.11
scurrier
Enthusiast
Enthusiast
Posts: 169
Joined: Sat May 03, 2003 4:10 am

Not in My Install

Post by scurrier »

the define.pb is not in my install looked in 4.3 4.31 4.02 3.93
none of mine have this file can u post it?

thanks sean
scurrier
Enthusiast
Enthusiast
Posts: 169
Joined: Sat May 03, 2003 4:10 am

define.pb

Post by scurrier »

can anyone post define.pb I can't find it on my HD looked in 4 different PB version i don't have it. Is it from a UserLib?
if so can someone post the name and download URL

Thanks

Sean
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Post by gnasen »

Sorry, my fault :oops: When I made this snippet for you, I forgot to delete this lines:

Code: Select all

IncludeFile "define.pb"
Define camera.object
I thought all the time the material would be missing....

I corrected the code above
pb 5.11
scurrier
Enthusiast
Enthusiast
Posts: 169
Joined: Sat May 03, 2003 4:10 am

Not Exactly What I want

Post by scurrier »

Not Exactly what i was looking for but thanks
let me clarify

the camera follows a plane chopper space ship ect...

how to make the object #1 look like it's flying not just moving
and the camera follows behind it not too close but not too far away

so when you turn left the object rotates a bit abd moves on the correct axis-es so X,Z would be INC depending on what direction you are pointed or it could be X,Y or Y,Z do u know what I am talking about

if not I can send you an example through e-mail

Thanks Sean
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Re: Not Exactly What I want

Post by gnasen »

scurrier wrote:how to make the object #1 look like it's flying not just moving
You must have an environment, otherwise you cant see any movement at all. Something like stars in the background, otherwise the player has no orientation in the void ;)
scurrier wrote:and the camera follows behind it not too close but not too far away
If it should follow your object in a static way, it would be enough to move the camera behind your object (just change theta/phi) and add to theta and phi the rotation of the object (X/Y).
scurrier wrote:so when you turn left the object rotates a bit abd moves on the correct axis-es so X,Z would be INC depending on what direction you are pointed or it could be X,Y or Y,Z do u know what I am talking about
I think you mean that the camera follows the movement of the object like a lazy dog. So if the object moves, the camera will only move after the angle changes too much. Like if the camera is in a box behind the spaceship, and not in a point, right?

This one is not so easy, because the spherical coordinate system will make the camera wobble (you can easily try that). In this case I think you must rotate the spherical coordinate system that it fits with the relative one of the object. Hm, hard to explain.

Maybe someone knows a better way for doing this?
pb 5.11
hunter
New User
New User
Posts: 5
Joined: Thu Oct 14, 2010 8:47 pm

Re: how do i have camra follow object?

Post by hunter »

Hi gnasen,

Could you please add camera left right move support?
I need exactly third person camera..
Thank you bro.
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Re: how do i have camra follow object?

Post by gnasen »

im not sure what you mean with moving the camera left/right. Do you mean, that the "person" is not in the center but moving to the left/right side of the screen if you are behind it?
It would be nice if you could give an example :)
pb 5.11
hunter
New User
New User
Posts: 5
Joined: Thu Oct 14, 2010 8:47 pm

Re: how do i have camra follow object?

Post by hunter »

Like this

http://www.youtube.com/watch?v=5GUXKEjm0ho
(Start from 1:40)


I think that this kind of control must include to "PureBasic - Ogre" examples..Its better than fps camera.
Thank you.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: how do i have camra follow object?

Post by PMV »

You can programm it and ask Fred to add this codepeace to the examples. :lol:

You are asking for a ready-to-use-code. I hope you know this. :wink:

The camera is nothing more than a object like all other. It has a
position and direction in a 3D-Environment. To move 2 objects
relative to each other, you only need to move this two objects
in the same way. If you want, that the camera is always behind
the player-model, then you need a litte mathematic and the
coordinates of the player-model. Than you add the distance from
the camera to this coordinates to set the position of the camera
to this new x-, y- and z-coordinates.

The video shows complex camera-movement with mouse-input.
Thats not that easy and i doesn't think, there is some one with so
much free time, that he will code it for you.

MFG PMV
hunter
New User
New User
Posts: 5
Joined: Thu Oct 14, 2010 8:47 pm

Re: how do i have camra follow object?

Post by hunter »

PMV,
If I could I would not ask. I'm a newbie and try to understand and produce something. I know its not fair but what can I do? I'm trying to understand Purebasic with examples.
Actually, I hate such answers(forgive me), If you don't want to help then why do you write such words. Obviously It does not help to get new users to PureBasic .
I can add something to community after got the idea behind of the software.
Your post did not encourage me and I'm thinking to myself, "I don't have to put my questions here?"

If I get such posts, of course I will leave the forum.

Please PMV, don't do that.

I understand that Why "gnasen" is identified as "Enthusiast" but you don't.

Regards, anyway.
Post Reply