-
Notifications
You must be signed in to change notification settings - Fork 0
/
vorton.h
78 lines (63 loc) · 2.65 KB
/
vorton.h
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
72
73
74
75
76
77
78
//
// vorton.h
// vtpartsim
//
// Created by Paul Francis Cunninghame Mathews on 25/09/14.
// Copyright (c) 2014 pfcm. All rights reserved.
//
#ifndef vtpartsim_vorton_h
#define vtpartsim_vorton_h
#include "particle.h"
#include <algorithm>
static const float ONE_OVER_FOUR_PI = 1.0/(4* 3.14159265359);
/** Vorton, a fancy particle */
class vorton : public particle
{
public:
// Gets the contribution of this vorton to something at otherPos
// adds result to otherVel
void get_velocity_contribution( vec3 &otherVel, const point3 &otherPos ) const
{
/*this is the stuff from gourlay
vec3 diff = otherPos - mPos;
// potentiall make this faster
float dist = diff.length()+ 0.0000001;
float oneoverdist = 1.0/dist;
float weight = (dist < mRadius)? oneoverdist / mRadius*mRadius
: oneoverdist / (dist*dist);
diff = diff * oneoverdist;
vec3 cross = crossproduct(mVorticity, diff)*weight;
otherVel += (ONE_OVER_FOUR_PI * (8.0f * mRadius * mRadius * mRadius)* (cross*weight))*0.1;
// end gourlay intel stuff
// begin some extra contribution so the particles follow the vortons
otherVel += diff.normalise() * - std::min(weight*0.1, 0.01);*/
// or we could ghetto it
// we want to add a contribution to otherVel based on rotating otherPos around
// mVorticity, with size of the velocity contribution based on both the length of
// mVorticity and inversely related to the distance between this vorton and
// this vorton
// let us get the difference in location between us and them
vec3 diff = otherPos-mPos;
// the distance is the length of this vector
float dist = diff.length()+0.0001;
vec3 ndiff = diff * (1.0/dist);
// the direction of the component we are adding to the velocity
// is going to be the cross product of the difference and the vorticity
vec3 cross = crossproduct(mVorticity.normalise(), ndiff);
float weight = (dist > mRadius)?(1.0/(dist*0.5 + dist*dist*1.5)) * 0.04 : 0.01;
weight *= mVorticity.length() * 0.2;
otherVel = otherVel + (cross*weight);
if (dist > 0.5) {
otherVel = otherVel - (ndiff*weight);//0.1);
otherVel = otherVel + mVel * weight;//* 0.8;
} else {
otherVel = otherVel + mVel * weight* 0.2;
}
}
float mRadius = 0.001; // radius of a vorton, used to avoid weirdness when too close
vec3 mVorticity;
point3 &position() {
return particle::mPos;
}
};
#endif