NDEVR
API Documentation
Particle.h
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
33#include "Base/Headers/Vertex.hpp"
34#include "Base/Headers/VectorFunctions.hpp"
35#include "Base/Headers/Buffer.hpp"
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 };
68 class Particle : public Vertex<3, fltp04>
69 {
70 public:
71 Particle(const Vector<3, fltp04>& pos)
72 : Vertex<3, fltp04>(pos)
73#ifndef SimpleParticle
74 , mass(1)
75 , acceleration(Vector<3, fltp04>(0, 0, 0))
76 , old_pos(pos)
77#else
78 , old_pos(pos[Z])
79#endif
80 , movable(true)
81
82 {}
83
84 Particle()
85 : Vertex<3, fltp04>(0, 0, 0)
86#ifndef SimpleParticle
87 , mass(1)
88 , acceleration(Vector<3, fltp04>(0, 0, 0))
89#endif
90 //, accumulated_normal(Vector<3, fltp04>(0, 0, 0))
91 , old_pos(0.0f)
92 , movable(true)
93 {}
94
95
96 bool isMovable() const
97 {
98 return movable;
99 }
100
101
102
103 /* This is one of the important methods, where the time is
104 * progressed a single step size (TIME_STEPSIZE) The method is
105 * called by Cloth.time_step()*/
106 inline void timeStep(fltp04 time, const Vector<3, fltp04>& acceleration)
107 {
108 constexpr fltp04 local_damping = (1.0f - damping_factor);
109#ifdef SimpleParticle
110 fltp04 temp = (*this)[Z];
111 (*this)[Z] += ((*this)[Z] - old_pos) * local_damping + acceleration[Z] * time;
112 old_pos = temp;
113#else
114 Vector<3, fltp04> temp = *this;
115 (*this) += ((*this) - old_pos) * (1.0f - DAMPING) + acceleration * time;
116 old_pos = temp;
117#endif
118 }
119
120#ifndef SimpleParticle
121 void resetAcceleration()
122 {
123 acceleration = Vector<3, fltp04>(0, 0, 0);
124 }
125 void addForce(const Vector<3, fltp04>& f)
126 {
127 acceleration += f / mass;
128 }
129#endif
130 void makeUnmovable()
131 {
132 movable = false;
133 }
134 // These two members are used in the process of edge smoothing after
135 // the cloth simulation step.
136 // the position of the particle in the previous time step, used as
137 // part of the verlet numerical integration scheme
138
139#ifndef SimpleParticle
140 Vector<3, fltp04> acceleration;
141 Vector<3, fltp04> old_pos;
142 fltp04 time_step2;
143 fltp04 mass;
144#else
145 fltp04 old_pos;
146#endif
147 //Vector<3, fltp04> accumulated_normal; // an accumulated normal (i.e. non normalized), used for OpenGL soft shading
148
149 bool movable; // can the particle move or not ? used to pin parts of the cloth
150 };
151 template<> inline const Particle Constant<Particle>::Invalid = Particle();
152}
Used with CSF Cloth, The particle class represents a particle of mass that can move around in 3D spac...
Definition Particle.h:69
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...