コード例 #1
0
ファイル: PhysicsNode.cpp プロジェクト: mediogre/nutmeg-sdl
	void PhysicsNode::render(AbstractRender *render) const {

		if (render_body) {
			if (body->getBody() == Nutmeg::BODY_CAPSULE) {

				vec3 size = body->getSize();
				float diameter = math::min(size.x, size.y);
				float height = size.z;

				renderCapsule(getScene(), render, diameter, height, getPos(true), getRot(true));

			} else {
				render->setMatrix(origin);
				render->drawMesh(scene->getPrimitive(body->getBody()));
			}
		}
	
		/*
		if (render_body) {
			//mat4 matrix;
			//body->getMatrix(matrix);
			//matrix = mat4::scale(scale) * matrix;
			//render->setMatrix(matrix);

			render->setMatrix(origin);
			render->drawMesh(scene->getPrimitive(body->getBody()));
		}
		*/

	}
コード例 #2
0
ファイル: main.cpp プロジェクト: bmarcott/cs275
void drawGeom( dGeomID g, int colored = 0 )
{
	if( !g )		//If the geometry object is missing, end the function.
		return;

	const dReal *position;		//Define pointers to internal positions and orientations.
	const dReal *orientation;	//Pointers to constant objects (so the objects will not change).

	int type = dGeomGetClass( g );				//Get the type of geometry.

	position = dGeomGetPosition( g );		//Then, get the geometry position.
	orientation = dGeomGetRotation( g );	//And get existing geometry orientation.
	
	if( type == dBoxClass )						//Is it a box?
	{		
		dReal sides[3];
		dGeomBoxGetLengths( g, sides );				//Get length of sides.
		renderBox( sides, position, orientation, colored );	//Render the actual box in environment.
	}
	else if (type == dCylinderClass)
	{
		dReal radius, length;
		dGeomCylinderGetParams(g, &radius, &length);
		renderCylinder(radius, length, position, orientation);
	}
	else if (type == dCapsuleClass)
	{
		dReal radius, length;
		dGeomCapsuleGetParams(g, &radius, &length);
		renderCapsule(radius, length, position, orientation);
	}
}
コード例 #3
0
/*******************************************************************************
Function to draw a geometry object.
*******************************************************************************/
void GOdeObject::drawGeom( dGeomID g, const dReal *position, const dReal *orientation ) const
{
	if( !g )		//If the geometry object is missing, end the function.
		return;

	if( !position )	//Position was not passed?
		position = dGeomGetPosition( g );		//Then, get the geometry position.

	if( !orientation )	//Orientation was not given?
		orientation = dGeomGetRotation( g );	//And get existing geometry orientation.

	int type = dGeomGetClass( g );				//Get the type of geometry.
	
	if( type == dBoxClass )						//Is it a box?
	{
		dReal sides[3];
		dGeomBoxGetLengths( g, sides );				//Get length of sides.
		renderBox( sides, position, orientation );	//Render the actual box in environment.
	}

	if( type == dSphereClass )					//Is it a sphere?
	{
		dReal radius;
		radius = dGeomSphereGetRadius( g );				//Get the radius.
		renderSphere( radius, position, orientation );	//Render sphere in environment.
	}

	if( type == dCapsuleClass )
	{
		dReal radius;
		dReal length;
		dGeomCapsuleGetParams( g, &radius, &length );	//Get both radius and length.
		renderCapsule( radius, length, position, orientation );	//Render capsule in environment.
	}

	if( type == dGeomTransformClass )					//Is it an embeded geom in a composite body.
	{
		dGeomID g2 = dGeomTransformGetGeom( g );		//Get the actual geometry inside the wrapper.
		const dReal *position2 = dGeomGetPosition( g2 );	//Get position and orientation of wrapped geometry.
		const dReal *orientation2 = dGeomGetRotation( g2 );
		
		dVector3 actualPosition;						//Real world coordinated position and orientation
		dMatrix3 actualOrientation;						//of the wrapped geometry.
		
		dMultiply0_331( actualPosition, orientation, position2 );	//Get world coordinates of geometry position.
		actualPosition[0] += position[0];
		actualPosition[1] += position[1];
		actualPosition[2] += position[2];

		dMultiply0_333( actualOrientation, orientation, orientation2 );	//Get world coordinates of geom orientation.

		drawGeom( g2, actualPosition, actualOrientation );	//Draw embeded geometry.
	}
}
コード例 #4
0
ファイル: PhysicsNode.cpp プロジェクト: mediogre/nutmeg-sdl
	void PhysicsNode::renderHelper(AbstractRender *render, bool selected) const {

		vec3 color = render->getColor();

		if (selected) {

		} else {

			if (render_body) return;

			render->setColor(vec3(0.5f, 0.2f, 1.0f), render->getAlpha());

		}

		if (this->body->getBody() == Nutmeg::BODY_CAPSULE) {

			vec3 size = body->getSize();
			float diameter = math::min(size.x, size.y);
			float height = size.z;

			renderCapsule(getScene(), render, diameter, height, pos, rot, true);

		} else {
			mat4 m;
			body->getMatrix(m);
			m = mat4::scale(body->getSize()) * m;
			render->setMatrix(m);
			render->drawMesh(scene->getPrimitive(body->getBody()), true);
		}

		if (selected == false) {
			render->setColor(color, render->getAlpha());
		}


	}