Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: So Jul 20, 2025 17:54

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 11 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: Particles + 3D Maths
BeitragVerfasst: So Aug 01, 2004 14:42 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Currently the particle system i use works in a basic way, with Z and Y speeds, basicaly you can only have "effects" that work in the up and down directions. I.e fountains , fire. Thus its imposible to have a pipe with ahole in it and fire coming out of it at an angle and acting correctly.

So id like to convert the particle system so it uses Angles, Velocity, etc, but there is one thing i can't work out. for some things like fire the starting point varies around the center point of the particle system, but i don't know how to work out a particle start point when given a direction and particle start point.

Pic attached shows what i mean by particle start point, they spring up randomly around the center depending on the settings, this is needed for certain effects like fire.

Code:
  1. particle[i].xpos := ParticleScript[PS].PosX;
  2.      particle[i].ypos := ParticleScript[PS].PosY;
  3.      particle[i].zpos := ParticleScript[PS].PosZ;
  4.  
  5.      if ParticleScript[PS].PosRandomX > 0 then
  6.      particle[i].xpos := particle[i].xpos + (random(trunc(ParticleScript[PS].PosRandomX))/2) - (random(trunc(ParticleScript[PS].PosRandomX))/2);
  7.  
  8.      if ParticleScript[PS].PosRandomY > 0 then
  9.      particle[i].ypos := particle[i].ypos + (random(trunc(ParticleScript[PS].PosRandomY))/2) - (random(trunc(ParticleScript[PS].PosRandomY))/2);
  10.  
  11.      if ParticleScript[PS].PosRandomZ > 0 then
  12.      particle[i].zpos := particle[i].zpos + (random(trunc(ParticleScript[PS].PosRandomZ))/2) - (random(trunc(ParticleScript[PS].PosRandomZ))/2);
  13.  


Basicaly say you have the particle system at (0,0,0) and the direction of it is (1,0,0) my question is how to work out random points around the center point taking its direction into account.


Dateianhänge:
particles.jpg [146.93 KiB]
118-mal heruntergeladen

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu
Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Aug 01, 2004 16:33 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
I suggest you to read the Physics for Game Developers Book from O'Reilly. :D I am reading it now and it is great!!!

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Aug 01, 2004 17:12 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
I don't have money to buy books (unemployed). I Failed higher maths(which is ironic since im programming in OpenGl.... where u need to have at least basic knowlage of 3d maths to do stuff) which delt with Vectors, etc, basicaly because i was too busy at home programming/scripting(PHP) to b bothered to do revision. Iv read articles on the net on various things, it all seems like a forren language, goes in one ear n out the other. I learn by code, works better for me than stairing at a book trying to work out what the maths means.

Think iv thought of a solution. Basicaly all i think i need to do is this:

Code:
  1.  
  2. Procedure WorkOutSpawnPoints(var ParticleSystem : TParticleSystem);
  3. begin
  4.  
  5. ParticleSystem.SS := GetPositionInfrontFromAngles(10,ParticleSystem.Position.Y,ParticleSystem.Position.X-90);
  6. ParticleSystem.SE := GetPositionInfrontFromAngles(10,ParticleSystem.Position.Y,ParticleSystem.Position.X+90);
  7.  
  8. end;
  9.  


GetPositionInfrontFromAngles works out a position based on the angles. The 10 would b the distance u want from 0 (+-). The + and - 90 change it from being the direction ur particles would b coming from to the 2 sides at right angles. (See Fig 1..... yes its rearly graphical.... boy the skills... anyway, yellow line being the direction the particle system faces, the other 2 colours would b the lines from 0 to ParticleSystem.SS and ParticleSystem.SE)

Now the simple part. Working out a random position from a 3d line.

Code:
  1.  
  2. Function GetPointOnLineUsingK(P1,P2 : TVector3f; K : Extended) : TVector3f;
  3. begin
  4. // Equation Of 3d Line: P = P1 + k(P2-P1)
  5. Result.X := P1.X + k*(P2.X-P1.X);
  6. Result.Y := P1.Y + k*(P2.Y-P1.Y);
  7. Result.Z := P1.Z + k*(P2.Z-P1.Z);
  8. end;
  9.  


Code:
  1.  
  2. Function GetRandomParticleStartPos(SS,SE : TVector3f) : TVector3f;
  3. var
  4. Distance,k : Extended;
  5. begin
  6.  
  7. Distance := abs(VectorDistance(SS,SE));
  8.  
  9. k := Random(Trunc(Distance*10)+1);
  10. if k > 0 then
  11. k := k/(Trunc(Distance*10)/10);
  12.  
  13. Result := GetPointOnLineUsingK(SS,SE,k);
  14.  
  15. end;
  16.  


Basicaly k should become a value between 0 and 1, which determins which part of the line is picked.

This should (theory wise it seems to b sound)mean particles can start around the center with the direction kept in mind. If i can get it to work right ill post all code.


Dateianhänge:
Dateikommentar: Maybe i could enter it into an art competition....yeh..
highlygraphicaldrawing.GIF
highlygraphicaldrawing.GIF [ 6.85 KiB | 6362-mal betrachtet ]

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu
Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Aug 01, 2004 21:03 
Offline
Guitar Hero
Benutzeravatar

Registriert: Do Sep 25, 2003 15:56
Beiträge: 7810
Wohnort: Sachsen - ERZ / C
Programmiersprache: Java (, Pascal)
You have a center-point and a direction...So you have a vector.
Your particel-start-point should lay in a plane.
So take the vektor as normale of the plane. Now, you can calculate the plane equation.

Hope it helps you. (hope I didn't write a to bad english)

_________________
Blog: kevin-fleischer.de und fbaingermany.com


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Aug 01, 2004 22:39 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Your english is fine, i just didn't understand a word about planes. My theory technicaly worked, i just forgot about one part, it only picks a random point along a line, without taking into consideration the other bit. err

Say the particle system points up. Particles should spring up around the center from say -10,0,-10 to 10,0,10 , currently the system would only go along the X axis, not taking into account the Z axis. I could get a random point that would take "Z" into account but i don't know how ill turn 2 points into 1.

EDIT: my theory was wrong.... no clue what to do.....

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Aug 02, 2004 01:48 
Offline
Guitar Hero
Benutzeravatar

Registriert: Do Sep 25, 2003 15:56
Beiträge: 7810
Wohnort: Sachsen - ERZ / C
Programmiersprache: Java (, Pascal)
Hmm... I try to discribe it...

You have the normal of the plane. Now you wont the plane it self.
The plane consists of a point P0 and two vectors v1 (P1-P0) and v2 (P2-p0).
The crossproduct <v1,v2> is your normal.

You said, that you have the center-point. This point lays in the plane. So you have P0.

Now you take an equation system wich consists of v1,v2 and n (your normal)

Nx = V1yV2z - V1zV2y
Ny = V1zV2x - V1xV2z
Nz = V1xV2y - V1yV2x

When you have a V1 and V2 that works, you can calculate P1 and P2.

So... Now you have your plane.

If you whant to calculate the distance between a point in the Plane and the centerpoint you can use the pythagoras formula.
(d = sqrt(x^2+y^2+z^2) where x,y,z = diference of the x-,y-,z-Value of the 2 Points)

May this help you.

_________________
Blog: kevin-fleischer.de und fbaingermany.com


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Aug 02, 2004 14:46 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
If i don't know V1,V2 how can the equation b solved, without going through every number in existance.

From what i can make out (never good with math equations) i have N and P0, but to do anything i need P1 or P2 or V1 or V2.

Basicaly i don't get what im ment to do.

Zitat:
If you whant to calculate the distance between a point in the Plane and the centerpoint you can use the pythagoras formula.
(d = sqrt(x^2+y^2+z^2) where x,y,z = diference of the x-,y-,z-Value of the 2 Points)


How can i get a point on the plane? Without trying every number thats posible?

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Aug 02, 2004 19:13 
Offline
Guitar Hero
Benutzeravatar

Registriert: Do Sep 25, 2003 15:56
Beiträge: 7810
Wohnort: Sachsen - ERZ / C
Programmiersprache: Java (, Pascal)
With the plane equation you can choose 2 coordinates and the third is given over the equation.

What points you choose is absolutely unimportant (ok...they have to lay in the plane ;) ), as long as they don't lay in a line.

When you use this formulas with P'n'P its no problem, but using them in a program could realy be tricky.

Maybe Lars, LosseyX or SoS could help you finding a way.

Sometimes it seems, that they solve every problem...

_________________
Blog: kevin-fleischer.de und fbaingermany.com


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Aug 02, 2004 20:48 
Offline
DGL Member
Benutzeravatar

Registriert: Di Nov 26, 2002 22:12
Beiträge: 259
Wohnort: Dresden
I’m not sure if I understood your problem. But I’m sure that one way to solve your problem is to rotate a point around the originpoint of your system.
You know how your system looks like.
e.g. the particles of a flame will move upwards. So your directionvector system points into the Y-Direction. Your particlespawnpoints will lie on a line which is orthogonal to your directionvector.

Now you want to use another directionvector. For example (1,0,0).

You’ll calculate a vector pointing from your systemoriginpoint to the spawnpoint of your Particle (like your directionvector would point upwards). Then you’ll send this point through a matrix, you created.
Have a look into the geometry.pas from Mike Lischke to get out, how you can create a rotationmatrix around 3 Axis.

Then you have to add the resultvector to your systemoriginpoint and you get your particlespawnpoint. For the individually velocityvector of your particle you can do it the same way.

Maybe you should have a look into our tutorialsection under „Mathematisches“:
-„Objekt gedreht und dennoch nach vorne bewegt“
-„Objekt immer um eigene Achse drehen“

The examples may be helpful.

I don’t know exactly, what you want to do, but I think you could solve this problem in another way.
The benefit of this way is, that you have to calculate your position and velocityvector once and use this until your particle “dies”.
But mostly if you use efficient particlesystems you also need billboaring. Then you have to rotate your whole System, means every particle itself, every frame. So if you need billboarding, you can take the sum of both angles for your rotation.
That is the way I used in Asteroids and which also works very wellin my Engine (if I can call it so ;))

Both ways need the following operation, which will calculate the angle between 2 Vectors (your Standarddirectionvector (e.g. (0,1,0) and your new directionvector (e.g. (1,0,0) )
Code:
  1.  
  2. //calculates the smallest angle between 2 vectors
  3. function VectorAngle(const Vector1, Vector2:TVector3f):single;
  4. begin
  5.   Result:=VectorMagnitude(Vector1) * VectorMagnitude(Vector2);
  6.   //zerodivision
  7.   if Result=0 then
  8.     exit;
  9.  
  10.   Result:=ArcCos(VectorDotProduct(Vector1, Vector2) / Result);
  11. end;



I hope I hit your problem.

_________________
Nichts auf der Welt ist so gerecht verteilt wie der Verstand. Denn jederman ist überzeugt, dass er genug davon habe.
Rene Descartes, frz. Mathematiker u. Philosoph, 1596-1650


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Aug 02, 2004 22:59 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Matrix idea might work. (iv used matrix's b4 for Tiberian Sun's/Red Alert 2's HVA's, HVA stands for homogeneous voxel animation or something like it, basicaly the frames are homogeneous matrix's)

EDIT: Matrix worked :) thx for the idea.

Code:
  1.  
  2. Function GetRandomParticleStartPos(Radius,XAngle,YAngle : Extended) : TVector3f;
  3. Const
  4. Multi = 1000; // Higher this is the more accurate the positions can be
  5. var
  6. Pos : TVector3f;
  7. Matrix : TMatrix;
  8. X,Y : Integer;
  9. begin
  10.  
  11. Pos.X := (Random(Trunc(Radius*Multi))/Multi)-(Random(Trunc(Radius*Multi))/Multi);
  12. Pos.Z := (Random(Trunc(Radius*Multi))/Multi)-(Random(Trunc(Radius*Multi))/Multi);
  13. Pos.Y := 1;
  14.  
  15. For x := 0 to 3 do
  16. For y := 0 to 3 do
  17. Matrix[x,y] := 0;
  18.  
  19. Matrix[0,0] := 1;
  20. Matrix[1,1] := 1;
  21. Matrix[2,2] := 1;
  22. Matrix[3,3] := 1;
  23.  
  24. //Matrix := Turn(Matrix,XAngle);
  25. //Matrix := Pitch(Matrix,XAngle);
  26. //Matrix := Roll(Matrix,DegToRad(YAngle));
  27. Matrix := Pitch(Matrix,DegToRad(YAngle+90));
  28. Matrix := Turn(Matrix,DegToRad(XAngle));
  29.  
  30. Result.X := Pos.X * Matrix[0,0] + Pos.Y * Matrix[0,1] + Pos.Z * Matrix[0,2] + Matrix[0,3];
  31. Result.Y := Pos.X * Matrix[1,0] + Pos.Y * Matrix[1,1] + Pos.Z * Matrix[1,2] + Matrix[1,3];
  32. Result.Z := Pos.X * Matrix[2,0] + Pos.Y * Matrix[2,1] + Pos.Z * Matrix[2,2] + Matrix[2,3];
  33.  
  34. end;
  35.  


Ill post the full code for the unit once iv finished it + made some particle scripts.

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Di Aug 03, 2004 21:27 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Iv found that i can't get the new system to do stuff the old system could do, but the new system can do stuff i wanted it to do. You could have water coming out of a pipe, etc.

Source Attached.


Dateianhänge:
ParticleTest2.zip [135.73 KiB]
351-mal heruntergeladen

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu
Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 11 Beiträge ] 
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 2 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.012s | 17 Queries | GZIP : On ]