Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Ayumi, 1 invisible), 584 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 5 1 2 3 4 5
rotation around a sphere #391473
01/12/12 21:57
01/12/12 21:57
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
I am playing around with spheric levels instead of flat ones, and am having a bit of trouble with player movement around the sphere. I have an almost working code, but it gets strange results at the poles (top & bottom).

Placing the player model on the sphere's surface is pretty straightforward. For a sphere with a radius of 500 for example I do the following:
place_on_surface(My_Planet, My_Vehicle, 500);
Code:
void place_on_surface(ENTITY* Planet, ENTITY* Vehicle, var planet_radius)
{
   VECTOR relative_pos;
   var desired_distance;
   
   //get vehicle position relative to the planet center
	vec_diff(relative_pos.x,Vehicle.x,Planet.x);
	
	//set desired distance from radius
	desired_distance=abs(Vehicle.min_z)+planet_radius;
	vec_normalize(relative_pos,desired_distance);
	vec_add(relative_pos,Planet.x);
	
	//place the vehicle on the planet surface
	vec_set(vehicle.x,relative_pos);
}




Now here comes the tricky part I am having trouble with, the player's rotations. So far this attempt is pretty close to what I want. but I get very strange results when the player reaches the top or bottom of the sphere:
rotate_on_surface(My_Planet,My_Vehicle,my_pan);
Code:
void rotate_on_surface(ENTITY* Planet, ENTITY* Vehicle, var desired_pan)
{
	VECTOR relative_pos;
	ANGLE relative_ang;
	ANGLE result_ang;
	
	//get vehicle position relative to the planet center
	vec_diff(relative_pos.x,Vehicle.x,Planet.x);
	
	//tranform relative position to angle
	vec_to_angle(relative_ang.pan,relative_pos.x);
	
	//build new angle
	vec_set(result_ang,vector(0,0,90));
	ang_rotate(result_ang,vector(0,-relative_ang.pan-90,0));
	ang_rotate(result_ang,vector(0,0,-relative_ang.tilt));
	ang_rotate(result_ang,vector(desired_pan,0,0));
	
	//rotate vehicle
	vec_set(vehicle.pan,result_ang);
}



I keep the desired absolute orientation (pan I want the vehicle to look at) in a separate variable so it dosn't get messsed up during the calculations.

The resuts are "almost" what I need, but even separating the pan like I do does not make my vehicle cross the planet surface in a straight line unless it is going straight across the equator... The farther it is from the middle (equator) the more it turns towards the poles (north/south), kind of like traveling in circles orbiting the poles and turning more and more towards them! And when walking directly on the north/south poles it just goes crazy! (it does stay aligned to the planet, but the pan just freaks out)
Movement Code:
Code:
while(1)
{
   c_move(My_Vehicle,vector(key_w-key_s,0,0),nullvector,IGNORE_MODELS);
   my_pan=cycle(my_pan+key_a-key_d,0,360);
   rotate_on_surface(My_Planet,My_Vehicle,my_pan);
   place_on_surface(My_Planet, My_Vehicle, 500);
   wait(1);
}



Has anyone tried something similar before?
Can you spot what I am doing wrong here?
Any advice would be great.

EDIT:
Uploaded an example video to youtube:
http://www.youtube.com/watch?v=KjgIwm75e8U
(keep in mind this is just placeholder art to test the code)

EDIT2:
Added a second video with a free camera further away so its easier to see whats going on with the vehicle withought getting dizzy:
http://www.youtube.com/watch?v=NXkbrUEMpfQ


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: rotation around a sphere [Re: Carlos3DGS] #391492
01/13/12 10:45
01/13/12 10:45
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
joys of [urlhttp://en.wikipedia.org/wiki/Gimbal_lock]Gimbal lock[/url] you'll need to use quaternion instead of euler calculations.

I think there's an ang_for_axis of something like that which will get you moving as expected

Re: rotation around a sphere [Re: MrGuest] #391502
01/13/12 13:09
01/13/12 13:09
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
I have been giving it some thought, but am still a little confused...

ang_for_axis(ANGLE* vAng, VECTOR* vAxis, var angle);

The way I understand this function (which is probably wrong) I think the values I would need are as follows?:

vAng=vector(desired_pan,0,0);
vAxsis=N
angle=a

Being "N" a normal vector perpendicular to my vehicle position relative to the planet center?
And "a" being the tilt if my vehicle faced the planet center +90?



"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: rotation around a sphere [Re: Carlos3DGS] #391504
01/13/12 13:55
01/13/12 13:55
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Heres an IDEA to think on... it may work, it may not.
But seeing as you have a project to test it in, it will be easier for
you to test than it is for me. laugh

Make a new SPHERE_MDL entity (PASSABLE & INVISIBLE) that surrounds the
existing planet, with the same origin point.

Do a c-trace from your Vehicle OUTWARDS to hit the new sphere.
The HIT struct now contains info about that hit, that means that the
HIT.nx,ny,nz contain the NORMAL of a perfect sphere at the point your ship is
touching it...
You may be able to use that normal to calculate your angles.

I suspect something like this...
Code:
...
   vec_set(Vehicle.pan, hit.nx);                     //set to same as captured normal
   vec_rotate(Vehicle.pan, vector(90,90,0));         //rotate vector to pan/tilt/roll orientation (needs tinkering)
   vec_to_angle(Vehicle.pan, Vehicle.pan);           //convert from direction-vector to angle
   ang_add(Vehickle.pan, vector(desired_pan,0,0));   //rotate to desired pan
...

BTW. This calculation does NOT need to be done IN the entity... A temp vector will do..

Best of luck dude... Your in a hairy area...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: rotation around a sphere [Re: EvilSOB] #391507
01/13/12 14:10
01/13/12 14:10
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
Very interesting idea indeed, that should make everything much simpler!

One question though... Does c_trace hit backfaces? Or are they ignored?

EDIT: seems like backfaces are not hit so I made a planet model with inverted normals. At first it was spazzing out, till I set me=vehicle and INGORE_ME in the trace. But I still get very very strange results though.

Last edited by Carlos3DGS; 01/13/12 14:45.

"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: rotation around a sphere [Re: Carlos3DGS] #391513
01/13/12 15:10
01/13/12 15:10
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
I forgot, c_trace detecting backfaces was phased out AGES ago.. sorry.
[EDIT] A way around this is to reverse the c-trace vectors, ie "c_trace(outside_sphere, vehicle.x, blah)", but who cares now...

But if you got the detection running thats a start.

Importantly, is the planet model PERFECTLY smooth? Otherwise you may get odd behaviour.
Even more odd than when it works RIGHT! Normals are strange little beasties.

So to start getting you to understand normals, we will go a step at a time...
First we will capture the normal, and convert it to an angle.

So if you are getting the normals OK, remember they will need INVERTING as they are
INSIDE faces, and therefore upside-down to what you want. So firstly you need to do this...
Code:
...
   VECTOR temp;
   vec_inverse(vec_set(temp, hit.nx));   //invert direction vector
   vec_to_angle(Vehicle.pan, temp);
...

to get the corrected vector, and force it into the Vehicle.
It may be worth TEMPORARILY increasing the gap between the vehicle and the surface
so when the vehicle performs 'odd' rotations, it wont collide with the surface, and 'disturb' the results.
Or at least make the planet PASSABLE to avoid the above...

While doing this test, put a DEBUG_VAR display showing the pan/tilt/roll of the vehicle.

Then have a fly around the planet, observing the vehicle rotations, and try to figure out the pattern.
(YES, I know. The vehicle's x-axis will currently be pointing UPWARD from the core, thats expected at this point)

HINT: Keep a CLOSE eye on the ROLL value when approaching the poles,
or when the pan or tilt values suddenly "jump' ...


I'll be waiting...



Last edited by EvilSOB; 01/13/12 15:14. Reason: EDIT added

"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: rotation around a sphere [Re: EvilSOB] #391518
01/13/12 15:50
01/13/12 15:50
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
I was working on another version and a new video while you posted.

I ended up not using a second sphere and just using the original planet tracing from out to the planet core.

This is the surrent code:
Code:
VECTOR start_trace;
VECTOR Temp_Vec;

//get the start coordinates for the trace
vec_set(start_trace,Vehicle.x);
vec_sub(start_trace,Planet.x);
vec_normalize(start_trace,vec_length(start_trace)*2);
vec_add(start_trace,Planet.x);

//perform the trace ignoring the vehicle
me=Vehicle;
c_trace(start_trace, Planet.x,IGNORE_ME);

//do angle calculations in a temporary vector
vec_set(Temp_Vec, hit.nx);                     //set to same as captured normal
   vec_rotate(Temp_Vec, vector(90,90,0));         //rotate vector to pan/tilt/roll orientation (needs tinkering)
   vec_to_angle(Temp_Vec, Temp_Vec);           //convert from direction-vector to angle
   ang_add(Temp_Vec, vector(desired_pan,0,0));   //rotate to desired pan

//place results into the vehicle
vec_set(vehicle.pan,Temp_Vec);




And these are the results:
http://www.youtube.com/watch?v=tqJ8LLydSj4

Working on a version that will show pan/tilt/roll on screen to try to understand what is happening...

Last edited by Carlos3DGS; 01/13/12 15:51.

"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: rotation around a sphere [Re: Carlos3DGS] #391525
01/13/12 16:17
01/13/12 16:17
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
Okay, here's a couple things.
First, if your level is always going to be perfectly spherical (or you always want to treat it as perfectly spherical), then the surface normal is just the player position relative to the sphere's origin.

Secondly, I wouldn't have an "absolute pan", since that just won't work rotating with arbitrary axes. This is explained a little bit in this thread that deals with a very similar problem, which is ultimately resolved using this function.

I hope these are helpful.

Jibb


Formerly known as JulzMighty.
I made KarBOOM!
Re: rotation around a sphere [Re: Carlos3DGS] #391527
01/13/12 16:22
01/13/12 16:22
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Looking at this video, you still have some code somewhere that is rotating the vehicle.

This is making the testing look off. If you CANT disable this other panning, then
create another 'ghost' vehicle entity that gets its x/y/z from the 'real'
vehicle
(but a bit further out from the core), but ONLY gets its pan/ilt/roll from the above code...



You say youre NOT using a second sphere... thats cool FOR NOW.
I see the one in the video IS smooth, but will that always be the case?


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: rotation around a sphere [Re: EvilSOB] #391532
01/13/12 17:10
01/13/12 17:10
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
For the finished version of this... Nope, the planets will not be perfect spheres. I currrently disabled my "random planet generator" code for testing while I learn how to get these rotations right. Planets will look more like this:
http://www.youtube.com/watch?v=m8meN7xX7-Y
random planet generator (and shader) working in this video.

But for vehicle angles I will probably not take into account the real surface normals. Just the distance from center and treat it as a sphere (seems waay to commplicated for what I need).
I might consider it though, but after I get how this movement works into my brain for simple spheres.

Off-topic:
The planet gerator works fine but the shader causes random crashes. After getting this movement thing to work I was going to send you a pm about the shader since it is based on the "random terrain shader" we worked on.


Back on topic:
Jibb I read those two threads but am still a little confused with the function...
alignToVec(ANGLE* entAng, VECTOR* vec, VECTOR* axis, var factor)

as an example with my current problem, what data would I put into that function?

entAng= vector(desired_pan,0,0) ?
vec= vec_sub(vehicle.x,planet.x) ?
axis= vector(0,0,1) ?
factor= 1 ?

Did I understand this correctly?


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Page 1 of 5 1 2 3 4 5

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1