Vectors math programming...,
Members - Reputation: 180
Posted 18 August 2001 - 06:01 PM
Members - Reputation: 351
Posted 20 August 2001 - 12:45 AM
First I would recoomend structs over unions: you don''t need unions to implement vectors and I think you''re more likely to trip up with them.
The advantages of structures [for vectors] are:
Simpler code: e.g. only one line to add two vectors, not three.
Easier to work with and debug: because it''s easier to tell what you are dealing with. Without structs you use the same types for vectors and scalars and it can be difficult to tell them apart.
Quicker code: this depends on how they are implemented, but often you can take advantage of processor features such as a vector/SIMD unit to accelerate vector operations.
Members - Reputation: 546
Posted 20 August 2001 - 01:19 AM
This way, you can access the members of the vector with either:
It''s really just a convenience thing though. There''s no real need for it. Also, you can define an operator like this:
That way, you can do stuff like this:
Pretty nifty, eh?
War Worlds - A 3D Real-Time Strategy game in development.