Example #1
0
void Frog::drawLimb(float * begin, float * length) {
   Sphere joint;
   Cylinder limb;

   float end[3] = {begin[0] + length[0], begin[1] + length[1], begin[2] + length[2]};
   float mag = sqrt(length[0]*length[0] + length[1]*length[1] + length[2]*length[2]);
   float norm[3] = {length[0]/mag, length[1]/mag, length[2]/mag};
   float cross[3] = {norm[2], 0, -1*norm[0]};
   float angle = acos(norm[1]) * 180 / 3.14159f;

   glColor3f(color[0], color[1], color[2]);
   glPushMatrix();
   glTranslatef(begin[0], begin[1], begin[2]);
   glRotatef(angle, cross[0], cross[1], cross[2]);
   glScalef(.1, mag, .1);
   limb.draw();
   glPopMatrix();

   glColor3f(color[0], color[1], color[2]);
   glPushMatrix();
   glTranslatef(begin[0], begin[1], begin[2]);
   glScalef(.1, .1, .1);
   joint.draw();
   glPopMatrix();

   glPushMatrix();
   glTranslatef(end[0], end[1], end[2]);
   glScalef(.1, .1, .1);
   joint.draw();
   glPopMatrix();
}
Example #2
0
//
// The Graphics Callback runs in the application "client thread" (qhStart) and sets the transformations
// for the Red Sphere and Green Line of the Cursor. Also, this callback sets the WorldToDevice matrix
// for use in the ServoLoopCallback.
//
void GraphicsCallback(void)
{
    QHGLUT* localDisplayObject = QHGLUT::searchWindow("Coulomb Field Demo");//Get a Pointer to the display object
    Cursor* localDeviceCursor = Cursor::searchCursor("devCursor");//Get a pointer to the cursor
    Cylinder* localForceArrow = Cylinder::searchCylinder("forceArrow");//get a pointer to the cylinder
    Cone* localForceArrowTip = Cone::searchCone("forceArrowTip");//get a pointer to the cylinder
	Sphere* localCursorSphere = Sphere::searchSphere("cursorSphere");//get a pointer top the Sphere

	if( localDisplayObject == NULL || localDeviceCursor == NULL || localForceArrow == NULL || localCursorSphere == NULL)
		return;

	hduMatrix CylinderTransform;//Transformation for the Cylinder. This transform makes it point toward the Model
	hduVector3Dd localCursorPosition;
	hduVector3Dd DirectionVecX;
	hduVector3Dd PointOnPlane;
	hduVector3Dd DirectionVecY;
	hduVector3Dd DirectionVecZ;

	//Compute the world to device transform
    WorldToDevice = localDisplayObject->getWorldToDeviceTransform();

	// Set transform for Red Sphere
    localCursorPosition = localDeviceCursor->getPosition();//Get the local cursor position in World Space
	
	hduVector3Dd localCursorSpherePos = localCursorSphere->getTranslation();
	localCursorSphere->setTranslation(-localCursorSpherePos);
	localCursorSphere->setTranslation(localCursorPosition);//Set the position of the Sphere the same as the cursor
    
	////////////////////////////////////////////////////////////////////////////////////////////
	//Code to calculate the transform of the green cylinder to point along the force direction
	////////////////////////////////////////////////////////////////////////////////////////////
	hduMatrix DeviceToWorld = WorldToDevice.getInverse();
	HDdouble ForceMagnitude = forceVec.magnitude();
	DeviceToWorld[3][0] = 0.0;			   
	DeviceToWorld[3][1] = 0.0;			   
	DeviceToWorld[3][2] = 0.0;
	DirectionVecX = forceVec * DeviceToWorld;
    DirectionVecX.normalize();
    PointOnPlane.set(0.0,0.0,(DirectionVecX[0]*localCursorPosition[0] + DirectionVecX[1]*localCursorPosition[1] + DirectionVecX[2]*localCursorPosition[2])/DirectionVecX[2]);
    DirectionVecY = PointOnPlane  - localCursorPosition;
    DirectionVecY.normalize();

    DirectionVecZ = -DirectionVecY.crossProduct(DirectionVecX);

    CylinderTransform[0][0] = DirectionVecZ[0]; CylinderTransform[0][1] = DirectionVecZ[1]; CylinderTransform[0][2] = DirectionVecZ[2]; CylinderTransform[0][3] = 0.0;
    CylinderTransform[1][0] = DirectionVecX[0]; CylinderTransform[1][1] = DirectionVecX[1]; CylinderTransform[1][2] = DirectionVecX[2]; CylinderTransform[1][3] = 0.0;
    CylinderTransform[2][0] = DirectionVecY[0]; CylinderTransform[2][1] = DirectionVecY[1]; CylinderTransform[2][2] = DirectionVecY[2]; CylinderTransform[2][3] = 0.0;
    CylinderTransform[3][0] = 0.0             ; CylinderTransform[3][1] = 0.0             ; CylinderTransform[3][2] = 0.0             ; CylinderTransform[3][3] = 1.0;
    CylinderTransform = CylinderTransform * hduMatrix::createTranslation(localCursorPosition[0], localCursorPosition[1], localCursorPosition[2]);
    
    localForceArrow->update(chargeRadius/4, ForceMagnitude*50, 15);
    localForceArrow->setTranslation(localCursorPosition);
    localForceArrow->setTransform(CylinderTransform);

     hduMatrix ConeTransform = CylinderTransform * hduMatrix::createTranslation(DirectionVecX[0]
     * ForceMagnitude*50,DirectionVecX[1] * ForceMagnitude*50,DirectionVecX[2] * ForceMagnitude*50 );

    localForceArrowTip->setTransform(ConeTransform);
	/////////////////////////////////////////////
}
Example #3
0
void DepotChest::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, cylinderlink_t)
{
	Cylinder* parent = getParent();
	if (parent != nullptr) {
		parent->postAddNotification(thing, oldParent, index, LINK_PARENT);
	}
}
Example #4
0
void Parser::parseCylinder(Scene* scene, TransformNode* transform, const Material& mat)
{
  Cylinder* cylinder = 0;
  Material* newMat = 0;

  _tokenizer.Read( CYLINDER );
  _tokenizer.Read( LBRACE );

  for( ;; )
  {
    const Token* t = _tokenizer.Peek();

    switch( t->kind() )
    {
      case MATERIAL:
        delete newMat;
        newMat = parseMaterialExpression( scene, mat );
        break;
      case NAME:
        parseIdentExpression();
        break;
      case RBRACE:
         _tokenizer.Read( RBRACE );
        cylinder = new Cylinder(scene, newMat ? newMat : new Material(mat));
        cylinder->setTransform( transform );
        scene->add( cylinder );
        return;
      default:
        throw SyntaxErrorException( "Expected: cylinder attributes", _tokenizer );
    }
  }

}
Example #5
0
int Line::intersect(std::list<Kernel::V3D> &PntOut, const Cylinder &Cyl) const
/**
For the line that intersects the cylinder generate
add the point to the VecOut, return number of points
added. It does not check the points for validity.

@param PntOut :: Vector of points found by the line/cylinder intersection
@param Cyl :: Cylinder to intersect line with
@return Number of points found by intersection
*/
{
    const Kernel::V3D Cent = Cyl.getCentre();
    const Kernel::V3D Ax = Origin - Cent;
    const Kernel::V3D N = Cyl.getNormal();
    const double R = Cyl.getRadius();
    const double vDn = N.scalar_prod(Direct);
    const double vDA = N.scalar_prod(Ax);
    // First solve the equation of intersection
    double C[3];
    C[0] = 1.0 - (vDn * vDn);
    C[1] = 2.0 * (Ax.scalar_prod(Direct) - vDA * vDn);
    C[2] = Ax.scalar_prod(Ax) - (R * R + vDA * vDA);
    std::pair<std::complex<double>, std::complex<double>> SQ;
    const int ix = solveQuadratic(C, SQ);
    // This takes the centre displacement into account:
    return lambdaPair(ix, SQ, PntOut);
}
Example #6
0
void Reward::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, cylinderlink_t)
{
	Cylinder* parent = getParent();
	if (parent != nullptr) {
		parent->postRemoveNotification(thing, newParent, index, LINK_PARENT);
	}
}
Example #7
0
Assembly *GraspGLObjects::CreateVisualTool( double magnifier ) {

	Assembly *tool = new Assembly();

	// Create a set of 'fingers', each of which is a 'capsule' composed of a tube with rounded caps.
	static int n_fingers = target_balls-1;

	double radius = finger_ball_radius * magnifier;
	double length = finger_length * magnifier;

	double spacing = radius * 2.0;

	for ( int trg = - n_fingers; trg <= n_fingers ; trg++ ){


		// Each finger is a 'capsule' composed of a cylinder that is capped on each end with a sphere.
		Assembly *finger = new Assembly();
		Sphere *sphere = new Sphere( radius );
		sphere->SetPosition( 0.0, 0.0, 0.0 );
		finger->AddComponent( sphere );
		Cylinder *cylinder = new Cylinder( radius, radius, length );
		cylinder->SetPosition( 0.0, 0.0, - length / 2 );
		finger->AddComponent( cylinder );
		sphere = new Sphere( radius );
		sphere->SetPosition( 0.0, 0.0, - length );
		finger->AddComponent( sphere );

		// Space the fingers vertically.
		finger->SetPosition( 0.0, spacing * trg, 0.0 );
		tool->AddComponent( finger );
	}
	SetHandColor( tool, true );

	return tool;
}
Vector ClosestPointCylinder ( Vector const & V, Cylinder const & C )
{
	Vector delta = V - C.getBase();

	delta.y = 0.0f;

	real dist = delta.magnitude();

	Vector point = V;

	// clamp the x-z coords of the point so they're inside the tube

	IGNORE_RETURN( delta.normalize() );
	delta *= std::min( C.getRadius(), dist );
	
	point = C.getBase() + delta;

	// and clamp the y coord so it's inside also

	real min = C.getBase().y;
	real max = min + C.getHeight();

	point.y = clamp( min, V.y, max );

	return point;
}
Example #9
0
inline typename Cylinder<T>::position_type
random_position(Cylinder<T> const& shape, Trng& rng)
{
    // -1 < rng() < 1. See for example CylindricalSurface.hpp.
    return add(shape.position(),
               multiply(shape.unit_z(), rng() * shape.half_length()));
}
void DepotChest::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, bool isCompleteRemoval, cylinderlink_t)
{
	Cylinder* parent = getParent();
	if (parent != nullptr) {
		parent->postRemoveNotification(thing, newParent, index, isCompleteRemoval, LINK_PARENT);
	}
}
AxialBox EncloseABox ( Cylinder const & C )
{
	Vector center = C.getCenter();

	Vector extent( C.getExtentX(), C.getExtentY(), C.getExtentZ() );

	return AxialBox(center-extent,center+extent);
}
PrimitiveShape *CylinderPrimitiveShapeConstructor::Deserialize(
    std::istream *i, bool binary) const
{
    Cylinder cylinder;
    cylinder.Init(binary, i);
    CylinderPrimitiveShape *shape = new CylinderPrimitiveShape(cylinder);
    return shape;
}
PrimitiveShape *CylinderPrimitiveShapeConstructor::Construct(
    const MiscLib::Vector< Vec3f > &samples) const
{
    Cylinder cy;
    if(!cy.Init(samples))
        return NULL;
    return new CylinderPrimitiveShape(cy);
}
Sphere EncloseSphere ( Cylinder const & shape )
{
	float x = shape.getExtentX();
	float y = shape.getExtentY();

    float radius = sqrt( x*x + y*y );

    return Sphere( shape.getCenter(), radius );
}
ContainmentResult     TestCylinderABox ( Cylinder const & C,
									 	 AxialBox const & B )
{
	ContainmentResult test2d = Containment2d::TestCircleABox(C.getBaseCircle(),B);

	ContainmentResult testY = Containment1d::TestRangeRange( C.getRangeY(), B.getRangeY() );

	return Containment::ComposeAxisTests( test2d, testY );
}
Example #16
0
Tile* Item::getTile()
{
	Cylinder* cylinder = getTopParent();
	//get root cylinder
	if (cylinder->getParent()) {
		cylinder = cylinder->getParent();
	}
	return dynamic_cast<Tile*>(cylinder);
}
Example #17
0
int main()
{
	Circle cir;
	cout << "圆的面积为:" << cir.area() << endl;
	Cylinder cy;
	cout << "圆柱体的表面积为:" << cy.area() << endl;
	cout << "圆柱体的体积为:" << cy.volume() << endl;
	return 0;
}
Example #18
0
Player* Item::getHoldingPlayer()
{
	for(Cylinder* p = getParent(); p; p = p->getParent())
	{
		if(p->getCreature())
			return p->getCreature()->getPlayer();
	}

	return NULL;
}
Example #19
0
//Deletes all of the created objects here.
void CloseFunc(){
	window.window_handle = -1;
	cylinder.TakeDown();torus.TakeDown();square.TakeDown();square2.TakeDown();
	disc.TakeDown();sphere.TakeDown();sphere2.TakeDown();tiger.TakeDown();goldeen.TakeDown();
	stadium.TakeDown();coin.TakeDown();ss.TakeDown();healthBar.TakeDown();
	shark.TakeDown();bird.TakeDown();sb.TakeDown();arena.TakeDown();skyboxUW.TakeDown();fbo.TakeDown();rain2.TakeDown();
	tri2.TakeDown();skybox.TakeDown();skybox2.TakeDown();skybox3.TakeDown();egg.TakeDown();snow2.TakeDown();
	star.TakeDown();magneton.TakeDown();haunter.TakeDown();frog.TakeDown();
	sph1.TakeDown(); enm.TakeDown(); usr.TakeDown();sq4.TakeDown();soldier.TakeDown();userTeam.TakeDown();cpuTeam.TakeDown();
}
Example #20
0
Player* Item::getHoldingPlayer()
{
	Cylinder* p = getParent();
	while(p){
		if(p->getCreature())
			// Must be a player, creatures are not cylinders
			return p->getCreature()->getPlayer();
		p = p->getParent();
	}
	return NULL;
}
PrimitiveShape *CylinderPrimitiveShapeConstructor::Construct(
    const MiscLib::Vector< Vec3f > &points,
    const MiscLib::Vector< Vec3f > &normals) const
{
    Cylinder cy;
    MiscLib::Vector< Vec3f > samples(points);
    std::copy(normals.begin(), normals.end(), std::back_inserter(samples));
    if(!cy.Init(samples))
        return NULL;
    return new CylinderPrimitiveShape(cy);
}
void computeBV<OBB>(const Cylinder& s, OBB& bv)
{
  Vec3f R[3];
  matMulMat(s.getRotation(), s.getLocalRotation(), R);
  Vec3f T = matMulVec(s.getRotation(), s.getLocalTranslation()) + s.getTranslation();

  bv.To = T;
  bv.axis[0] = Vec3f(R[0][0], R[1][0], R[2][0]);
  bv.axis[1] = Vec3f(R[0][1], R[1][1], R[2][1]);
  bv.axis[2] = Vec3f(R[0][2], R[1][2], R[2][2]);
  bv.extent = Vec3f(s.radius, s.radius, s.lz / 2);
}
void computeBV<AABB>(const Cylinder& s, AABB& bv)
{
  Vec3f R[3];
  matMulMat(s.getRotation(), s.getLocalRotation(), R);
  Vec3f T = matMulVec(s.getRotation(), s.getLocalTranslation()) + s.getTranslation();

  BVH_REAL x_range = fabs(R[0][0] * s.radius) + fabs(R[0][1] * s.radius) + 0.5 * fabs(R[0][2] * s.lz);
  BVH_REAL y_range = fabs(R[1][0] * s.radius) + fabs(R[1][1] * s.radius) + 0.5 * fabs(R[1][2] * s.lz);
  BVH_REAL z_range = fabs(R[2][0] * s.radius) + fabs(R[2][1] * s.radius) + 0.5 * fabs(R[2][2] * s.lz);

  bv.max_ = T + Vec3f(x_range, y_range, z_range);
  bv.min_ = T + Vec3f(-x_range, -y_range, -z_range);
}
Example #24
0
inline std::pair<typename Cylinder<T_>::position_type,
                 typename Cylinder<T_>::length_type>
projected_point(Cylinder<T_> const& obj,
                typename Cylinder<T_>::position_type const& pos)
{
    typedef typename Cylinder<T_>::length_type length_type;

    // The projection lies on the z-axis.
    std::pair<length_type, length_type> r_z(to_internal(obj, pos));
    return std::make_pair(
        add(obj.position(), multiply(obj.unit_z(), r_z.second)),
        r_z.first);
}
Example #25
0
int main() {
	Circle a;
	Circle b(Point(1, 3), 3);
	Cylinder c;
	Cylinder d(Point(2, -4), 3, 4);
	Point e;
	Point f(4, 5);

	cout << "\nThe Circles:\n\tDefault:\n\t\t" << a.toString() << "\n\tCustom:\n\t\t" << b.toString() << endl;
	cout << "\nThe Cylinders:\n\tDefault:\n\t\t" << c.toString() << "\n\tCustom:\n\t\t" << d.toString() << endl;
	cout << "\nThe Points:\n\tDefault:\n\t\t" << e.toString() << "\n\tCustom:\n\t\t" << f.toString() << endl;
	return 0;
}
Example #26
0
bool CylinderPrimitiveShape::Fit(const PointCloud &pc, float epsilon,
	float normalThresh, MiscLib::Vector< size_t >::const_iterator begin,
	MiscLib::Vector< size_t >::const_iterator end)

{
	Cylinder fit = m_cylinder;
	if(fit.LeastSquaresFit(pc, begin, end))
	{
		m_cylinder = fit;
		return true;
	}
	return false;
}
Example #27
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_KEYDOWN:
		{
			Helper::SpectatorCoords* pSpectatorCoords = NULL;
			Cylinder* cylinder = NULL;
			pSpectatorCoords = reinterpret_cast<Helper::SpectatorCoords*>(
												GetWindowLong(hWnd, 0));
			cylinder = reinterpret_cast<Cylinder*>( GetWindowLong(hWnd,sizeof(LONG)) );
			switch(wParam)
			{
			case VK_UP:
				pSpectatorCoords->DecTheta();
				break;
			case VK_DOWN:
				pSpectatorCoords->IncTheta();
				break;
			case VK_RIGHT:
				pSpectatorCoords->IncPhi();
				break;
			case VK_LEFT:
				pSpectatorCoords->DecPhi();
				break;
			case VK_NEXT:
			case 'S':
				pSpectatorCoords->IncR();
				break;
			case VK_PRIOR:
			case 'W':
				pSpectatorCoords->DecR();
				break;
			default:
				return DefWindowProc(hWnd, message, wParam, lParam);
			}
			cylinder->SetViewMatrix( ViewMatrix( pSpectatorCoords->GetCartesianCoords(),
												 D3DXVECTOR3(0.0f, 0.0f, 0.0f),
												 D3DXVECTOR3(0.0f, 1.0f, 0.0f)) );

			break;
		}
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}

	return 0;
}
Example #28
0
float Cylinder::nhs(const Cylinder &c) const
{
	int hamming = 0;
	const float P = 30;

	if (abs(dFi(getrT(),c.getrT())) > 0.785398163397 || dss(c.getX(), c.getY()) > DELTAXY*DELTAXY)
		return 0;
	
	for(unsigned int i = 0; i < NUMCELLS; ++i)
		if (getB1(i) != c.getB1(i))
			hamming++;
		
	return pow(1.0-((float)hamming)/NUMCELLS, P);
}
Example #29
0
Node<real>* SceneImporter<real>::ReadCylinder( std::istream& stream, const std::string& name )
{
	Cylinder<real>* cylinder = new Cylinder<real>;
	cylinder->SetName( name );

	ReadGeometryHeader( stream, cylinder ); ReadNextExactToken( stream, "," );

	real height = ReadReal( stream ); ReadNextExactToken( stream, "," );
	real radius = ReadReal( stream ); ReadNextExactToken( stream, "," );
	real radiusSubdivisions = ReadUnsignedInt( stream );
	cylinder->SetSizes( height, radius, radiusSubdivisions );

	return cylinder;
}
Example #30
0
Player* Item::getHoldingPlayer()
{
	Cylinder* p = getParent();

	while (p) {
		if (p->getCreature()) {
			return p->getCreature()->getPlayer();
		}

		p = p->getParent();
	}

	return NULL;
}