-
Notifications
You must be signed in to change notification settings - Fork 0
/
ForceGenerators.h
89 lines (75 loc) · 2.87 KB
/
ForceGenerators.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
79
80
81
82
83
84
85
86
87
88
#pragma once
#include "SimulationObjects.h"
#include "Particle.h"
#include "Defines.h"
#include "debug.h"
#include "FSR.h"
void customForceDynamic(ForceObject& fo, const FixedPoint& timeDelta) {
Vector3D forceVector = *((Vector3D*)fo.m_analogForceData.m_dynamicForceVector);
fo.m_obj->m_force += forceVector;
}
void buildCustomForce(ForceObject *fo, Object* obj, Vector3D *vector) {
fo->m_obj = obj;
fo->m_generator = customForceDynamic;
fo->m_analogForceData.m_dynamicForceVector = (void*)vector;
}
void gravityForce(ForceObject& fo, const FixedPoint& timeDelta) {
if(fo.m_obj->m_invMass > 0) {
switch (fo.m_obj->m_objectType) {
case PARTICLE:
particleGravityForce(fo, timeDelta, fo.m_gravData.m_gravMult);
break;
default:
break;
}
}
}
void buildGravityForce(ForceObject *fo, Object* obj, FixedPoint gravMult = ONE) {
fo->m_obj = obj;
fo->m_generator = gravityForce;
fo->m_gravData.m_gravMult = gravMult;
}
void springForce(ForceObject& fo, const FixedPoint& timeDelta) {
if(fo.m_obj->m_invMass > 0) {
switch (fo.m_obj->m_objectType) {
case PARTICLE:
particleSpringForce(fo, timeDelta, fo.m_springData.m_endpoint, fo.m_springData.m_springConstant, fo.m_springData.m_restLength);
break;
default:
break;
}
}
}
void fixedSpringForce(ForceObject& fo, const FixedPoint& timeDelta) {
if(fo.m_obj->m_invMass > 0) {
Vector3D vector(fo.m_springData.m_fixedEndpoint.m_fixedEndpointX, fo.m_springData.m_fixedEndpoint.m_fixedEndpointY, fo.m_springData.m_fixedEndpoint.m_fixedEndpointZ);
switch (fo.m_obj->m_objectType) {
case PARTICLE:
particleSpringForce(fo, timeDelta, &vector, fo.m_springData.m_springConstant, fo.m_springData.m_restLength);
break;
default:
break;
}
}
}
void buildSpringForce(ForceObject *fo, Object* obj, Vector3D* endPoint, FixedPoint springLength, FixedPoint springConstant, bool isFixedPoint) {
debugln("BuildSpringForce", DEBUG_FORCE);
debugln(endPoint->toString(), DEBUG_FORCE);
fo->m_obj = obj;
if(isFixedPoint) {
debug("FixedPoint Spring", DEBUG_FORCE);
debugln(endPoint->toString(), DEBUG_FORCE);
fo->m_springData.m_fixedEndpoint.m_fixedEndpointX = endPoint->m_x;
fo->m_springData.m_fixedEndpoint.m_fixedEndpointY = endPoint->m_y;
fo->m_springData.m_fixedEndpoint.m_fixedEndpointZ = endPoint->m_z;
debugln(TO_STRING(fo->m_springData.m_fixedEndpoint.m_fixedEndpointX), DEBUG_FORCE);
debugln(TO_STRING(fo->m_springData.m_fixedEndpoint.m_fixedEndpointY), DEBUG_FORCE);
debugln(TO_STRING(fo->m_springData.m_fixedEndpoint.m_fixedEndpointZ), DEBUG_FORCE);
fo->m_generator = fixedSpringForce;
} else {
fo->m_springData.m_endpoint = (void*)endPoint;
fo->m_generator = springForce;
}
fo->m_springData.m_springConstant = springConstant;
fo->m_springData.m_restLength = springLength;
}