SceneNode(GLfloat x = 0, GLfloat y = 0, GLfloat z = 0, GLfloat velx = 0, GLfloat vely = 0, GLfloat velz = 0, GLfloat accx = 0, GLfloat accy = 0, GLfloat accz = 0) { newX = 0; newY = 0; newZ = 0; this->x[POS] = x; this->x[VEL] = velx; this->x[ACC] = accx; this->y[POS] = y; this->y[VEL] = vely; this->y[ACC] = accy; this->z[POS] = z; this->z[VEL] = velz; this->z[ACC] = accz; transform.setIdentity(); normTransform.setIdentity(); alive = true; }
virtual void update(unsigned long long time) { transform.translate(-newX, -newY, -newZ); x[VEL] += x[ACC]; y[VEL] += y[ACC]; z[VEL] += z[ACC]; x[POS] += x[VEL]; y[POS] += y[VEL]; z[POS] += z[VEL]; if(z[POS] < 0) z[POS] = 0; newX = x[POS]; newY = y[POS]; newZ = z[POS]; transform.translate(newX, newY, newZ); for(i = children.begin(); i != children.end(); i++) (*i)->update(time); children.remove_if(is_dead); }
SceneNode() { transform.setIdentity(); UNIFORM_mvpMatrix.setIdentity(); }
CubeNode(GLfloat size, int color) { GLuint colors[6]; if(color == 0) { for(int i = 0; i < 6; i++) { colors[i] = (rand() % 0x100000000) | 0xFF000000; } } else { for(int i = 0; i < 6; i++) { colors[i] = color; } } static const GLfloat permutation[][4][3] = { { {-1,1,1},{-1,-1,1},{1,-1,1},{1,1,1} }, { {1,1,-1},{1,-1,-1},{-1,-1,-1},{-1,1,-1} }, { {1,1,1},{1,-1,1},{1,-1,-1},{1,1,-1} }, { {-1,1,-1},{-1,-1,-1},{-1,-1,1},{-1,1,1} }, { {-1,1,-1},{-1,1,1},{1,1,1},{1,1,-1} }, { {1,-1,-1},{1,-1,1},{-1,-1,1},{-1,-1,-1} } }; static const GLfloat norms[][3] = { {0, 0, 1}, {0, 0, -1}, {1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0} }; int index = 0; size /= 2; for ( size_t i = 0; i < 6; ++i ) { vtx[index].x = size * permutation[i][0][0]; vtx[index].y = size * permutation[i][0][1]; vtx[index].z = size * permutation[i][0][2]; vtx[index].color = colors[i]; vtx[index].nx = norms[i][0]; vtx[index].ny = norms[i][1]; vtx[index].nz = norms[i][2]; ++index; vtx[index].x = size * permutation[i][1][0]; vtx[index].y = size * permutation[i][1][1]; vtx[index].z = size * permutation[i][1][2]; vtx[index].color = colors[i]; vtx[index].nx = norms[i][0]; vtx[index].ny = norms[i][1]; vtx[index].nz = norms[i][2]; ++index; vtx[index].x = size * permutation[i][3][0]; vtx[index].y = size * permutation[i][3][1]; vtx[index].z = size * permutation[i][3][2]; vtx[index].color = colors[i]; vtx[index].nx = norms[i][0]; vtx[index].ny = norms[i][1]; vtx[index].nz = norms[i][2]; ++index; vtx[index].x = size * permutation[i][3][0]; vtx[index].y = size * permutation[i][3][1]; vtx[index].z = size * permutation[i][3][2]; vtx[index].color = colors[i]; vtx[index].nx = norms[i][0]; vtx[index].ny = norms[i][1]; vtx[index].nz = norms[i][2]; ++index; vtx[index].x = size * permutation[i][1][0]; vtx[index].y = size * permutation[i][1][1]; vtx[index].z = size * permutation[i][1][2]; vtx[index].color = colors[i]; vtx[index].nx = norms[i][0]; vtx[index].ny = norms[i][1]; vtx[index].nz = norms[i][2]; ++index; vtx[index].x = size * permutation[i][2][0]; vtx[index].y = size * permutation[i][2][1]; vtx[index].z = size * permutation[i][2][2]; vtx[index].color = colors[i]; vtx[index].nx = norms[i][0]; vtx[index].ny = norms[i][1]; vtx[index].nz = norms[i][2]; ++index; } rot.setRotation(rand(), rand(), rand(), 0.005); }