I've decided to write a "particle" class, as a learning project and for fun, to be able to create simple "rule driven" particle collision "simulators" to try out what happens with different collision rules and such.
The only thing is..I got stuck at the starting line.
The matter is simple: Should my "particles" have a vector describing both speed and direction, or is it wiser to go with a direction and velocity approach? I'm talking purely 2D here, and collision detection and deflection calculation seems to be the primary tasks. Although, that's some math I will have to learn when I write the actual application.
What do you think is the best approach? I.e what makes later calculations, in the actual application, easier?
Vector or dir+vel?
Started by Walle, Jan 06 2010 08:13 AM
19 replies to this topic
#1
Posted 06 January 2010 - 08:13 AM
________________________________________________
"I'm not young enough to know everything." - Oscar Wilde
"I'm not young enough to know everything." - Oscar Wilde
|
|
|
#2
Posted 06 January 2010 - 08:18 AM
direction is already a vector with length 1. velocity = direction * speed.
I think a simple velocity vector would be simpler.
I think a simple velocity vector would be simpler.
#3
Posted 06 January 2010 - 08:53 AM
Oh, I was thinking more like having a variable describing direction in the form of a 360-degree direction, and a another one describing speed. I think I'm confusing everything by using the incorrect terms.
But maybe a velocity vector is a good thing. I guess I have to define the type myself? Or is there any built-in 2-d velocity vector format in any of the "standard" includes?
But maybe a velocity vector is a good thing. I guess I have to define the type myself? Or is there any built-in 2-d velocity vector format in any of the "standard" includes?
________________________________________________
"I'm not young enough to know everything." - Oscar Wilde
"I'm not young enough to know everything." - Oscar Wilde
#4
Posted 06 January 2010 - 09:19 AM
It's best to build them for yourself, thats where the learning starts ;)
#5
Posted 06 January 2010 - 09:24 AM
True. I found out that there is a vector-class in STL, but it seemed overly complicated for my needs :) I guess in theory a simple int[1] would do.
Maybe even better:
Maybe even better:
typedef struct{
int x;
int y;
} vector;
Edited by Walle, 06 January 2010 - 09:36 AM.
Added some code
________________________________________________
"I'm not young enough to know everything." - Oscar Wilde
"I'm not young enough to know everything." - Oscar Wilde
#6
Posted 06 January 2010 - 12:43 PM
The vector class has nothing to do with the type of vectors you're thinking of.
#7
Posted 06 January 2010 - 01:30 PM
I think I figured that out after looking at it a bit more. It seems to have to do with linked lists, am I correct?
Anyway, my struct should work for what I'm doing (even though I'm putting it aside for a few days), right?
Anyway, my struct should work for what I'm doing (even though I'm putting it aside for a few days), right?
________________________________________________
"I'm not young enough to know everything." - Oscar Wilde
"I'm not young enough to know everything." - Oscar Wilde
#8
Posted 06 January 2010 - 04:59 PM
A linked list would probably work well to store your particles, yes.
#9
Posted 06 January 2010 - 05:15 PM
WingedPanther said:
A linked list would probably work well to store your particles, yes.
Array can do the trick to ;) and it's a easier way out than a linked list.
#10
Posted 06 January 2010 - 05:21 PM
For a particle system where they may be getting created and destroyed frequently, an array would NOT be a good idea.
#11
Posted 07 January 2010 - 12:00 AM
create a struct or class with x, y, a speed variable and a bool for if its alive or dead. then create an stl vector or list and fill it with your structure.
Iterate over the container that you choose updating the position, speed and life of the particle.
The way that a particle system works you are constantly adding and removing particles so an array won't work as WingedPanther said.
Iterate over the container that you choose updating the position, speed and life of the particle.
The way that a particle system works you are constantly adding and removing particles so an array won't work as WingedPanther said.
#12
Posted 07 January 2010 - 03:46 AM
i think each particle wont need to hold a vector of speed and distance, it would only be variable for speed and a variable for distance, since a class called Particle refers to a single particle and if your application will have many "Particles" then your main program will hold a vector of "Particle class" with each element in the vector refers to a single particle.


Sign In
Create Account


Back to top









