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.

AppGameKit Classic Chat / Camera orbit object?

Author
Message
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 1st Mar 2018 23:27
Hey Gang, I have not been about much over the last few months due to life getting busy but now I want to start making this game I have been planing for the last 3 years and instantly hit a roadblock in the 3d math!

I want to make the camera orbit an object based on the mouse drag, its for a space game, the camera will always look at the player ship, click and drag the mouse and the camera should move in the opersit direction to the drag maintaining its current distance (typical space game 3d camera movement), I have searched google for advice and cobbled some code togeather that does not work properly, every solution out there uses in built engine functions to achive this, I have tried to interprate the code and recreate in AppGameKit but I'm no math guy and I dont really know where I am going wrong or what to change, the below is the closest I can get to what I need and its miles away!

This is the best I can do based on the information Google can turn up, I'm sure its close but I know its not quite right


Please someone help and put me out of my misery with some code that works, I am utterly lost trying to figure this out
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 2nd Mar 2018 05:50 Edited at: 2nd Mar 2018 06:31
I didn't plan on doing any dev stuff tonight but saw this and thought it would be interesting.

I think I ended up finding the same tutorial you had maybe.... C code using OpenGL? Anyway, I converted that but it also does not work... I suspect it probably works as well as the original source though which was probably also flawed. lol

Still here is the code for what it's worth.



I think the main thing different over yours is I tweaked it to set the start point (oldX, oldY) when the mouse button is first clicked. So just clicking around on the screen in isolation does not cause rotation and otherwise mess things up.

The issue is clearly in the formulas to convert 2D screen positions and movement into 3D rotations and seems mainly to be an issue with the calculation of the Z coordinate (I *think*) because I notice sometimes it basically just zooms in and out.

Might be worth dropping back to implementing it as a auto flyby orbit. Get that working for orbiting around X & Z and for orbiting around Y & Z.
Then maybe focus on trying to manage it with mouse movement controlling it.

It might be better to use Quaternions. I think AGK2 supports it.

Also I thought about approaching it from rotating the object (cube) itself then having that cast out a ray in direction facing a set distance (radius) or more likely just moving the cube (or a dummy object) forward a set distance and positioning the camera there. That might be simpler.

I think that is actually how I would probably approach it but again the issue still comes in from converting 2D mouse position and movement into 3D rotation of the cube. It is just not something I've ever had a need to do before so never experimented or researched it even until just now. Otherwise I would gladly share a working solution.
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 2nd Mar 2018 11:37
Thanks for taking the time to give it a try Gar and yes it looks like we were working from the same (maybe flawed) C/OpenGL code, it was the only solution I could find that used actual math and not inbuilt functions so I thought it had to be the best starting point but not being able to test the source I am unsure how it performs.

Taking onboard your comment about mouse position and movement I am thinking maybe not use mouse position as such but use a mouse drag direction combined with the distance the mouse has moved and apply that to the camera local ....



Now to see if I can apply this to the camera code and see if I can get more stable results.
hendron
8
Years of Service
User Offline
Joined: 20th Dec 2015
Location:
Posted: 2nd Mar 2018 17:27
Here is basically how I handle it. Normally I'd use a Spherical Coordinate UDT instead of globals, but just as an example...

PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 2nd Mar 2018 18:54
That is perfect, thank you so much, you would not belive how long I have been trying to get this working!

I shifted the code around a bit and added some limits to the distance and elevation, made it 'drop in' ready for other projects and consolidated the globals



Thanks again
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 2nd Mar 2018 19:09 Edited at: 2nd Mar 2018 19:10
I'm out for my birthday lunch but that looks interesting. A quick look at the code seems like the C/GL code had the formula messed up with Y and Z calculations being switched around. Course that is just based on my cell phone quick analysis. I am alos looking forward to trying it out later.
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 2nd Mar 2018 19:25
Happy Birthday Gar, enjoy the lunch, I'm off out to the local steak house soon, no occoasion, well other than being friday and clebrating the fact I can spend the weekend in front of my PC in the warm after 5 days of trudging about on a building site in the snow and ice, I think that warrents a pint and a tee-bone.

I think I now have all the base code I need to start building this project, can't wait to get started.
hendron
8
Years of Service
User Offline
Joined: 20th Dec 2015
Location:
Posted: 2nd Mar 2018 19:30
@PartTimeCoder
No problem, glad it helped. Nice re-factoring there.

@GarBenjamin
Yeah, one thing you have to look out for when searching out formulas for this kind of stuff is how the axes are laid out. I find that most of the time, they don't match AGK's. For instance, the formula that I use in that example is the standard one to convert a Spherical coordinate into a Cartesian coordinate. But, in the articles you'll find on it, x = depth, y = left/right, z = up/down, so you have to compensate for that in your function.
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 2nd Mar 2018 21:39
Another way of doing this is not to use any maths at all: just place the camera on the space ship, rotate the camera the desired angle and then move the camera back.



I use this method quite a lot for positioning cameras and objects and thought it might be a useful alternative for people who struggle with maths.
Hover Car Race Challenge! - available now on Google Play
Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB
hendron
8
Years of Service
User Offline
Joined: 20th Dec 2015
Location:
Posted: 2nd Mar 2018 22:26 Edited at: 2nd Mar 2018 22:29
Just thought I'd throw this in as well. It's more of a preference, really. I'm using this same type of camera control for the level editor I'm working on for my project. I've found that using a non-linear distance adjustment feels a bit more natural to me when dollying the camera in/out with the mouse wheel. The distance the camera moves is smaller or larger depending on the current distance. This might not be the best option for your project, but might be worth a try.

PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 2nd Mar 2018 23:07
@29 games, I wish I had of thought of that 2 or 3 weeks ago!, saved to snippets for later use, I can actully use this system, along side the math based system for a 'chase' type transition from one location to another, but I would set the angle of the object based on the direction to move and set it in motion and have the camera follow behind at the same angle.

@hendron, I had that thought of slowing the zoom fator the when close to the object I also need a variable zoom limit for larger objects, I attach the camera to a dummy object and attach the dummy object to various other objects, planets, starbases, ships etc and need to setup the camera for each object type based on its size so I will implement a variable zoom system at some point.



PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 8th Mar 2018 13:38
Quote: "Another way of doing this is not to use any maths at all: just place the camera on the space ship, rotate the camera the desired angle and then move the camera back."


Yeah that was what I came across too when searching, but changing the camera forward and back each frame for anything more demanding causing flickering and noticeable camera movement.

It did work for that car game with checkpoints and cubes with a lot of GoSub routines, but didn't work with my 3D physics based game Cube House Kings. I am now calculating angles and using the CameraLookAt function. Probably could get better results and probably should limit the angles to something like 180 (if you rotate one direction it handles an angle variable that can be thousands instead of +180 or -180.
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 9th Mar 2018 22:44 Edited at: 9th Mar 2018 22:46
You can also use the MoveCameraLocalX(), (Y) and (Z) commands. Whatever code you use to trap mouse drags and mouse wheel can move the camera around, always pointing at the object.

This code sort of illustrates what I mean, although the distance of the camera changes on the x/y movement.



This is quick and dirty, I typed it while at work. Obviously you would have to modify the code.
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 10th Mar 2018 14:56
I'll show you my approach on this subject visually. If you are having difficulties then I'll post some code:
Rick Nasher
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 10th Mar 2018 22:35
The real kicker is to also combine above code with a geometry avoiding routine, which I did after janbo showed me the best practice last year.
I'm hoping to release an update soon. but first want to iron out few minor additional things.( I keep adding and tweaking)

Login to post a reply

Server time is: 2024-04-20 11:23:41
Your offset time is: 2024-04-20 11:23:41