0 registered members (),
18,561
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Newbie Vector Problem!!!
#163085
10/24/07 17:24
10/24/07 17:24
|
Joined: Oct 2007
Posts: 49 Hildesheim, Germany
benni
OP
Newbie
|
OP
Newbie
Joined: Oct 2007
Posts: 49
Hildesheim, Germany
|
Hello everybody, could you please to a short look and tell me why my script is not working? I've tested it with usual variables instead of vectors and it worked. But with vectors I only get 0,0,0 as result! #include <acknex.h> #include <default.c> var Point1[3]={5,5,5}; var Point2[3]={2,2,2}; var vecPoint1_Point2[3]; function calculateVector(a,b) { return(vec_sub(a,b)); } function main() { screen_color.blue=150; vecPoint1_Point2=calculateVector(Point1,Point2); PANEL* Anzeige= { digits (10, 10, 5, *, 1,vecPoint1_Point2[0]); digits (10, 20, 5, *, 1,vecPoint1_Point2[1]); digits (10, 30, 5, *, 1,vecPoint1_Point2[2]); flags = VISIBLE; } } Thanks for your response 
|
|
|
Re: Newbie Vector Problem!!!
[Re: Lukas]
#163088
10/24/07 17:54
10/24/07 17:54
|
Joined: Oct 2007
Posts: 49 Hildesheim, Germany
benni
OP
Newbie
|
OP
Newbie
Joined: Oct 2007
Posts: 49
Hildesheim, Germany
|
Thanks for your fast response but both your suggestions don't´work  @shadow969: calculateVector(a,b) is O.K. as I tested it with non-vector variables. @Lukas: Strangely, I get random numbers with your suggestion.
|
|
|
Re: Newbie Vector Problem!!!
[Re: benni]
#163089
10/24/07 18:03
10/24/07 18:03
|
Joined: May 2007
Posts: 2,043 Germany
Lukas
 
Programmer
|
 
Programmer
Joined: May 2007
Posts: 2,043
Germany
|
Quote:
@Lukas: Strangely, I get random numbers with your suggestion.
If you change this:
Quote:
vecPoint1_Point2=calculateVector(Point1,Point2);
to: Code:
vec_set(vecPoint1_Point2,calculateVector(Point1,Point2));
it schould work 
|
|
|
Re: Newbie Vector Problem!!!
[Re: benni]
#163091
10/24/07 20:10
10/24/07 20:10
|
Joined: Jan 2006
Posts: 1,829 Neustadt, Germany
TWO

Serious User
|

Serious User
Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
|
This should work:
#include <acknex.h> #include <default.c>
VECTOR* Point1 = { x=5; y=5; z=5; } VECTOR* Point2 = { x=2; y=2; z=2; } VECTOR* vecPoint1_Point2;
VECTOR* calculateVector(VECTOR* a, VECTOR* b) { return(vec_sub(a,b)); }
void main() { screen_color.blue=150;
vecPoint1_Point2=calculateVector(Point1,Point2); }
PANEL* Anzeige= { digits (10, 10, 5, *, 1,vecPoint1_Point2.x); digits (10, 20, 5, *, 1,vecPoint1_Point2.y); digits (10, 30, 5, *, 1,vecPoint1_Point2.z);
flags = VISIBLE; }
|
|
|
Re: Newbie Vector Problem!!!
[Re: benni]
#163092
10/24/07 20:11
10/24/07 20:11
|
Joined: May 2007
Posts: 2,043 Germany
Lukas
 
Programmer
|
 
Programmer
Joined: May 2007
Posts: 2,043
Germany
|
Code:
#include <acknex.h> #include <default.c>
VECTOR* Point1 = {x=5; y=5; z=5;} VECTOR* Point2 = {x=2; y=2; z=2;} VECTOR* vecPoint1_Point2 = {x=0; y=0; z=0;}
function calculateVector(VECTOR* a,VECTOR* b) { return(vec_sub(a,b)); }
PANEL* Anzeige= { digits (10, 10, 5, *, 1,vecPoint1_Point2.x); digits (10, 20, 5, *, 1,vecPoint1_Point2.y); digits (10, 30, 5, *, 1,vecPoint1_Point2.z);
flags = VISIBLE; }
function main() { screen_color.blue=150; vec_set(vecPoint1_Point2,calculateVector(Point1,Point2)); }
VECTOR* vecPoint1_Point2; creates a vector-pointer, not a vector so it must be VECTOR* vecPoint1_Point2 = {x=0; y=0; z=0;}  And I think it's not good to define a panel in the main function. I tried running the script but the results are wrong. If you replace vec_set(vecPoint1_Point2,calculateVector(Point1,Point2)); with vec_set(vecPoint1_Point2,vec_sub(Point1,Point2)); it works. Dunno why... ------------------------- EDIT: TWO was faster If you replace VECTOR* vecPoint1_Point2; with VECTOR* vecPoint1_Point2 = {x=0; y=0; z=0;} his code works fine  Dunno why that works: vecPoint1_Point2=calculateVector(Point1,Point2); I think normally you must use vec_set...
Last edited by Lukas; 10/24/07 20:15.
|
|
|
Re: Newbie Vector Problem!!!
[Re: TWO]
#163093
10/24/07 20:19
10/24/07 20:19
|
Joined: Oct 2007
Posts: 49 Hildesheim, Germany
benni
OP
Newbie
|
OP
Newbie
Joined: Oct 2007
Posts: 49
Hildesheim, Germany
|
With slightly modified PANEL... digits (10, 10, 5, *, 1,vecPoint1_Point2[0]); digits (10, 20, 5, *, 1,vecPoint1_Point2[1]); digits (10, 30, 5, *, 1,vecPoint1_Point2[2]); ...it works! Thanks to everyone ! 
|
|
|
|