Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Orbit Code Malfunction

Author
Message
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 12th Nov 2009 03:20
Hello all i am using this code to make the camera orbit around an object, but it wont do it properly..

All that it does is position itself at the object and pivots in the same position.
I had this working in another program so i really dont know whats going on...



Any help is appreciated..

MSon
20
Years of Service
User Offline
Joined: 13th Jul 2004
Location: Earth, (I Think).
Posted: 12th Nov 2009 05:18 Edited at: 12th Nov 2009 05:19
Heres a simple 'RotateCameraRoundObjectUsingMouse(Obj)' Function, you should be able to change this to rotate automatically instead of by mouse control.



Everyone Be Cool, You, Be Cool.
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 12th Nov 2009 07:15
thanks for that, let me tell you what i want the end result to be, i want to make it like a 3rd person camera for a spaceship.

the other code that i posted had a zooming feature using the mousewheel and the up/down keys, im a bit rusty arent i...

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 12th Nov 2009 12:43
Here's another method, but it only moves the camera vertically between set limits (it doesn't rotate). The method is best suited to following a character around - rather than full rotation around a spaceship so it might not be suitable.

It does however still rotate around the cube when it is moved (use cursor keys).



TDK

lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 12th Nov 2009 13:12
thats very close thankyou vm.

i will see what i can do with it..

lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 12th Nov 2009 23:31 Edited at: 13th Nov 2009 05:51
hmmm thats very weird, i stretched the code out and it makes the cube go slower, owell..

ok my next step is to get the camera to follow the character and only rotate when the right mouse button is down, any suggestions..

EDIT1: Ok i have the rightclick code working properly



ok now i just have to get the camera to rotate when the cube rotates..

EDIT2:


i tried to make the camera follow the object when righclick isnt pressed but it ends up going weird, am i atleast on the right track with this??
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 13th Nov 2009 09:49
ok im just 1 step closer to getting the camera right



the effect i get when i try to pitche the camera screws up alot.

please any help is loved..
feiting shadow
18
Years of Service
User Offline
Joined: 12th Sep 2006
Location:
Posted: 14th Nov 2009 06:35
When complex math is involved, I usually do this:

1) Move camera to object position
2) Set camera to object rotation
3) Use your Sine/Cosine functions if necessary to position it above or below the object. (step 3 might not be necessary if you use a static angle)
4) move object a negative distance.

Voila, math avoided. You do have a few extra lines, but hopefully the speed isn't too necessary. The beauty of this is the rendering is only done once, so the user will never know the shortcuts are used.

Signed
------
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 15th Nov 2009 00:05
thankyou for that feiting shadow but i already have a mostly working code i just need to get the camera to follow in the y rotation...

thanks anyway
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 15th Nov 2009 23:23
can anybody help me with this please??....
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 18th Nov 2009 08:57 Edited at: 18th Nov 2009 09:10
Hey there, I don't think I've seen you around lately. Good to see you.

I've been breaking my head over this for the last 48 hours, and I think I've come up with a workable solution. Of course, I don't know if you still need this, but it was a good exercise for me nonetheless.



My solution uses a lot of complex math, but it works. I kinda wish there was an easier solution. If you need help understanding anything please ask.

Edit:

Some things I forgot to mention:
This demo uses the point camera command, which will always keep the camera right-side-up, so while pitching the cube down, the camera will turn itself around after it reaches the very top of its orbit. That might be a problem if you want true free-flight. I think I might mess around with trying to impose my own up vector on the camera to correct this, but the native DBPro command set makes this very difficult. We'll see.
...I thought I had more things, but I'm going blank right now... I'll post back later if I remember.
Oh, and if someone has a way to do the same thing, while avoiding all that nasty math, please share.
Let me know if this is at least close to what you were going for.
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 18th Nov 2009 17:08
Feiting Shadow's method is what you want in order to have the camera follow the player. Using DBPro you're going to want to use all the shortcuts you can find, as complex math will slow your framerate.

- Set a variable for the distance from the player (zoom)
- Make the mousewheel (or whatever else) modify that variable.
- Set a variable for the angle the camera will be in relation to the player.
- Make your camera rotation controls alter that angle. (using Wrapvalue to keep the angle valid)
- Position the camera at the player position.
- Rotate it using the angle variable in your sin cos calculation.
- Move it backwards the amount in the zoom variable.

Do this each loop and the camera will follow the player at whatever angle and distance you specify.

Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 18th Nov 2009 20:45
feiting shadow's method does not do what mine does. In mine, while the right mouse button is pressed, the user is allowed to rotate the cube without affecting the camera's position at all, and when the right mouse button is up, the camera's position relative to the object is held exactly as the cube rotates. Of course, if feiting shadow's method produces a result that's closer to what lucifer 1101 had in mind, then by all means, skip the math.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 19th Nov 2009 01:01
lucifer 1101:

As none of the code any of us has supplied so far seems to exactly fit the bill, before we go any further, I think it would be best if you clearly explain exactly what you are trying to achieve in detail.

So far, you appear to not be sure of what you are after. You started off with:

Quote: "make the camera orbit around an object, but it wont do it properly"


...and after that, you went on to the 'next step' and completely lost me. So...

1. What controls the cube?

2. What controls the camera?

3. What should the mouse buttons do?

4. What should happen when the mouse buttons are not being used?

Everything in one big hit please - so we know exactly what we are aiming for!

TDK

lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 19th Nov 2009 01:24
thankyou all for your help unfortunately i dont think im ready to do much coding right now, i made a mistake, thats why i am active with 3d modelling..

thanks again..

anyway what i was after was a camer that when the right mouse buton is pressed will orbit around the spaceship when the mouse moves, but when the button is released it goes back to its original position, which it did in my last code snippet, i also wanted zoom with mousez.

and then i was starting to get the camera to follow the rotations of the spaceship(cube) on x,z and y.

the spaceship movement code i had done previously which i was going to integrate into this code is..

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 19th Nov 2009 01:56


TDK

Login to post a reply

Server time is: 2024-11-24 22:37:42
Your offset time is: 2024-11-24 22:37:42