cloth

annotate src/disc.cc @ 3:28a31079dcdf

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