1 registered members (TipmyPip),
18,619
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Why???
#163460
10/25/07 21:54
10/25/07 21:54
|
Joined: Oct 2007
Posts: 49 Hildesheim, Germany
benni
OP
Newbie
|
OP
Newbie
Joined: Oct 2007
Posts: 49
Hildesheim, Germany
|
Hi, I started learning Lite-C some days ago and now I am working on a small test project. Everything was fine and working, but then I wanted to make the code more beautiful and readable by replacing everything that was seperate xyz coordinates before by VECTORS...a work of minutes as I thought. Many confused hours later I realized that everytime I use vec math functions (vec_sub and so on), the source vector is overwritten. So before every f*****g calculation I have to make copy of that vector to work with. And those vector math functions really suck, vec_scale doesn't accept a negative factor for Example. Before I start re-writing my whole script, is there a reason for using a vectors instead of a set of 3 variables for xyz? 
|
|
|
Re: Why???
[Re: ventilator]
#163462
10/25/07 22:38
10/25/07 22:38
|
Joined: Oct 2007
Posts: 49 Hildesheim, Germany
benni
OP
Newbie
|
OP
Newbie
Joined: Oct 2007
Posts: 49
Hildesheim, Germany
|
#include <acknex.h> #include <default.c>
VECTOR* P1={x=1;y=1;z=8;} VECTOR* P2={x=7;y=4;z=5;} VECTOR* P3={x=1;y=7;z=7;} VECTOR* Result;
var Travel_Speed=1; var Smoothness=1;
function bezier_spline(VECTOR* a, VECTOR* b, VECTOR* c, var Travel_Speed, var Smoothness) { VECTOR* Copy_a=a; VECTOR* Copy_b=b; VECTOR* Copy_c=c; VECTOR* vec_a_b=vec_sub(Copy_b,a); VECTOR* Copy_b = vec_set(Copy_b,b); VECTOR* vec_b_c=vec_sub(Copy_c,b); VECTOR* Copy_c = vec_set(Copy_c,c); VECTOR* vec_a_c=vec_sub(Copy_c,a); VECTOR* Copy_c = vec_set(Copy_c,c);
VECTOR* Copy_vec_a_b=vec_a_b; VECTOR* Copy_vec_b_c=vec_b_c; VECTOR* Copy_vec_a_c=vec_a_c; VECTOR* Copy_vec_a_b=vec_set(Copy_vec_a_b, vec_a_b); VECTOR* Copy_vec_b_c=vec_set(Copy_vec_b_c, vec_b_c); VECTOR* Copy_vec_a_c=vec_set(Copy_vec_a_c, vec_a_c); VECTOR* vec_b_h1; VECTOR* vec_b_h2; VECTOR* vec_b_h1=vec_scale(Copy_vec_a_c,0.5); VECTOR* vec_b_h1=vec_inverse(vec_b_h1);
return(vec_b_h1);
}
function main() { Result=bezier_spline(P1,P2,P3,1,1);
}
PANEL* Anzeige= { digits (10, 10, 5.3, *, 1,Result[0]); digits (10, 20, 5.3, *, 1,Result[1]); digits (10, 30, 5.3, *, 1,Result[2]);
flags = VISIBLE; }
This is an example of my code, I posted a wrong version before, sorry for that.
Everything works as supposed but is this really the way it's done?
|
|
|
Re: Why???
[Re: benni]
#163463
10/25/07 22:52
10/25/07 22:52
|
Joined: Oct 2007
Posts: 49 Hildesheim, Germany
benni
OP
Newbie
|
OP
Newbie
Joined: Oct 2007
Posts: 49
Hildesheim, Germany
|
I reworked everything so now it looks better, but something doesn't work...
vec_b_h1 should be different from vec_b_h2 but isn't.
#include <acknex.h> #include <default.c>
VECTOR* P1={x=1;y=1;z=8;} VECTOR* P2={x=7;y=4;z=5;} VECTOR* P3={x=1;y=7;z=7;} VECTOR* Result;
var Travel_Speed=1; var Smoothness=1;
function bezier_spline(VECTOR* a, VECTOR* b, VECTOR* c, var Travel_Speed, var Smoothness) { VECTOR* Copy_a=a; VECTOR* Copy_b=b; VECTOR* Copy_c=c; VECTOR* vec_a_b=vec_sub(Copy_b,a); vec_set(Copy_b,b); VECTOR* vec_b_c=vec_sub(Copy_c,b); vec_set(Copy_c,c); VECTOR* vec_a_c=vec_sub(Copy_c,a); vec_set(Copy_c,c);
VECTOR* Copy_vec_a_b=vec_a_b; VECTOR* Copy_vec_b_c=vec_b_c; VECTOR* Copy_vec_a_c=vec_a_c;
VECTOR* vec_b_h1=vec_scale(Copy_vec_a_c,0.5); vec_inverse(vec_b_h1); vec_set(Copy_vec_a_c, vec_a_c); VECTOR* vec_b_h2=vec_scale(Copy_vec_a_c,0.5); return(vec_b_h2);
}
function main() { Result=bezier_spline(P1,P2,P3,1,1);
}
PANEL* Anzeige= { digits (10, 10, 5.3, *, 1,Result[0]); digits (10, 20, 5.3, *, 1,Result[1]); digits (10, 30, 5.3, *, 1,Result[2]);
flags = VISIBLE; }
|
|
|
Re: Why???
[Re: benni]
#163464
10/25/07 23:02
10/25/07 23:02
|
Joined: Oct 2007
Posts: 49 Hildesheim, Germany
benni
OP
Newbie
|
OP
Newbie
Joined: Oct 2007
Posts: 49
Hildesheim, Germany
|
ARRRGH... after checking my results nothing works at is it supposed. I have to admit I don't understand the concept of those vector functions... but I'll find out! 
|
|
|
Re: Why???
[Re: benni]
#163465
10/25/07 23:43
10/25/07 23:43
|
Joined: Oct 2007
Posts: 49 Hildesheim, Germany
benni
OP
Newbie
|
OP
Newbie
Joined: Oct 2007
Posts: 49
Hildesheim, Germany
|
So, slowly but sure I'm going mad...
Here an example:
#include <acknex.h> #include <default.c>
VECTOR* P1={x=1;y=1;z=8;} VECTOR* P2={x=7;y=4;z=5;} VECTOR* P3={x=1;y=7;z=7;} VECTOR* Result;
var Travel_Speed=1; var Smoothness=1;
function bezier_spline(VECTOR* a, VECTOR* b, VECTOR* c, var Travel_Speed, var Smoothness) { VECTOR* Copy_a=nullvector; vec_set(Copy_a,a); VECTOR* Copy_b=nullvector; vec_set(Copy_b,b); VECTOR* Copy_c=nullvector; vec_set(Copy_c,c); VECTOR* vec_a_b=nullvector; vec_sub(Copy_b,a); //EXCLUDE THIS!!!
return(Copy_c);
}
function main() { Result=bezier_spline(P1,P2,P3,1,1);
}
PANEL* Anzeige= { digits (10, 10, 5.3, *, 1,Result[0]); digits (10, 20, 5.3, *, 1,Result[1]); digits (10, 30, 5.3, *, 1,Result[2]);
flags = VISIBLE; }
What the hell has the marked line to do with vector Copy_c ???????????? If you exclude/include it the result will change!!! I don't get it.
|
|
|
Re: Why???
[Re: benni]
#163466
10/26/07 00:37
10/26/07 00:37
|
Joined: Oct 2006
Posts: 106
i_program_games
Member
|
Member
Joined: Oct 2006
Posts: 106
|
Ok, I need to know where you are now and what is happening or not happening.
Chaos is a paradox consistently inconsistent.
|
|
|
Re: Why???
[Re: i_program_games]
#163467
10/26/07 09:16
10/26/07 09:16
|
Joined: Oct 2007
Posts: 49 Hildesheim, Germany
benni
OP
Newbie
|
OP
Newbie
Joined: Oct 2007
Posts: 49
Hildesheim, Germany
|
Hello, thanks for your interest - in my last posted script I have a function "bezier spline". This function doesn't do anything special, just a few vector calculations. Then it returns vector Copy_c which is printed by the panel.
The strange thing I don't understand is: When I exclude/include the marked line the result will change - but this calculation seems to have absolutely nothing to do with vector Copy_c.
P.S. You can ignore the variables Travel_Speed and Smoothness.
Last edited by benni; 10/26/07 09:19.
|
|
|
Re: Why???
[Re: Spirit]
#163469
10/26/07 10:37
10/26/07 10:37
|
Joined: Oct 2007
Posts: 49 Hildesheim, Germany
benni
OP
Newbie
|
OP
Newbie
Joined: Oct 2007
Posts: 49
Hildesheim, Germany
|
Quote:
...for instance you are using local variables and then return them, but they cease to exist outside the function and thus all you return is garbage.
Are you sure about that? Where do the local variables leave the function? If I exclude the line " vec_sub(Copy_b,a); ", then vector Copy_c is returned properly. I ask again what has this line to do with vector Copy_c ?
Perhaps I really misunderstand something very badly, so please be patient - If I had found a tutorial about vectors I would have worked this through...but I was so enthusiastic because when I used usual variables instead of vectors everything worked perfectly.
|
|
|
|