API Documentation
Loading...
Searching...
No Matches
Particle.h
Go to the documentation of this file.
1/**--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: NDEVR
28File: NDEVRPCH
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
36#define SimpleParticle 1
37namespace NDEVR
38{
39 /* Some physics constants */
40 constexpr fltp04 damping_factor = 0.01f; // how much to damp the cloth simulation each frame
41#define MAX_INF 9999999999.0f
42#define MIN_INF -9999999999.0f
43
44/*
45Initially, we have to make modifications of particle positions for each constraint(constraintTimes = rigidness), However, to save computation time, we
46precomputed the total displacement of a particle for all constraintTimes.
47For singleMove1, which means one of the two particles is unmovable, then we move the other one only:
48if constraintTimes = 0: singleMove1 = 0
49if constraintTimes = 1: singleMove1 = 0.3, i.e., each time we move 0.3 (scale factor of the total distance) for a particle towards the other one
50if constraintTimes = 2: singleMove1 = (1-0.3)*0.3+0.3 = 0.51
51if constraintTimes = 3: singleMove1 = (1-0.51)*0.3+0.51 = 0.657
52...
53
54For doubleMove1, we move both of the two particles towards each other.
55if constraintTimes = 0: singleMove2 = 0
56if constraintTimes = 1: singleMove2 = 0.3, i.e., each time we move 0.3 (scale factor of the total distance) for the two particles towards each other
57if constraintTimes = 2: singleMove2 = (1-0.3*2)*0.3+0.3 = 0.42
58if constraintTimes = 3: singleMove2 = (1-0.42*2)*0.3+0.42 = 0.468
59...
60
61*/
62 const fltp04 singleMove1[15] = { 0, 0.3f, 0.51f, 0.657f, 0.7599f, 0.83193f, 0.88235f, 0.91765f, 0.94235f, 0.95965f, 0.97175f, 0.98023f, 0.98616f, 0.99031f, 0.99322f };
63 const fltp04 doubleMove1[15] = { 0, 0.3f, 0.42f, 0.468f, 0.4872f, 0.4949f, 0.498f, 0.4992f, 0.4997f, 0.4999f, 0.4999f, 0.5f, 0.5f, 0.5f, 0.5f };
64
65 /* The particle class represents a particle of mass that can move
66 * around in 3D space*/
67 class Particle : public Vertex<3, fltp04>
68 {
69 public:
71 : Vertex<3, fltp04>(pos)
72#ifndef SimpleParticle
73 , mass(1)
74 , acceleration(Vector<3, fltp04>(0, 0, 0))
75 , old_pos(pos)
76#else
77 , old_pos(pos[Z])
78#endif
79 , movable(true)
80
81 {}
82
84 : Vertex<3, fltp04>(0, 0, 0)
85#ifndef SimpleParticle
86 , mass(1)
87 , acceleration(Vector<3, fltp04>(0, 0, 0))
88#endif
89 //, accumulated_normal(Vector<3, fltp04>(0, 0, 0))
90 , old_pos(0.0f)
91 , movable(true)
92 {}
93
94
95 bool isMovable() const
96 {
97 return movable;
98 }
99
100
101
102 /* This is one of the important methods, where the time is
103 * progressed a single step size (TIME_STEPSIZE) The method is
104 * called by Cloth.time_step()*/
105 inline void timeStep(fltp04 time, const Vector<3, fltp04>& acceleration)
106 {
107 constexpr fltp04 local_damping = (1.0f - damping_factor);
108#ifdef SimpleParticle
109 fltp04 temp = (*this)[Z];
110 (*this)[Z] += ((*this)[Z] - old_pos) * local_damping + acceleration[Z] * time;
111 old_pos = temp;
112#else
113 Vector<3, fltp04> temp = *this;
114 (*this) += ((*this) - old_pos) * (1.0f - DAMPING) + acceleration * time;
115 old_pos = temp;
116#endif
117 }
118
119#ifndef SimpleParticle
120 void resetAcceleration()
121 {
122 acceleration = Vector<3, fltp04>(0, 0, 0);
123 }
124 void addForce(const Vector<3, fltp04>& f)
125 {
126 acceleration += f / mass;
127 }
128#endif
130 {
131 movable = false;
132 }
133 // These two members are used in the process of edge smoothing after
134 // the cloth simulation step.
135 // the position of the particle in the previous time step, used as
136 // part of the verlet numerical integration scheme
137
138#ifndef SimpleParticle
139 Vector<3, fltp04> acceleration;
141 fltp04 time_step2;
142 fltp04 mass;
143#else
145#endif
146 //Vector<3, fltp04> accumulated_normal; // an accumulated normal (i.e. non normalized), used for OpenGL soft shading
147
148 bool movable; // can the particle move or not ? used to pin parts of the cloth
149 };
150 template<> inline const Particle Constant<Particle>::NaN = Particle();
151}
#define SimpleParticle
Definition Particle.h:36
Definition Particle.h:68
bool isMovable() const
Definition Particle.h:95
void makeUnmovable()
Definition Particle.h:129
void timeStep(fltp04 time, const Vector< 3, fltp04 > &acceleration)
Definition Particle.h:105
Particle(const Vector< 3, fltp04 > &pos)
Definition Particle.h:70
bool movable
Definition Particle.h:148
fltp04 old_pos
Definition Particle.h:144
Particle()
Definition Particle.h:83
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
A vertex.
Definition Vertex.hpp:54
Definition ACIColor.h:37
const fltp04 singleMove1[15]
Definition Particle.h:62
float fltp04
Defines an alias representing a 4 byte floating-point number.
Definition BaseValues.hpp:157
constexpr fltp04 damping_factor
Definition Particle.h:40
const fltp04 doubleMove1[15]
Definition Particle.h:63
@ Z
Definition BaseValues.hpp:204
Definition BaseValues.hpp:272