|
|
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
OP
Expert
|
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: Pappenheimer]
#262418
04/23/09 15:58
04/23/09 15:58
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
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: jcl]
#262530
04/24/09 11:58
04/24/09 11:58
|
Joined: Mar 2003
Posts: 3,010 analysis paralysis
NITRO777
Expert
|
Expert
Joined: Mar 2003
Posts: 3,010
analysis paralysis
|
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? 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
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
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. #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
OP
Expert
|
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.  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".  Many hours of brain-bashing, and copious amounts of schnapps have failed to resolve this problem.  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 FOUR  c_traces a frame to achieve. Plus another trace to set the height from the surface. Much work still to do.  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.  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...  And discovered that the pan keeps getting twisted (possibly by gimbal lock ) 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: VeT]
#264954
05/09/09 01:06
05/09/09 01:06
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
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
|
|
|
|