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
1 registered members (TipmyPip), 18,606 guests, and 5 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
Newbie Vector Problem!!! #163085
10/24/07 17:24
10/24/07 17:24
Joined: Oct 2007
Posts: 49
Hildesheim, Germany
benni Offline OP
Newbie
benni  Offline 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: benni] #163086
10/24/07 17:33
10/24/07 17:33
Joined: Oct 2006
Posts: 873
S
Shadow969 Offline
User
Shadow969  Offline
User
S

Joined: Oct 2006
Posts: 873
function calculateVector(var a, var b)
{
return(vec_sub(a,b));
}

i think that'll do it

Re: Newbie Vector Problem!!! [Re: benni] #163087
10/24/07 17:34
10/24/07 17:34
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
Your vectors aren't defined correctly.

You must define them like this:

VECTOR* Point1 = {x=5; y=5; z=5;}
VECTOR* Point2 = {x=2; y=2; z=2;}
VECTOR* vecPoint1_Point2;



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 Offline OP
Newbie
benni  Offline 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 Offline

Programmer
Lukas  Offline

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: Lukas] #163090
10/24/07 19:50
10/24/07 19:50
Joined: Oct 2007
Posts: 49
Hildesheim, Germany
benni Offline OP
Newbie
benni  Offline OP
Newbie

Joined: Oct 2007
Posts: 49
Hildesheim, Germany
Still doesn't work, now I get "Empty pointer in function" message.
It is not absolutely essential for me to get this done, but I made a script for Bezier Splines with lots af vector calculations. At this point I have all vectors
splitted off in their components which looks pretty messy, and I would like to work directly with vectors.
Perhaps you can copy the code and test it if you like.

P.S. Ich schreibe mal auf englisch weiter damit jeder mitlesen kann.

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
T
TWO Offline

Serious User
TWO  Offline

Serious User
T

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 Offline

Programmer
Lukas  Offline

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 Offline OP
Newbie
benni  Offline 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 !



Re: Newbie Vector Problem!!! [Re: benni] #163094
10/24/07 20:36
10/24/07 20:36
Joined: Oct 2007
Posts: 49
Hildesheim, Germany
benni Offline OP
Newbie
benni  Offline OP
Newbie

Joined: Oct 2007
Posts: 49
Hildesheim, Germany
P.S. Everybody will be rewarded with my superfast Bezier Spline Script (if interested)


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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