https://github.com/xbpeng/DeepTerrainRL
Revision 2dea28963a7a53a041193371ce287883ab944ea1 authored by Glen on 19 October 2016, 16:52:30 UTC, committed by GitHub on 19 October 2016, 16:52:30 UTC
1 parent 36d2167
Raw File
Tip revision: 2dea28963a7a53a041193371ce287883ab944ea1 authored by Glen on 19 October 2016, 16:52:30 UTC
Update README.md
Tip revision: 2dea289
DrawObj.cpp
#include "DrawObj.h"

void cDrawObj::Draw(const cSimObj* obj, cDrawUtil::eDrawMode draw_mode)
{
	cSimObj::eShape shape = obj->GetShape();
	switch (shape)
	{
	case cSimObj::eShapeBox:
		DrawBox(reinterpret_cast<const cSimBox*>(obj), draw_mode);
		break;
	case cSimObj::eShapePlane:
		DrawPlane(reinterpret_cast<const cSimPlane*>(obj), draw_mode);
		break;
	case cSimObj::eShapeCapsule:
		DrawCapsule(reinterpret_cast<const cSimCapsule*>(obj), draw_mode);
		break;
	default:
		assert(false); // unsupported shape
		break;
	}
}

void cDrawObj::DrawBox(const cSimBox* box, cDrawUtil::eDrawMode draw_mode)
{
	tVector pos = box->GetPos();
	tVector size = box->GetSize();
	tVector axis;
	double theta;
	box->GetRotation(axis, theta);

	glPushMatrix();

	cDrawUtil::Translate(pos);
	cDrawUtil::Rotate(theta, axis);
	cDrawUtil::DrawBox(tVector::Zero(), size, draw_mode);

	glPopMatrix();
}

void cDrawObj::DrawPlane(const cSimPlane* plane, double size, cDrawUtil::eDrawMode draw_mode)
{
	tVector coeffs = plane->GetCoeffs();
	cDrawUtil::DrawPlane(coeffs, size, draw_mode);
}

void cDrawObj::DrawCapsule(const cSimCapsule* cap, cDrawUtil::eDrawMode draw_mode)
{
	tVector pos = cap->GetPos();
	double h = cap->GetHeight();
	double r = cap->GetRadius();
	tVector axis;
	double theta;
	cap->GetRotation(axis, theta);

	glPushMatrix();

	cDrawUtil::Translate(pos);
	cDrawUtil::Rotate(theta, axis);
	cDrawUtil::DrawCapsule(h, r, 8, 8, draw_mode);

	glPopMatrix();
}
back to top