cloth

view src/disc.cc @ 3:28a31079dcdf

disc
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 04 Jan 2016 10:52:15 +0200
parents
children
line source
1 #include "disc.h"
2 #include "opengl.h"
3 #include "simworld.h"
5 Disc::Disc()
6 {
7 radius = 1.0f;
8 }
10 Disc::Disc(const Vector3 &pt, const Vector3 &norm, float rad)
11 : Plane(pt, norm)
12 {
13 radius = rad;
14 }
16 bool Disc::collision(const Ray &ray, float rad, Collision *col) const
17 {
18 if(!Plane::collision(ray, rad, col)) {
19 return false;
20 }
21 Vector3 pt = this->pt - normal * rad;
22 float dist_sq = (col->pos - pt).length_sq();
23 if(dist_sq > radius * radius) {
24 return false;
25 }
26 return true;
27 }
29 void Disc::draw() const
30 {
31 Matrix4x4 rot_matrix = calc_rot_matrix();
33 glMatrixMode(GL_MODELVIEW);
34 glPushMatrix();
35 glMultTransposeMatrixf(rot_matrix[0]);
37 glBegin(GL_TRIANGLE_FAN);
38 glNormal3f(normal.x, normal.y, normal.z);
39 glVertex2f(0, 0);
40 const int segm = 42;
41 for(int i=0; i<segm; i++) {
42 float u = (float)i / (float)(segm - 1);
43 float theta = u * M_PI * 2.0;
44 float x = cos(theta) * radius;
45 float y = sin(theta) * radius;
46 glVertex2f(x, y);
47 }
48 glEnd();
50 glPopMatrix();
51 }