cloth

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/disc.cc	Mon Jan 04 10:52:15 2016 +0200
     1.3 @@ -0,0 +1,51 @@
     1.4 +#include "disc.h"
     1.5 +#include "opengl.h"
     1.6 +#include "simworld.h"
     1.7 +
     1.8 +Disc::Disc()
     1.9 +{
    1.10 +	radius = 1.0f;
    1.11 +}
    1.12 +
    1.13 +Disc::Disc(const Vector3 &pt, const Vector3 &norm, float rad)
    1.14 +	: Plane(pt, norm)
    1.15 +{
    1.16 +	radius = rad;
    1.17 +}
    1.18 +
    1.19 +bool Disc::collision(const Ray &ray, float rad, Collision *col) const
    1.20 +{
    1.21 +	if(!Plane::collision(ray, rad, col)) {
    1.22 +		return false;
    1.23 +	}
    1.24 +	Vector3 pt = this->pt - normal * rad;
    1.25 +	float dist_sq = (col->pos - pt).length_sq();
    1.26 +	if(dist_sq > radius * radius) {
    1.27 +		return false;
    1.28 +	}
    1.29 +	return true;
    1.30 +}
    1.31 +
    1.32 +void Disc::draw() const
    1.33 +{
    1.34 +	Matrix4x4 rot_matrix = calc_rot_matrix();
    1.35 +
    1.36 +	glMatrixMode(GL_MODELVIEW);
    1.37 +	glPushMatrix();
    1.38 +	glMultTransposeMatrixf(rot_matrix[0]);
    1.39 +
    1.40 +	glBegin(GL_TRIANGLE_FAN);
    1.41 +	glNormal3f(normal.x, normal.y, normal.z);
    1.42 +	glVertex2f(0, 0);
    1.43 +	const int segm = 42;
    1.44 +	for(int i=0; i<segm; i++) {
    1.45 +		float u = (float)i / (float)(segm - 1);
    1.46 +		float theta = u * M_PI * 2.0;
    1.47 +		float x = cos(theta) * radius;
    1.48 +		float y = sin(theta) * radius;
    1.49 +		glVertex2f(x, y);
    1.50 +	}
    1.51 +	glEnd();
    1.52 +
    1.53 +	glPopMatrix();
    1.54 +}