Gamestudio Links
Zorro Links
Newest Posts
zorro license, IB connection
by AndrewAMD. 12/06/23 17:16
Newbie Questions
by fairtrader. 12/06/23 11:29
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
5 registered members (AndrewAMD, miwok, TipmyPip, 3run, 1 invisible), 631 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 3 of 3 1 2 3
Re: Get the angle of the surface of a normal. [Re: KiwiBoy] #262397
04/23/09 14:11
04/23/09 14:11
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Pappenheimer ::
I cant post a video Im afraid, cause I cant get thew bad effect to show very visually.
The background (the inside of a sphere) makes what is happening unclear.
Plus my camera is still jumping around and flipping a lot. Thats a problem for lanother day.

BTW Im looking for a spider crawling around the inside of a sphere, sticking to the inside surface
no matter what direction it is travelling/facing. (Ive never seen mario galaxy)
Therefore only its pan angle and forward/backward motions are under ITS control.
The spiders tilt and roll are calculated from the surface 'beneath' it.

KiwiBoy ::
Thanks but doesnt help unfortunately. That idea cant get my modal to 'align' itself to the
angle of the obstacle it is being pushed against. And my current height-control coding is
making the model hug up against the surfaces quite fine.
Its just inheriting the angle thats still seems doomed...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Get the angle of the surface of a normal. [Re: EvilSOB] #262400
04/23/09 14:29
04/23/09 14:29
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
HeelX posted an interesting link with source code which re-constructed the way the developers at nintendo might have done it:

http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Main=29359&Number=261343#Post261343

Re: Get the angle of the surface of a normal. [Re: Pappenheimer] #262418
04/23/09 15:58
04/23/09 15:58
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Interesting but no joy. After a bit of testing, I am now certain it ISNT Gimbal-Lock.
After looking at the mario-galaxy demo, Im after the same idea but inside the planetoids.
Unfortunately, after examining the source that came with it, the important function,
AlignToVector appears to be an engine function. (Im looking into that more)

My problem appears to be that the normals Im getting from the 'ceiling' are somehow
angularly different from the 'floor' in some odd way.


Hey Moderators... Unless JCL sticks his head in here again soon, you may want to bounce this thread to
Lite-C Programming.....

Last edited by EvilSOB; 04/23/09 16:01.

"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Get the angle of the surface of a normal. [Re: EvilSOB] #262514
04/24/09 08:49
04/24/09 08:49
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
The suggested method of using vec_to_angle for the normal, and then tilting the model by 90 degrees and rotating it by the pan angle is the mathematically correct way. So from my theoretical point of view I can't give you a suggestion why it still does not work in your script. Maybe there's a mistake with the normal detection, or the angle calculation.

However, as I see that this is a frequently asked question and a long thread, I will implement an engine function for aligning an entity axis to a normal vector, while keeping its rotation. This should solve all those issues. I'll put it on my list for one of the next updates.

When you want to send me your project where an entity moves along floor, wall and ceiling, I'll use it then for a real life test of the new function.

Re: Get the angle of the surface of a normal. [Re: jcl] #262530
04/24/09 11:58
04/24/09 11:58
Joined: Mar 2003
Posts: 3,010
analysis paralysis
NITRO777 Offline
Expert
NITRO777  Offline
Expert

Joined: Mar 2003
Posts: 3,010
analysis paralysis
Quote:
You can correct the pan angle with a second rotation:

vec_to_angle(my.pan,hit.nx); // adapt object to floor slope
my.roll = 0;
ang_rotate(my.pan,vector(0,-90,0)); // make it upright
ang_rotate(my.pan,vector(pan_angle-my.pan,0,0)); // adjust the pan angle
The only thing that I don't understand about this is the pan_angle value...is it the stored my.pan from the previous iteration or is it some fixed value?

Quote:
I will implement an engine function for aligning an entity axis to a normal vector
I think it would be extremely helpful to a lot of people because you could use it to attach things to a mesh also, you could have things appear to be traveling over a mesh, you could simulate anti-gravity for games like prey,you could make some custom collision effects, there are a lot of uses.

Re: Get the angle of the surface of a normal. [Re: NITRO777] #262637
04/25/09 03:42
04/25/09 03:42
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Originally Posted By: JCL
However, as I see that this is a frequently asked question and a long thread, I will implement an engine function for aligning an entity axis to a normal vector, while keeping its rotation. This should solve all those issues. I'll put it on my list for one of the next updates.
Kewl! An engine function to take all the evil math would remove a lot of the pain.
(Do you want me to put a post in the "The Future" forum, or can someone move this whole thread there?)

But... If possible, can you make the function change a VECTOR or ANGLE rather than a whole entity?
That way we can slice up the result for our own smoothing coding, and also still be useful
directly on an entity if we supply "entity_name.pan" as the parameter that gets "aligned".

Anyway, as youve requested, here is my whole sample code, I cant put it on my web-space from here at work.
But the two models it needs are available from there. Earth-i.mdl and Spike.mdl
[NOTE] This sample code does not include any 'knowledge' from either JCL or Nitro777.
I will attempt to integrate that knowledge shortly.

I have added a couple of trace lines for your viewing pleasure, BLUE is where it gets its height from,
and RED is where its getting its normal(and therefore angle) from.
After seeing these in action, I suspect there IS something of a flaw in my logic flow of
retrieving which normal to use, and that is being aggravated by my 'normal to angle' shortcomings.
Click to reveal..
Code:
#include <acknex.h>
#include <default.c>

//Player pointer of preference
ENTITY* Player;

//function prototypes
function camera_handling();
function draw_trace_line(VECTOR*,VECTOR*,COLOR*);




//action function

action player_action()
{
	var HeightLock = 30;		//height above surface setting
	//
	wait(1);		c_setminmax(my);	Player = my;	
	VECTOR tmpV;	
	while(1)
	{	//move or rotate me
		if(key_cuu)	c_move(my,vector( 50*time_step,0,0),nullvector,GLIDE|IGNORE_PASSABLE);
		if(key_cud)	c_move(my,vector(-50*time_step,0,0),nullvector,GLIDE|IGNORE_PASSABLE);
		if(key_cul)	my.pan += time_step;
		if(key_cur)	my.pan -= time_step;
		if(key_grave)	{	my.pan += 90;								wait(-0.25);	}
		if(key_bksp)	{	vec_fill(my.x, 0);	my.pan=0;		wait(-0.25);	}
		//
		//
		//get surface below me to set height.
		vec_set(tmpV, vector(0,0,-999));		vec_rotate(tmpV, my.pan);
		c_trace(my.x, vec_add(tmpV, my.x), IGNORE_ME | USE_BOX | IGNORE_PASSABLE);
		if(trace_hit)	// Hit, so adjust my height to be HeightLock quants above the surface
		{
			/* draw BLUE line from me to HEIGHT target */	draw_trace_line(my.x, target, vector(255,0,0));
			if(vec_dist(my.x, target.x) != HeightLock)
				c_move(my, vector(0,0,HeightLock-vec_dist(my.x, target.x)), nullvector, GLIDE);	
		}
		//
		//###### BEGIN problem area ######
		
		
		//
		//get surface below me to set tilt/roll.
		vec_set(tmpV, vector(0,0,-50));		vec_rotate(tmpV, my.pan);
		c_trace(my.x, vec_add(tmpV, my.x), IGNORE_ME | USE_BOX | IGNORE_PASSABLE);
		if(trace_hit)	// Hit, so adjust MY angle to match surface using NORMAL
		{
			/* draw RED line from me to ANGLE target */		draw_trace_line(my.x, target, vector(0,0,255));
			vec_rotate(normal, vector(my.pan,0,0));
			vec_set(my.pan,vector(my.pan,asin(-normal.x),asin(-normal.y)));
			if(normal.z<0)		my.tilt = 180 - my.tilt;
		}
		
		
		//###### END problem area ######
		wait(1);
	}
}






function main()
{	
	fps_max = 60;	
	mouse_mode=4;
	video_set(800,600,0,2);
	vec_fill(sky_color.blue, 64);
	level_load(NULL);
	ent_create("earth-i.mdl", vector(0,0,5000), NULL);
	ent_create("spike.mdl", vector(0,0,100), player_action);
	camera_handling();
	while(1)		wait(1);	
}





function camera_handling()
{
	VECTOR tmpV, pos_off, ang_off;	//working space
	vec_set(pos_off, vector(-300,0,60));		//TWEAK :: distance of camera from ball.
	vec_set(ang_off, vector(0,15,0));			//TWEAK :: adjust angle of camera AFTER centered on player

	while(1)
	{
		if((Player)&&(def_camera==0))
		{
			//position camera
			vec_set(tmpV, pos_off);		vec_rotate(tmpV, Player.pan);
			vec_add(tmpV, Player.x);	vec_set(camera.x, tmpV);	
			
			//rotate camera toward player
			vec_set(tmpV, Player.x); 	vec_sub(tmpV, camera.x);	
  			vec_to_angle(camera.pan, tmpV);
			if(tmpV.x<0)	{  camera.pan -= 180;	camera.tilt = 90-(camera.tilt-90);  }
  			vec_add(camera.pan, ang_off);
		}
		proc_mode = PROC_LATE;
		wait(1);
	}
}


function draw_trace_line(VECTOR* start,VECTOR* end,COLOR* col)
{
	VECTOR tStart, tEnd;
	vec_set(tStart, start);		vec_set(tEnd, end);	
	wait(1);
	draw_line(vec_to_screen(tStart,camera), col, 100);
	draw_line(vec_to_screen(tEnd,  camera), col, 100);
}

PS :: I feel this thread SHOULD be moved out of "Ask the Developers" as it has grown much too huge to belong here.
Im just not sure where it should go except maybe "The Future". I'll leave that up to the moderators...



"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Get the angle of the surface of a normal. [Re: EvilSOB] #262935
04/27/09 04:19
04/27/09 04:19
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
JCL :: BEWARE MY SAMPLE CODE! It has a serious design flaw in retrieving a normal to use. mad
It is prone to completely "losing the plot" about what it considers is the surface to match itself to,
especially if you travel forwards AND turn left at the same time. It suffers from a severe angular "runaway". crazy
Many hours of brain-bashing, and copious amounts of schnapps have failed to resolve this problem. confused

I have since developed a hideous new way of staying level with the surface that looks promising so far,
that doesnt use normals at all, but it is still currently requiring sick FOUR sick c_traces a frame to achieve.
Plus another trace to set the height from the surface. Much work still to do. sleep

So if you can find a way to get my old code going, I will be grateful. But I am no longer depending on it. laugh
This doesnt meant I dont still want the "align-to-normal" engine function, I can think of
a couple of other places I could really use it.

[EDIT] Got it down to just four c_traces now, and still hacking... laugh
And discovered that the pan keeps getting twisted (possibly by gimbal lock mad) when near the spherical "equator".
But a quick question to anyone.
According to the manual, c_trace is a "slow" function. Even slower when using long range tracing.
BUT, if I have a long trace that hits a close object, does this make it roughly as fast as a short scan hitting the same object?



Last edited by EvilSOB; 04/27/09 05:18. Reason: Update and question

"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Get the angle of the surface of a normal. [Re: EvilSOB] #264864
05/08/09 14:47
05/08/09 14:47
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline
Serious User
VeT  Offline
Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
How are you, EvilSOB? smile
Did you finish your work with normals?


1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: Get the angle of the surface of a normal. [Re: VeT] #264954
05/09/09 01:06
05/09/09 01:06
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
No, unfortunately. I am still stuck on this problem.
But I have gotten halfway through a work-around using 4 c-traces and a calculation
to get a genuine angle because I think my logic in retrieving a normal to use is wrong.
Im still having issues with Gimbal lock even so. Once I get that sorted I can test better,
and try to use the normals rather than 4 traces per frame.

But Ive had a more urgent sub-project pop-up since then so this is on hold for now.
I am still open for suggestions though, cause I WILL be getting back to this...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Get the angle of the surface of a normal. [Re: EvilSOB] #265389
05/12/09 12:37
05/12/09 12:37
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline
Serious User
VeT  Offline
Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
Okay, i'd also return to this in near time
(somewhere i got an example of smoothly climbing the walls, but it was compiled exe... i'd look for it, when i'd be home)


1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Page 3 of 3 1 2 3

Moderated by  old_bill, Tobias 

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