-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparticle.cpp
71 lines (55 loc) · 2.36 KB
/
particle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <math.h>
#include <iostream>
#include "mathLib3D.h"
#include "particle.h"
#include <stdio.h> /* printf, scanf, puts, NULL */
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
#include <vector>
using namespace std;
Particle::Particle(){};//default constructor, not used
Particle::Particle(State state,bool setAntiGrav,bool setRubber){
antiGrav=false;rubber=false;
initState=state;
mPos=Point3D(0,0,250);
mOrig=Point3D(mPos.mX,mPos.mY,mPos.mZ);
mVel=Vec3D((rand()/float(RAND_MAX))*1 -.5,(rand()/float(RAND_MAX))*3 +2,(rand()/float(RAND_MAX))*1 -.5);
mRot=Point3D(float(RAND_MAX)*360,float(RAND_MAX)*360,float(RAND_MAX)*360);
ageMax=rand()%300 + 70; //age is 1s to 5s
cDull=7;
gravity= 0.14;
cameraInThisParticle=false;
//position is within 1000x1000 window, direction is stationary
mColor[0]=(rand()/float(RAND_MAX));mColor[1]=rand()/float(RAND_MAX);mColor[2]=rand()/float(RAND_MAX); //color's rgb streams, each r g and b being between 0-255 randomized
mSize = rand()%100; if (mSize>=99) mSize = 5; else if (mSize>=95) mSize = 4; else if (mSize>3) mSize=rand()%3;//size 0-4
mSpeed = (rand()/float(RAND_MAX))*1+1; //speed 1-5
}
void Particle::update(Point3D mousePos){
//cout<<mVel.mY*mSpeed<<"\n";
if (initState!=PAUSED){
age++;
mPos.plus(mVel.mX*mSpeed,mVel.mY*mSpeed,mVel.mZ*mSpeed);
if (mPos.mZ<=-500 || mPos.mZ>=500) {mVel.mZ=-mVel.mZ;}
if (mPos.mX<=-500 || mPos.mX>=500) {mVel.mX=-mVel.mX;}//when hitting borders of animation, bounce off
if (mPos.mY<0 || mPos.mY>=500) {
mVel.mY=-mVel.mY;
if (mPos.mY<0){
mPos.mY=0;
} else if (mPos.mY>500){
mPos.mY=0;
}
}
if (mVel.mY>gHeight/4)mVel.mY=gHeight/4;
else if (mVel.mY<-gHeight/4)mVel.mY=-gHeight/4;
if (abs(mPos.mY)+abs(mPos.mX)+abs(mPos.mZ)>10000) {mPos.multiply(0,0,0);}
//if moving so fast that jumping outside of screen borders, remake in middle of platform
if (!antiGrav) mVel.mY-=gravity; //if antigrav, gravity doesnt affect
//cout<<"\nmRotY: "<<mRot.mY;
}
}
/*float Particle::forceFunction(float dist){
return ((dist+1));
}*/
void Particle::slowDown(){
mSpeed*=gravity;
}