-
Notifications
You must be signed in to change notification settings - Fork 1
/
sand.h
160 lines (119 loc) · 4.4 KB
/
sand.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#pragma once
#ifndef SAND_
#define SAND_
#include "obstacle.h"
#include <iostream>
#include <unsupported/Eigen/MatrixFunctions>
#include <Eigen>
#include <algorithm>
typedef float coord[3];
#define DEFAULT_MASS 1;
#define DEFAULT_VOL 0.1;
#define MAXOBSTACLES 100;
class Sand {
public:
int xres, yres, zres;
int xyres;
float* mg, * fg;
Obstacle obstacles[100];
int n_obstacles = 0;
int* col_obst;
int* col_grid;
int n_collisions = 0;
float dt;
int h;
float* sigma;
float* rho;
float* v;
float h0, h1, h2, h3;
float phi;
int d = 3;
float lambda;
float mu;
int n_particle;
int n_grid;
float* w;
Eigen::Matrix<float, 3, 1>* xg, *xgb;
Eigen::Matrix<float, 3, 1>* gradw;
// particle related objects
float* mp, * Vp0, * ap, * apn, * qp, * qpn;
Eigen::Matrix<float, 3, 3>* Bp, * Bpn, * Fp, * Fpn, * FEp, * FEpn, * FPp, *FPpn,
*FEpt, *FPpt, *Cp, *Dp, *Fph, *FEph, *FPph, *gradv, *Zp;
Eigen::Matrix<float, 3, 1>* vp, * vpn, *xp, *xpn, *vpb;
Eigen::Matrix<float, 3, 1>* vg, * vgb, * vgt, *vgs;
Eigen::Matrix<float, 3, 1> g = Eigen::Matrix<float, 3, 1>(0, 0, -9.8);
Sand(int xRes, int yRes, int zRes, int nparticle, float h_, float dt_);
int transer_to_grid();
int explicit_grid_step();
int implicit_grid_step();
int transfer_to_particles();
int update_particle_state();
int plasticity_hardening();
int friction(Eigen::Matrix<float, 3, 1>* v, Eigen::Matrix<float, 3, 1>* gradv);
int grid_collisions(Eigen::Matrix<float, 3, 1>* v, Eigen::Matrix<float, 3, 1>* dv);
int project(const Eigen::Matrix<float, 3, 3>&Sigma, float a, Eigen::Matrix<float, 3, 3>& expH, float& delgam);
int energy_derivative(const Eigen::Matrix<float, 3, 3>& Sigma, Eigen::Matrix<float, 3, 3>& deriv);
int force_increment(Eigen::Matrix<float, 3, 3> * Fp, float b, Eigen::Matrix<float, 3, 1>* f);
int force_increment_vel(Eigen::Matrix<float, 3, 1>* v, Eigen::Matrix<float, 3, 1>* f);
void initialize();
int x2i(Eigen::Matrix<float, 3, 1> x);
void i2x(int i, Eigen::Matrix<float, 3, 1>& x);
void random_initial_positions();
float Nh(float x);
float dNh(float x);
void update_weight();
void get_B(Eigen::Matrix<float, 3, 3>* B);
void add_obstacle(Obstacle& obs);
//float* lambda;
//float* G;
//Float* dG;
//unsigned short xres;
//unsigned short yres;
//GzPixel* pixelbuffer; /* frame buffer array */
//char* framebuffer;
//GzCamera m_camera;
//short matlevel; /* top of stack - current xform */
//GzMatrix Ximage[MATLEVELS]; /* stack of xforms (Xsm) */
//GzMatrix Xnorm[MATLEVELS]; /* xforms for norms (Xim) */
//GzMatrix Xsp; /* NDC to screen (pers-to-screen) */
//GzColor flatcolor; /* color state for flat shaded triangles */
//int interp_mode;
//int numlights;
//GzLight lights[MAX_LIGHTS];
//GzLight ambientlight;
//GzColor Ka, Kd, Ks;
//float spec; /* specular power */
//GzTexture tex_fun; /* tex_fun(float u, float v, GzColor color) */
//// Constructors
//GzRender(int xRes, int yRes);
//~GzRender();
//// Function declaration
//// HW1: Display methods
//int GzDefault();
//int GzBeginRender();
//int GzPut(int i, int j, GzIntensity r, GzIntensity g, GzIntensity b, GzIntensity a, GzDepth z);
//int GzGet(int i, int j, GzIntensity* r, GzIntensity* g, GzIntensity* b, GzIntensity* a, GzDepth* z);
//int GzFlushDisplay2File(FILE* outfile);
//int GzFlushDisplay2FrameBuffer();
//// HW2: Render methods
//int GzPutAttribute(int numAttributes, GzToken* nameList, GzPointer* valueList);
//int GzPutTriangle(int numParts, GzToken* nameList, GzPointer* valueList);
//// HW3
//int GzPutCamera(GzCamera camera);
//int GzPushMatrix(GzMatrix matrix);
//int GzPopMatrix();
//// Extra methods: NOT part of API - just for general assistance */
//inline int ARRAY(int x, int y) { return (x + y * xres); } /* simplify fbuf indexing */
//inline short ctoi(float color) { return(short)((int)(color * ((1 << 12) - 1))); } /* convert float color to GzIntensity short */
//// Object Translation
//int GzRotXMat(float degree, GzMatrix mat);
//int GzRotYMat(float degree, GzMatrix mat);
//int GzRotZMat(float degree, GzMatrix mat);
//int GzTrxMat(GzCoord translate, GzMatrix mat);
//int GzScaleMat(GzCoord scale, GzMatrix mat);
//// hW6
//float Xoffset;
//float Yoffset;
//float weight;
};
#endif