|
Re: declaring Vector
[Re: boyax]
#270919
06/10/09 14:28
06/10/09 14:28
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Ive had great difficulties with the vector over time too. To the best of my knowledge, which is far from perfect
Use version A when it is a local variable.
Use version B when it is a local or global POINTER, and is just going to point at other vectors. (uncommon)
Use version A when it is a global variable, but you dont care about its initial value. (dirty!)
Use version C when it is a global variable, and you want to set its initial value. Version C is VECTOR* temp = { x=0; y=0; z=0; }
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: declaring Vector
[Re: EvilSOB]
#270920
06/10/09 14:52
06/10/09 14:52
|
Joined: Aug 2000
Posts: 1,140 Baunatal, Germany
Tobias

Moderator
|

Moderator
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
|
In version a) you declare a vector. In version b) you declare not a vector, but an empty pointer. Using empty pointers in functions will CRASH. So, there is no sample code for b) unless you want to learn how to crash the engine.
Sample code for a:
function foo() { VECTOR v; vec_set(v,vector(1,2,3)); vec_add(v,v); ... }
and so on...
When you really want to use pointers, you must always let those pointers point to something... otherwise, CRASH!!
VECTOR* v; // empty pointer, points to nothing vec_set(v,vector(1,2,3)); // crash!
but
VECTOR* v = { x = 0; y = 0; z = 0; } // now v points to a real vector vec_set(v,vector(1,2,3)); // no crash!
Hope this helps..
|
|
|
|