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
0 registered members (), 18,561 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
Page 1 of 2 1 2
Why??? #163460
10/25/07 21:54
10/25/07 21:54
Joined: Oct 2007
Posts: 49
Hildesheim, Germany
benni Offline OP
Newbie
benni  Offline 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: benni] #163461
10/25/07 22:05
10/25/07 22:05
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
please post example code of your problem.

Re: Why??? [Re: ventilator] #163462
10/25/07 22:38
10/25/07 22:38
Joined: Oct 2007
Posts: 49
Hildesheim, Germany
benni Offline OP
Newbie
benni  Offline 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 Offline OP
Newbie
benni  Offline 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 Offline OP
Newbie
benni  Offline 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 Offline OP
Newbie
benni  Offline 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 Offline
Member
i_program_games  Offline
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 Offline OP
Newbie
benni  Offline 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: benni] #163468
10/26/07 10:13
10/26/07 10:13
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
Hello benni - your concept of copying vectors and not being able to scale negative values and so on is all nonsense, so the first thing you should do is throwing out all your copy_vectors.

Apart from that your code looks very wrong, 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. I think the problem is not vector math, the problem is some fundamental misunderstanding of functions and pointers.

function whatever(VECTOR* a, VECTOR* b, VECTOR* c)
{
VECTOR result; // intermediate results
vec_set(result,b);
vec_sub(result,c);
vec_set(a,result);
// result is returned in a
}

Hope you get the idea...

Re: Why??? [Re: Spirit] #163469
10/26/07 10:37
10/26/07 10:37
Joined: Oct 2007
Posts: 49
Hildesheim, Germany
benni Offline OP
Newbie
benni  Offline 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.

Page 1 of 2 1 2

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