Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (AndrewAMD, TipmyPip, OptimusPrime), 15,359 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 5 1 2 3 4 5
Re: rotation around a sphere [Re: Carlos3DGS] #391533
01/13/12 17:24
01/13/12 17:24
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
Almost -- entAng needs to be the player's actual angle (and not just a representation of it), since that will get directly changed by the function. That is:
alignToVec(my.pan, vec, vector(0, 0, 1), 1); // you got vec right, as well

Also, to smooth things out, you might want to have the last parameter be time_step.

What this will do is align your model to the normal by its local z axis by changing its orientation as little as possible -- so really, whatever your model's previous angle was will determine the direction it is ultimately facing. Then you can use ang_add/ang_rotate (I always forget which one) afterwards if you want to change the ship's pan relative to its current orientation.

It'll make more sense as you put it into practice and fiddle with it, I think.

The planet generator looks really cool grin


Formerly known as JulzMighty.
I made KarBOOM!
Re: rotation around a sphere [Re: JibbSmart] #391547
01/13/12 19:24
01/13/12 19:24
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
Thanks for the compliment on the random planet generator! It took alot of work to figure out all the math for that, I still consider it (and the shader) a work in progress but it's pretty close to what I want.

I got the rotations to work with your function, thanks alot!

Only one problem though... Now I somehow managed to mess up the positioning of my vehicle! This is starting to turn into a huge headache (literally).

The function:
Code:
void align_to_surface(ENTITY* Planet, ENTITY* Vehicle)
{
   VECTOR start_trace;
	VECTOR Temp_Vec;
	
	
	//get the surface position
   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);
	me=Vehicle;
	c_trace(start_trace, Planet.x,IGNORE_ME);
	
	//place vehicle on surface 
	//(taking into account vehicle min_z)
	vec_set(Temp_Vec,hit.x);
	vec_sub(Temp_Vec,Planet.x);
	vec_normalize(Temp_Vec,vec_length(Temp_Vec.x)-Vehicle.min_z);
	vec_add(Temp_Vec,Planet.x);
	vec_set(Vehicle.x,Temp_Vec);
	
	//rotate towards planet core
	vec_sub(Temp_Vec,Planet.x);
	alignToVec(Vehicle.pan, Temp_Vec, vector(0, 0, 1), 1); 
}



JibbSmart's AlignToVec funtion:
Click to reveal..
Code:
function alignToVec(ANGLE* entAng, VECTOR* vec, VECTOR* axis, var factor) {
	vec_rotate(axis, entAng);
	vec_normalize(axis, 1);
	vec_normalize(vec, 1);
	VECTOR rotAxis;
	vec_cross(rotAxis, vec, axis);
	var angle = -acos((float)vec_dot(axis, vec)) * factor * vec_length(rotAxis);
	ANGLE rotAngle;
	ang_for_axis(rotAngle, rotAxis, angle);
	ang_add(entAng, rotAngle);
}



My movement code:
Code:
c_move(vehicle,vector(key_w-key_s,0,0),nullvector,IGNORE_MODELS);
ang_rotate(vehicle.pan,vector(key_a-key_d,0,0));
align_to_surface(Planet, Vehicle);



I know its ugly withought any time_step in there, but its just for testing till I get it to work properly.

This is the result:
http://www.youtube.com/watch?v=1Y2uTAf8twI

EDIT:
it looks as if it was detecting the planet as a box or something... But I have set it's POLYGON flag, I swear!
set(Planet,POLYGON);

Last edited by Carlos3DGS; 01/13/12 19:30.

"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] #391557
01/13/12 20:26
01/13/12 20:26
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
Weird. I would debug the trace visually -- I'd draw_point3d at the hit position, and use DEBUG_VAR to show vec_length(Temp_Vec) before and after you use vec_normalize.


Formerly known as JulzMighty.
I made KarBOOM!
Re: rotation around a sphere [Re: JibbSmart] #391562
01/13/12 21:07
01/13/12 21:07
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
debugging function:
Code:
void align_to_surface(ENTITY* Planet, ENTITY* Vehicle)
{
        VECTOR start_trace;
	VECTOR Temp_Vec;
	
	
	//get the surface position
        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);
	me=Vehicle;
	c_trace(start_trace, Planet.x,IGNORE_ME);
	
	      //DEBUGGING
	      draw_line3d(start_trace,NULL,100);
	      draw_line3d(start_trace,COLOR_RED,100);
	      draw_line3d(Planet.x,COLOR_RED,100);
	      draw_point3d(hit.x,COLOR_RED,100,16);
	
	//place vehicle on surface 
	//(taking into account vehicle min_z)
	vec_set(Temp_Vec,hit.x);
	vec_sub(Temp_Vec,Planet.x);

	      //DEBUGGING
	      DEBUG_VAR(vec_length(Temp_Vec), 100);

	vec_normalize(Temp_Vec,vec_length(Temp_Vec.x)-Vehicle.min_z);

	      //DEBUGGING
	      DEBUG_VAR(vec_length(Temp_Vec), 120);

	vec_add(Temp_Vec,Planet.x);
	vec_set(Vehicle.x,Temp_Vec);
	
	//rotate towards planet core
	vec_sub(Temp_Vec,Planet.x);
	alignToVec(Vehicle.pan, Temp_Vec, vector(0, 0, 1), 1); 
}



RESULT:
http://www.youtube.com/watch?v=r3j5MKgXWR8


"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: JibbSmart] #391563
01/13/12 21:08
01/13/12 21:08
Joined: Dec 2009
Posts: 256
USA , NY
msmith2468 Offline
Member
msmith2468  Offline
Member

Joined: Dec 2009
Posts: 256
USA , NY
I got it working.
It was doing the same thing as yours did in your video but when i made the planet use its polygon it worked perfect.

Double check your planet.


Mikes Wicked Games

www.mikeswickedgames.com
Re: rotation around a sphere [Re: msmith2468] #391564
01/13/12 21:11
01/13/12 21:11
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
checked it... planet is using polygon cry

EDIT:
I am soooooooooooooo stuuuuuupid!!!
Since I am not using my planet generator code... you cannot see the water (another translucent sphere the same size as planet) so I forgot it was even there! I set polygon flag for water too and it works now... Time to go buy another brain!

Anyway thanks alot for your comment, you got me thinking in the right direction when i went to double check planet's polygon flag!

Now I'm off to check the results with my randomly generated planets, and mabe i will consider making the code take into account surface normals...

Last edited by Carlos3DGS; 01/13/12 21:19.

"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] #391569
01/13/12 21:32
01/13/12 21:32
Joined: Dec 2009
Posts: 256
USA , NY
msmith2468 Offline
Member
msmith2468  Offline
Member

Joined: Dec 2009
Posts: 256
USA , NY
Here is a download link to all my files in a zipped folder.
It should run as is.

http://www.mikeswickedgames.com/Planet%20movement.zip


Mikes Wicked Games

www.mikeswickedgames.com
Re: rotation around a sphere [Re: JibbSmart] #391588
01/14/12 00:07
01/14/12 00:07
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
Got it working also with non-spheric surface normals. Wasn't hard at all, I just had to change Temp_Vec for hit.nx

Anyway, I just thought you guys might want to see it working after helping me out:
http://www.youtube.com/watch?v=DJJD1jZ2Ob0

Two new objectives (but they will have to wait till monday):

1-Making it walk to places (no pathfinding or anything complicated, just simple "look towards objective - move forward"), either to another object on the planet surface or to a mouse click on the surface...
2-Fixing those random crashes that the shader produces (I'm pretty sure its the shader, not assigning the material stops the random crashes)


"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] #391595
01/14/12 01:18
01/14/12 01:18
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
Great work laugh It looks good!

1- Shouldn't be too hard. If the object is aligned according to its spherical co-ordinates rather than the normal beneath it, you can just translate the destination into a position relative to the object's orientation (vec_rotateback) and rotate the object's pan (relative to its z axis) towards that point. Since you use actual surface normals, we can set up a temporary angle that uses the spherical co-ordinates instead.

2- A shader shouldn't be able to crash a program. Divide by zero and square root of a negative number, the obvious suspects in traditional programming, don't cause crashes in shaders in my experience -- we just get zero instead. It could be a driver problem. Then again, it could be both -- perhaps the driver's supposed to not crash, but it does, and perhaps the code that triggers it is undesirable anyway.

Anyway, that's just food for thought. Enjoy your weekend and forget about this for now.


Formerly known as JulzMighty.
I made KarBOOM!
Re: rotation around a sphere [Re: JibbSmart] #391601
01/14/12 03:08
01/14/12 03:08
Joined: Dec 2009
Posts: 256
USA , NY
msmith2468 Offline
Member
msmith2468  Offline
Member

Joined: Dec 2009
Posts: 256
USA , NY
It looks Very good! Well done.
Your project looks very interesting id like to see how it progresses. keep us updated.


Mikes Wicked Games

www.mikeswickedgames.com
Page 2 of 5 1 2 3 4 5

Gamestudio download | 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