- Timestamp:
- Aug 10, 2017, 1:46:16 AM (7 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 9d22ee9
- Parents:
- 4046b51
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pong.cpp
r4046b51 r237ec28 87 87 // glFrontFace(GL_CW); 88 88 89 unsigned int numBallPoints = 3; 90 91 GLfloat* points = createCirclePoints(numBallPoints, 0.0f, 0.0f, 0.2f); 89 unsigned int numBallPoints = 36; 90 91 GLfloat ballRadius = 0.2f; 92 GLfloat paddleThickness = 0.1f; 93 94 GLfloat* points = createCirclePoints(numBallPoints, 0.0f, 0.0f, ballRadius); 92 95 GLfloat* colors = createCircleColors(numBallPoints); 93 96 … … 117 120 }; 118 121 119 GLuint ball_points_vbo = createDataBuffer(numBallPoints* 3*sizeof(GLfloat), points);120 GLuint ball_colors_vbo = createDataBuffer(numBallPoints* 3*sizeof(GLfloat), colors);122 GLuint ball_points_vbo = createDataBuffer(numBallPoints*9*sizeof(GLfloat), points); 123 GLuint ball_colors_vbo = createDataBuffer(numBallPoints*9*sizeof(GLfloat), colors); 121 124 GLuint ball_vao = createArrayBuffer(ball_points_vbo, ball_colors_vbo); 122 125 … … 147 150 previous_seconds = current_seconds; 148 151 149 if ( fabs(last_position) > 1.0f) {152 if (last_position > 1.0f-ballRadius) { 150 153 speed = -speed; 151 154 } 155 156 if (last_position < -1.0f+ballRadius+paddleThickness && 157 fabs(last_paddle_pos) < 0.15f) { 158 speed = -speed; 159 } 160 161 // if the ball hits the paddle on a corner, I should make it bounce 162 // off at an angle 152 163 153 164 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); … … 163 174 glDrawArrays(GL_TRIANGLES, 0, sizeof(points_paddle)/sizeof(GLfloat)/3); 164 175 165 // model[12] = last_position + speed*elapsed_seconds; 166 model[12] = 0.0f; 176 model[12] = last_position + speed*elapsed_seconds; 167 177 last_position = model[12]; 168 178 model[13] = 0.0f; … … 173 183 glEnableVertexAttribArray(1); 174 184 175 glDrawArrays(GL_TRIANGLES, 0, numBallPoints );185 glDrawArrays(GL_TRIANGLES, 0, numBallPoints*3); 176 186 177 187 glfwPollEvents(); … … 250 260 251 261 GLfloat* createCirclePoints(unsigned int smoothness, GLfloat centerX, GLfloat centerY, GLfloat radius) { 252 GLfloat* points = new GLfloat[smoothness*3]; 253 254 points[0] = 0.0f; 255 points[1] = 0.5f; 256 points[2] = 0.5f; 257 points[3] = -0.5f; 258 points[4] = -0.5f; 259 points[5] = 0.5f; 260 points[6] = 0.5f; 261 points[7] = -0.5f; 262 points[8] = 0.5f; 263 264 cout << "Sphere center: (" << centerX << ", " << centerY << ")" << endl; 265 266 smoothness *= 2; 262 GLfloat* points = new GLfloat[smoothness*9]; 263 264 GLfloat curX, curY, nextX, nextY; 265 curX = centerX; 266 curY = centerY+radius; 267 267 268 for (unsigned int i=0; i<smoothness; i++) { 268 double radians = PI/2 + 2*PI * i/smoothness; 269 cout << radians << endl;; 270 GLfloat x = centerX + cos(radians)*radius; 271 GLfloat y = centerY + sin(radians)*radius; 272 cout << "point " << i << ": (" << x << ", " << y << ")" << endl; 269 double radians = PI/2 + 2*PI * (i+1)/smoothness; 270 nextX = centerX + cos(radians)*radius; 271 nextY = centerY + sin(radians)*radius; 272 273 points[i*9] = curX; 274 points[i*9+1] = curY; 275 points[i*9+2] = 0.5f; 276 points[i*9+3] = nextX; 277 points[i*9+4] = nextY; 278 points[i*9+5] = 0.5f; 279 points[i*9+6] = centerX; 280 points[i*9+7] = centerY; 281 points[i*9+8] = 0.5f; 282 283 curX = nextX; 284 curY = nextY; 273 285 } 274 286 … … 277 289 278 290 GLfloat* createCircleColors(unsigned int smoothness) { 279 GLfloat* colors = new GLfloat[smoothness* 3];280 281 for (unsigned int i=0; i<smoothness ; i++) {291 GLfloat* colors = new GLfloat[smoothness*9]; 292 293 for (unsigned int i=0; i<smoothness*3; i++) { 282 294 colors[i*3] = 0.0f; 283 295 colors[i*3+1] = 1.0f; 284 296 colors[i*3+2] = 0.0f; 285 297 } 286 colors[smoothness*3-3] = 0.0f;287 colors[smoothness*3-2] = 0.0f;288 colors[smoothness*3-1] = 1.0f;289 298 290 299 return colors;
Note:
See TracChangeset
for help on using the changeset viewer.