Пример #1
0
void mesa_redonda(float alt) {
	float altura=alt;
//Extras
	float expMesa=altura/13;
	float altCone=altura*0.2, altCilin=altura-altCone;
	int camadas=60,lad=60;
//figuras
	Cone *con = new Cone(altCone*1.5,altCone,camadas,lad,camadas);
	Cilindro *cilAlt = new Cilindro(altCone*1.5/2,altCilin,camadas,lad,camadas);
	Cilindro *cilTampo = new Cilindro(altCone*2.5,expMesa,camadas,lad,camadas);

	glPushMatrix();

	con->desenhar();

	glPopMatrix();
	glPushMatrix();

	glTranslatef(0,(altCone*0.5)+(altCilin/2),0);
	cilAlt->desenhar();

	glPopMatrix();
	glPushMatrix();
	
	glTranslatef(0,(altCone*0.5)+(altCilin)+(expMesa/2),0);
	
	cilTampo->desenhar();
	
	glPopMatrix();
	
}
Пример #2
0
void update(void)
{
    /* this sets Maze_Timer which actually is used later */
    timeval thisTime;
    gettimeofday(&thisTime, NULL);
    timersub(&thisTime, &Initial_Timer, &Maze_Timer);


    work(&Widget_List, &Mouse_State);

    cone1.update();
    cone2.update();


    for (unsigned int i=0; i<Player_List.size(); ++i) {
        Player_List[i]->update();
    }

    updateCamera();

#ifndef DEBUG_DISABLE_COLLISION
    cameraCollision();
#endif
    checkForWinners();
}
Пример #3
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);
	/////////////////////////////////////////////
}
Пример #4
0
void Microphone::setUprightRadius (float r) {
	float shift = r - uR;
	uR = r;

	Cone		upright	 (uH * 0.35211f, uR * 0.66667f, uR * 0.66667f, 24),
				shroudLow(uH * 0.21127f, uR, uR, 24),
				shroudHi (uH * 0.63317f, uR, uR, 24),
				bridge   (uH * 0.084537f,uR * 0.66667f, uR * 0.41667f, 24);
	upright.Fly(bH);
	shroudLow.Fly(tH * 0.0823f);
	shroudHi.Fly(shroudLow.getPosition().z + shroudLow.getHeight() + uG);
	bridge.Fly(shroudHi.getPosition().z + shroudHi.getHeight());

	replaceMesh(MIC_UPRIGHT, upright);
	replaceMesh(MIC_SHROUD_LOW, shroudLow);
	replaceMesh(MIC_SHROUD_HI, shroudHi);
	replaceMesh(MIC_BRIDGE, bridge);

	for (int i = MIC_HANDLE_BU; i < MIC_HEAD; i++){
		micParts[i]->Translate(	micParts[i]->getPosition().x + shift,
								micParts[i]->getPosition().y,
								micParts[i]->getPosition().z);
		recalcMeshVertices((MIC_PART)i, *micParts[i]);
	}
}
Пример #5
0
void CadeiraVBO::banco_alto_parametros(float altura, float raio){

	
	Cone* cc;
	Cilindro* c1,*c2;



	//Parte do centro
	glPushMatrix();
	glRotatef(180,1,0,0);
	glTranslatef(0,-altura,0);
	
	cc=new Cone(raio*0.22,altura,CAM,LAD,DR);
	cc->desenhar();

	glPopMatrix();
	
	
	glPushMatrix();
	glTranslatef(0,altura,0);
	
	c1=new Cilindro(raio,altura*1/8,CAM,LAD,DR);
	c1->desenhar();
	glPopMatrix();

	c2=new Cilindro(raio*0.4,altura*1/8,CAM,LAD,DR);
	c2->desenhar();
}
Пример #6
0
int main()
{
    //set up basisvectors
    std::vector<std::vector<double> > basis(2,std::vector<double>(2));
    basis[0][0] = 1;
    basis[0][1] = 0;
    basis[1][0] = 0;
    basis[1][1] = 1;
    
    
    //define lattice
    Lattice myLattice(2,basis);
    
    //set up cones
    
    Cone Sigma0 = Cone({{1,0},{0,1}},myLattice);
    Cone Sigma11 = Cone({{0,1},{-1,0}},myLattice);
    Cone Sigma12 = Cone({{-1,0},{-1,-1}},myLattice);
    Cone Sigma13 = Cone({{-1,-1},{-2,-3}},myLattice);
    Cone Sigma21 = Cone({{-2,-3},{-1,-2}},myLattice);
    Cone Sigma22 = Cone({{-1,-2},{0,-1}},myLattice);
    Cone Sigma23 = Cone({{0,-1},{1,0}},myLattice);
    
    //Define fan
    std::vector<Cone> myCones = {Sigma0, Sigma11, Sigma12, Sigma13, Sigma21, Sigma22, Sigma23};
    Fan myFan(myCones,myLattice);
    
    //Get dual fan
    Fan myDualFan = myFan.getCorrespondingDualFan();
    
    
    std::vector<Cone> myDualCones = myDualFan.getCones();
    std::cout << "CONES OF THE DUAL FAN" << std::endl;
    std::cout << "----------------------" << std::endl;
    for(int i = 0; i < myDualCones.size();++i)
    {
        std::cout << "Cone nr = " << i  << std::endl;
        Cone myDualCone = myDualCones[i];
        std::vector<std::vector<double> > myBVs = myDualCone.getBasisVectors();
        std::cout << "        " << myBVs[0][0] << std::endl;
        std::cout << "Ray 1 = " << myBVs[0][1] << std::endl;
        std::cout << "        " << myBVs[0][2] << std::endl;
        std::cout << "" << std::endl;
        std::cout << "        " << myBVs[1][0] << std::endl;
        std::cout << "Ray 2 = " << myBVs[1][1] << std::endl;
        std::cout << "        " << myBVs[1][2] << std::endl;
        std::cout << "----------------------" << std::endl;
    }
    
    myFan.drawFan();
    myDualFan.drawFan();
  
    return 0;
}
Пример #7
0
void drawGameMeshes(void)
{
    skybox.render();
    glmaze.render();

    for (unsigned int i=0; i<Player_List.size(); ++i) {
        Player_List[i]->draw();
    }

    cone1.render();
    cone2.render();
}
Пример #8
0
void computeBV<OBB>(const Cone& 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);
}
bool ConePrimitiveShape::Fit(const PointCloud &pc, float epsilon,
	float normalThresh, MiscLib::Vector< size_t >::const_iterator begin,
	MiscLib::Vector< size_t >::const_iterator end)
{
	Cone fit = m_cone;
	if(fit.LeastSquaresFit(pc, begin, end))
	{
		m_cone = fit;
		return true;
	}
	return false;

}
Пример #10
0
void computeBV<AABB>(const Cone& 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);
}
Пример #11
0
void Parser::parseCone(Scene* scene, TransformNode* transform, const Material& mat)
{
  _tokenizer.Read( CONE );
  _tokenizer.Read( LBRACE );

  Cone* cone;
  Material* newMat = 0;

  double bottomRadius = 1.0;
  double topRadius = 0.0;
  double height = 1.0;
  bool capped = true;				// Capped by default

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

    switch( t->kind() )
    {
      case MATERIAL:
        delete newMat;
        newMat = parseMaterialExpression( scene, mat );
        break;
      case NAME:
         parseIdentExpression();
         break;
      case CAPPED:
        capped = parseBooleanExpression();
        break;
      case BOTTOM_RADIUS:
        bottomRadius = parseScalarExpression();
        break;
      case TOP_RADIUS:
        topRadius = parseScalarExpression();
        break;
      case HEIGHT:
        height = parseScalarExpression();
        break;
      case RBRACE:
        _tokenizer.Read( RBRACE );
        cone = new Cone( scene, newMat ? newMat : new Material(mat), 
          height, bottomRadius, topRadius, capped );
        cone->setTransform( transform );
        scene->add( cone );
        scene->addBB( cone );
        return;
      default:
        throw SyntaxErrorException( "Expected: cone attributes", _tokenizer );
    }
  }
}
Пример #12
0
void Handle::drawObjectTranslateAxisForDisplay()
{
	if (!Handle::pObjectXTranslateHandleLine)
		initAxisHandleObjects();

	Cone* pXHead = Handle::pObjectXTranslateHandleHead;
	Cone* pYHead = Handle::pObjectYTranslateHandleHead;
	Cone* pZHead = Handle::pObjectZTranslateHandleHead;

	glDisable(GL_DEPTH_TEST);
	glDisable(GL_LIGHTING);

	EditHandle editHandle = ViewContext::instance().getEditHandle();

	// if we've only got one, then the mouse must be down on one, so only draw that
	if (editHandle >= eXTranslate && editHandle <= eZTranslate)
	{
		if (editHandle == eXTranslate)
		{
			glColor3f(1.0f, 0.0f, 0.0f);
			OpenGLEx::drawLine(Point(0.0f, 0.0f, 0.0f), Point(1.0f, 0.0f, 0.0f));
			pXHead->drawForDisplay();
		}
		else if (editHandle == eYTranslate)
		{
			glColor3f(0.0f, 1.0f, 0.0f);
			OpenGLEx::drawLine(Point(0.0f, 0.0f, 0.0f), Point(0.0f, 1.0f, 0.0f));
			pYHead->drawForDisplay();
		}
		else if (editHandle == eZTranslate)
		{
			glColor3f(0.0f, 0.0f, 1.0f);
			OpenGLEx::drawLine(Point(0.0f, 0.0f, 0.0f), Point(0.0f, 0.0f, 1.0f));
			pZHead->drawForDisplay();
		}
	}
	else
	{
		// draw them all
		glColor3f(1.0f, 0.0f, 0.0f);
		OpenGLEx::drawLine(Point(0.0f, 0.0f, 0.0f), Point(1.0f, 0.0f, 0.0f));
		pXHead->drawForDisplay();

		glColor3f(0.0f, 1.0f, 0.0f);
		OpenGLEx::drawLine(Point(0.0f, 0.0f, 0.0f), Point(0.0f, 1.0f, 0.0f));
		pYHead->drawForDisplay();

		glColor3f(0.0f, 0.0f, 1.0f);
		OpenGLEx::drawLine(Point(0.0f, 0.0f, 0.0f), Point(0.0f, 0.0f, 1.0f));
		pZHead->drawForDisplay();
	}

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);
}
Пример #13
0
Node<real>* SceneImporter<real>::ReadCone( std::istream& stream, const std::string& name )
{
	Cone<real>* cone = new Cone<real>;
	cone->SetName( name );

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

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

	return cone;
}
PrimitiveShape *ConePrimitiveShape::LSFit(const PointCloud &pc, float epsilon,
	float normalThresh, MiscLib::Vector< size_t >::const_iterator begin,
	MiscLib::Vector< size_t >::const_iterator end,
	std::pair< size_t, float > *score) const
{
	Cone fit = m_cone;
	if(fit.LeastSquaresFit(pc, begin, end))
	{
		score->first = -1;
		return new ConePrimitiveShape(fit);
	}
	score->first = 0;
	return NULL;
}
Пример #15
0
void Microphone::setUprightGap (float g) {
	float shift = g - uG;

	Cone			upright	 (uH * 0.21127f + 2 * g, uR * 0.66667f, uR * 0.66667f, 24),
					shroudLow(uH * 0.21127f, uR, uR, 24),
					shroudHi ( uH * 0.7042f - 2*uG - shift, uR, uR, 24);


	upright.Fly(bH);
	shroudLow.Fly(tH * 0.0823f);
	shroudHi.Fly(shroudLow.getPosition().z + shroudLow.getHeight() + g);


	replaceMesh(MIC_UPRIGHT, upright);
	replaceMesh(MIC_SHROUD_LOW, shroudLow);
	replaceMesh(MIC_SHROUD_HI, shroudHi);
}
Пример #16
0
void Microphone::setUprightHeight (float h) {
	float shift = h - uH;
	tH += shift; uH = tH * 0.58436f;

	Cone			upright	 (uH * 0.21127f + 2 * uG, uR * 0.66667f, uR * 0.66667f, 24),
					shroudLow(uH * 0.21127f, uR, uR, 24),
					shroudHi (uH - upright.getHeight() - uH * 0.084537f, uR, uR, 24),
					bridge   (uH * 0.084537f,uR * 0.66667f, uR * 0.41667f, 24);

	Pyramid			handleBridgeUp	(uH * 0.09155f, uR * 0.653f, hI, uR * 0.653f, hI),
					handleBridgeDown(uH * 0.077f,   uR * 0.653f, hI, uR * 0.653f, hI),
					handle			(uH * 0.7598f,  uR * 0.792f, uR * 0.5418f, uR * 0.5418f, uR * 0.5418f, uR * 0.125f),
					handleTop		(uH * 0.05647f, uR * 0.792f, uR * 0.5418f, uR * 0.792f,  uR * 0.5418f,-uR * 0.3542f);

	upright.Fly(bH);
	shroudLow.Fly(tH * 0.0823f);
	shroudHi.Fly(shroudLow.getPosition().z + shroudLow.getHeight() + uG);
	bridge.Fly(shroudHi.getPosition().z + shroudHi.getHeight());

	handleBridgeUp.Fly(tH * 0.46f);
	handleBridgeUp.Follow(bR * 0.2f);
	handleBridgeDown.Fly(tH * 0.15f);
	handleBridgeDown.Follow(handleBridgeUp.getPosition().x);
	handle.Translate(bR * 0.306f, bR * 0.0059f, tH * 0.547f);
	handle.Pitch((FLOAT)M_PI);
	handle.Yaw((FLOAT)M_PI_2);
	handleTop.Translate(handle.getPosition().x, handle.getPosition().y, handle.getPosition().z);
	handleTop.Yaw((FLOAT)M_PI_2);

	replaceMesh(MIC_UPRIGHT, upright);
	replaceMesh(MIC_SHROUD_LOW, shroudLow);
	replaceMesh(MIC_SHROUD_HI, shroudHi);
	replaceMesh(MIC_BRIDGE, bridge);
	replaceMesh(MIC_HANDLE_BU, handleBridgeUp);
	replaceMesh(MIC_HANDLE_BD, handleBridgeDown);
	replaceMesh(MIC_HANDLE, handle);
	replaceMesh(MIC_HANDLE_TOP, handleTop);

	for (int i = MIC_HEAD; i < PARTS_NUM; i++){
		micParts[i]->Translate(	micParts[i]->getPosition().x,
								micParts[i]->getPosition().y,
								bridge.getPosition().z + bridge.getHeight() + hR);
		recalcMeshVertices((MIC_PART)i, *micParts[i]);
	}
}
Пример #17
0
void Cross::pickCones(const RayCast& ray, int width, int height){
    int distTol = 30;

    float x = ray.currentX;
    float y = ray.currentY;

    float vX = 2.0 / (float) width;
    int rayX = (x + 1.0f) / vX;

    float vY = 2.0 / (float) height;
    int rayY = (y + 1.0f) / vY;

    float minDist = 9999.0f;
    Cone* minBody = NULL;

    for(unsigned int i = 0; i < cones.size(); i++){

        Cone* body = cones[i];
        const vec3& bodyProjectedPosition = body->getProjectedPosition();

        float bodyX = bodyProjectedPosition.x;
        float bodyY = bodyProjectedPosition.y;

        int bodypX = (bodyX + 1.0f) / vX;
        int bodypY  = (bodyY + 1.0f) / vY;

        int dx = rayX - bodypX;
        int dy = rayY - bodypY;
        int dist = sqrt(dx*dx + dy*dy);

        if(dist < distTol){
            if(dist < minDist){
                minDist = dist;
                minBody = body;
            }
        }
    }
    if(minBody != NULL){
        this->pickedCone = minBody;
        this->pickedCone->setColor(COLOR_OBJECT_ACTIVE);
        return;
    }

}
Пример #18
0
bool RayTracer::shadow_ray_intersection(SbVec3f *point_of_intersection, SbVec3f *ray_direction,  int light_source){
    float t_value;
    for(int j=0; j< objects.size(); j++){
        //Cube tempCube;
        bool intersects = false;
        int shapetype = 0;
        shapetype = objects.at(j).shapeType ;


        if(shapetype == 1){
            Sphere tempSphere = objects.at(j);
            if(tempSphere.transparency > 0 && refraction_on) continue;
            intersects = tempSphere.intersection(point_of_intersection, ray_direction, &t_value);
            //intersects = tempSphere.intersection(&poi, &ray_direction, &t_value);
        }
        else if (shapetype ==2){
            //std::cout<<"cube";

            Cube tempCube = objects.at(j);
            if(tempCube.transparency > 0 && refraction_on) continue;
            intersects = tempCube.intersection(point_of_intersection, ray_direction, &t_value);
            //temp = (Cube)tempCube;
        }else if (shapetype == 3){
            Cone tempCone = objects.at(j);
            if(tempCone.transparency > 0 && refraction_on)  continue;
            intersects = tempCone.intersection(point_of_intersection, ray_direction, &t_value);

        }
        else{
            //std::cout<<"cube";
            Cube tempCylinder = objects.at(j);
            if(tempCylinder.transparency > 0 && refraction_on) continue;
            intersects = tempCylinder.intersection(point_of_intersection, ray_direction, &t_value);
            //intersects = tempCube.intersection(&poi, &ray_direction, &t_value);
            //temp = (Cube)tempCube;
        }
        if(intersects)
            return true;

    }
    return false;
}
Пример #19
0
int main()
{

  cout << fixed << showpoint << setprecision(2);

  Cylinder one;
  cout << "Enter cylinder height and radius >>> ";
  cin >> one;
  cout << "The cylinder volume is " << one.volume(one) << endl;
  cout << "The cylinder surface area is " << one.surface_area(one) << endl;
  cout << one;

  Sphere two;
  cout << "Enter sphere radius >>> ";
  cin >> two.radius;
  cout << "The sphere volume is " << two.volume(two) << endl;
  cout << "The sphere surface area is " << two.surface_area(two) << endl;
  cout << two.radius << endl;

  Prism three;
  cout << "Enter rectangular prism base length, height, and width >>> ";
  cin >> three;
  cout << "The rectangular prism volume is " << three.volume(three) << endl;
  cout << "The rectangular prism surface area is " << three.surface_area (three) << endl;
  cout << three;

  Cone four;
  cout << "Enter cone height and radius >>> ";
  cin >> four;
  cout << "The cone volume is " << four.volume(four) << endl;
  cout << "The cone surface area is " << four.surface_area(four) << endl;
  cout << four;

  Pyramid five;
  cout << "Enter pyramid base side length and height >>> ";
  cin >> five;
  cout << "The pyramid volume is " << five.volume(five) << endl;
  cout << "The pyramid surface area is " << five.surface_area(five) << endl;
  cout << five;

  return 0;
}
Пример #20
0
	SpatialObject* SegmentObjectReader::getNext()
	{
		bbp::Vector_3D<bbp::Micron> gbegin = transformation * segmentIT->begin().center();
		bbp::Vector_3D<bbp::Micron> gend   = transformation * segmentIT->end().center();
		Vertex begin = Vertex(gbegin.x(),gbegin.y(),gbegin.z());
		Vertex end   = Vertex(gend.x(),gend.y(),gend.z());
		Cone* segment = new Cone(begin,end,segmentIT->begin().radius(),segmentIT->end().radius());
		Box mbr = segment->getMBR();
		if (counter==1) universe = mbr;
		else
		{
			for (int i=0;i<DIMENSION;i++)
			{
				if (mbr.high[i]>universe.high[i]) universe.high[i] = mbr.high[i];
				if (mbr.low[i]<universe.low[i])   universe.low[i] = mbr.low[i];
			}
		}
		segmentIT++;
		return segment;
	}
Пример #21
0
		void run() {
			glUseProgram(wireframeShaderProgram);

			Vertex centre = {0,0,0};

			Cone cone = Cone(1, 1, centre, 30, 0);

			mat4 Projection = perspective(45.0f, 1.0f, 0.1f, 100.0f);
			mat4 View = lookAt(vec3(0,2,1), vec3(0,0,0), vec3(0,1,0));
			View = scale(View, vec3(0.7f));
			mat4 Model = mat4(1.0f);
			mat4 MVP;
			GLuint MatrixID = glGetUniformLocation(wireframeShaderProgram, "MVP");

			//Running stuff
			running = GL_TRUE;
			double old_time = 0, current_time = 0;
			ostringstream title;
			float rotation = 0.f;
			while( running ) { 
				current_time = glfwGetTime();
				rotation = (float)((current_time - old_time) * speed);
				if (rotation >= 360.f) {
					rotation = 0.f;
				}
				old_time = current_time;
				
				View = rotate(View, rotation, vec3(1, 1, 1));
				MVP = Projection * View * Model;
				glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
		
				glClearColor(0,0,0,0);
				glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
				cone.render();
				glFlush();
				glfwSwapBuffers();	
				if (!glfwGetWindowParam(GLFW_OPENED)) {
					running = GL_FALSE;
				}
			}
		}
Пример #22
0
void Handle::drawObjectTranslateAxisForSelection()
{
	if (!Handle::pObjectXTranslateHandleLine)
		initAxisHandleObjects();

	Cylinder* pXLine = Handle::pObjectXTranslateHandleLine;
	Cylinder* pYLine = Handle::pObjectYTranslateHandleLine;
	Cylinder* pZLine = Handle::pObjectZTranslateHandleLine;

	Cone* pXHead = Handle::pObjectXTranslateHandleHead;
	Cone* pYHead = Handle::pObjectYTranslateHandleHead;
	Cone* pZHead = Handle::pObjectZTranslateHandleHead;

	glDisable(GL_DEPTH_TEST);
	glDisable(GL_LIGHTING);

	pXLine->drawForSelection();
	pXHead->drawForSelection();
	pYLine->drawForSelection();
	pYHead->drawForSelection();
	pZLine->drawForSelection();
	pZHead->drawForSelection();

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);
}
Пример #23
0
void Microphone::setHeadDepth (float d) {
	float shift = d - hD;
	hD = d;

	Hole			head	 (hD,  hR,	 cR, hR, cR, 24),
					headFront(hD / 10.f, hR * 1.075f, cR * 0.9f, hR * 1.075f, cR * 0.9f, 24),
					headBack (hD / 10.f, hR * 1.075f, cR * 0.9f, hR * 1.075f, cR * 0.9f, 24);
	Cone			core	 (hD * 1.43333f,  cR, cR, 24);

	head.Fly(micParts[MIC_HEAD]->getPosition().z);
	head.Strafe(-hD/2);
	head.Pitch((FLOAT)M_PI_2);
	head.Roll((FLOAT)M_PI_2);

	headFront.Fly(head.getPosition().z);
	headFront.Strafe(-head.getPosition().y);
	headFront.Pitch((FLOAT)M_PI_2);
	headFront.Roll((FLOAT)M_PI_2);

	headBack.Translate(head.getPosition());
	headBack.Pitch((FLOAT)M_PI_2);
	headBack.Roll((FLOAT)M_PI_2);

	core.Fly(head.getPosition().z);
	core.Strafe(-core.getHeight() / 2.1f);
	core.Pitch((FLOAT)M_PI_2);
	core.Roll((FLOAT)M_PI_2);

	replaceMesh(MIC_HEAD,		head);
	replaceMesh(MIC_HEAD_FRONT, headFront);
	replaceMesh(MIC_HEAD_BACK,	headBack);
	replaceMesh(MIC_CORE,		core);
}
Пример #24
0
void IntersectionUI::writeTest() const {
    // creates a deterministic sequence of ray positions and directions
    // and writes the resulting intersections to a file
    // you must add the proper intersect calls for this file to be generated
    
    double invBase[5] = {1.0 / 2.0, 1.0 / 3.0, 1.0 / 5.0, 1.0 / 7.0, 1.0 / 11.0};
    double values[5] = {0.0, 0.0, 0.0, 0.0, 0.0};
    std::ofstream file("../intersections.txt");
    file.precision(4);

    const int seed = static_cast<int>(intersectionUI->m_iSeed->value());
    // generate a halton sequence to pick position/ray combinations
    // skip the first 'seed' values
    for (int i = 0; i < seed; i++) {
        for (int j = 0; j < 5; j++) {
            double r = 1.0 - values[j] - 1e-10;
            if (invBase[j] < r)
                values[j] += invBase[j];
            else {
                double hh;
                double h = invBase[j];
                do {
                    hh = h;
                    h *= invBase[j];
                } while (h >= r);
                values[j] += ((hh + h) - 1.0);
            }
        }
    }
    for (int i = seed; i < (seed + 1638); i++) {
        for (int j = 0; j < 5; j++) {
            double r = 1.0 - values[j] - 1e-10;
            if (invBase[j] < r)
                values[j] += invBase[j];
            else {
                double hh;
                double h = invBase[j];
                do {
                    hh = h;
                    h *= invBase[j];
                } while (h >= r);
                values[j] += ((hh + h) - 1.0);
            }
        }
        // create the ray from the five random values
        // compute ray origin
        Point3 p;
        p[0] = values[4] * sin(values[0] * M_PI) * cos(values[1] * 2.0 * M_PI);
        p[1] = values[4] * sin(values[0] * M_PI) * sin(values[1] * 2.0 * M_PI);
        p[2] = values[4] * cos(values[0] * M_PI);
        // compute ray direction
        Vector3 dir;
        dir[0] = sin(values[2] * M_PI) * cos(values[3] * 2.0 * M_PI);
        dir[1] = sin(values[2] * M_PI) * sin(values[3] * 2.0 * M_PI);
        dir[2] = cos(values[2] * M_PI);
        
        HitRecord cubeHr, cylinderHr, coneHr, sphereHr;
        // ToDo: intersect with your shapes here and store the result
        // in the appropriate hit record
        //cube.intersect(p, dir);
		Cube cube = Cube(1);
		cubeHr = *(cube.intersect(p, dir));
        //cylinder.intersect(p, dir);
		Cylinder cylinder = Cylinder(1, 1);
		cylinderHr = *(cylinder.intersect(p, dir));
        //coneHr = cone.intersect(p, dir);
		Cone cone = Cone(1, 1);
		coneHr = *(cone.intersect(p, dir));
        //sphereHr = sphere.intersect(p, dir);
		Sphere sphere = Sphere(1);
		sphereHr = *(sphere.intersect(p, dir));

        // write out
        file << i << " Cube     " << cubeHr     << std::endl;
        file << i << " Cylinder " << cylinderHr << std::endl;
        file << i << " Cone     " << coneHr     << std::endl;
        file << i << " Sphere   " << sphereHr   << std::endl;
    }
    file.close();
}
Пример #25
0
bool RayTracer::shade(SbVec3f *ray_origin, SbVec3f *ray_direction, SbVec3f *retColor, int recursionDepth, int flag){
	float t_value, t_min = 999;
	float epsilon = 0.01;
	SbVec3f normal_at_intersection;
	SbVec3f normal_at_intersection1, actual_ray_direction ;
	bool should_color = false;
    SbVec3f color;
    color[0] = 0.0;
    color[1] = 0.0;
    color[2] = 0.0;
    //Cone *tempCone = new Cone();
    for(int k =0; k<objects.size(); k++){
        //Object temp1 ;
        //temp1 = spheres.at(k);
        Sphere tempSphere;
        Cube tempCube;
        Cone tempCone;
        Object temp;
        bool intersects = false;
        int shapetype = 0;
        shapetype = objects.at(k).shapeType ;
        if(shapetype == 1){
            tempSphere = objects.at(k);
            intersects = tempSphere.intersection(ray_origin, ray_direction, &t_value);
        }
        else if (shapetype ==2){
            //std::cout<<"cube";
            tempCube = objects.at(k);
            intersects = tempCube.intersection(ray_origin, ray_direction, &t_value);
            //temp = (Cube)tempCube;
        }else{
            tempCone = objects.at(k);
            intersects = tempCone.intersection(ray_origin, ray_direction, &t_value);

        }

        if(intersects)
        {
            if(t_value < t_min && t_value > 0 && t_value !=999) {
                t_min = t_value;
                SbVec3f V = -(*ray_direction); //view vector
                V.normalize();
                SbVec3f point_of_intersection ;

                if(shapetype == 1){
                    normal_at_intersection = tempSphere.calculate_normal(ray_origin, ray_direction, t_value);
                    normal_at_intersection.normalize(); // N vector at the point of intersection
                    point_of_intersection = tempSphere.point_of_intersection( ray_origin, ray_direction, t_value);
                    temp = tempSphere;
                }else if(shapetype == 2){
                    normal_at_intersection = tempCube.calculate_normal(ray_origin, ray_direction, t_value);
                    normal_at_intersection.normalize(); // N vector at the point of intersection
                    point_of_intersection = tempCube.point_of_intersection( ray_origin, ray_direction, t_value);
                    temp = tempCube;
                }
                else{
                    normal_at_intersection = tempCone.calculate_normal(ray_origin, ray_direction, t_value);
                    normal_at_intersection.normalize(); // N vector at the point of intersection
                    point_of_intersection = tempCone.point_of_intersection( ray_origin, ray_direction, t_value);
                    temp = tempCone;

                }


                for(int i = 0; i <3; i++) {// set the ambient color component
                        color[i] = (0.2 *  temp.material->ambientColor[0][i] * (1 - temp.transparency ));
                }
                //*retColor = color; return true;//ntc
                // iterate through all the lights and add the diffuse and specular component
                for(int j = 0; j < lights.size(); j++){
                        SbVec3f poi;

                        actual_ray_direction = lights.at(j).position - point_of_intersection ;
                        actual_ray_direction.normalize();
                        poi = point_of_intersection + (epsilon * actual_ray_direction);
                        bool shadowFlag = false;
                        if(shadow_on == 0 || shadow_on == 1)
                        {
                            if(shadow_on == 1)
                                shadowFlag = shadow_ray_intersection(&poi, &actual_ray_direction , j );
                            //shadowFlag = true;
                            if(!shadowFlag)
                            {
                                SbVec3f L = lights.at(j).position - point_of_intersection;
                                L.normalize();
                                SbVec3f R;
                                R = (2 * normal_at_intersection.dot(L) * normal_at_intersection) - L;
                                R.normalize();

                                float NdotL = normal_at_intersection.dot(L);
                                float cos_theta = V.dot(R);

                                for(int i = 0; i <3; i++){
                                    if(NdotL > 0)
                                        color[i] += (( NdotL * temp.material->diffuseColor[0][i] * lights.at(j).intensity * lights.at(j).color[i]  * (1 - temp.transparency )));
                                    if(cos_theta > 0)
                                        color[i] += (( pow(cos_theta, 50) * temp.material->specularColor[0][i]* lights.at(j).intensity * lights.at(j).color[i]) );
                                }
                            }
                        }
                    else
                    { // soft shadows
                            {

                         //shadowLevel = soft_shadow_ray_intersection(&point_of_intersection, j );
                            SbVec3f actual_ray_direction, offset_ray_direction;
                            SbVec3f tempu, tempv, tempn;
                            int number_of_shadow_rays;
                            number_of_shadow_rays = NUMBER_OF_SHADOW_RAYS;
                            float epsilon = 0.01;
                            float R = 0.1;
                            actual_ray_direction = lights.at(j).position - point_of_intersection ;
                            actual_ray_direction.normalize();
                            SbVec3f point = point_of_intersection + (epsilon * actual_ray_direction);

                            calculate_coordinate_system(&tempu, &tempv, &tempn, actual_ray_direction);

                            for(int ir =0; ir< number_of_shadow_rays; ir++){

                                    float du, dv;
                                    //float t;
                                    du = get_random_number();
                                    dv = get_random_number();
                                    du = R * (du - 0.5);
                                    dv = R * (dv - 0.5);
                                    offset_ray_direction = actual_ray_direction + (du * tempu) + (dv * tempv);
                                    offset_ray_direction.normalize();

                                    //offset_ray_direction = actual_ray_direction - (R/2 * u) - (R/2 * v) + (du * R * u) + (dv *R * v);
                                    SbVec3f poi;
                                    poi = point + (epsilon * offset_ray_direction);
                                    //offset_ray_direction = actual_ray_direction;
                                    if(!shadow_ray_intersection(&poi, &offset_ray_direction, j)){
                                        //normal_at_intersection = temp.calculate_normal(&poi, &offset_ray_direction, t_value);
                                        //normal_at_intersection.normalize();
                                        SbVec3f V = -1 * (*ray_direction); //view vector
                                        V.normalize();
                                        SbVec3f L = offset_ray_direction;
                                        L.normalize();
                                        SbVec3f R;
                                        R = (2 * normal_at_intersection.dot(L) * normal_at_intersection) - L;
                                        R.normalize();

                                        float NdotL = normal_at_intersection.dot(L);
                                        float cos_theta = V.dot(R);
                                        //if(temp.transparency > 0) std::cout<<"trnas";
                                        for(int i = 0; i <3; i++){
                                            {
                                                if(NdotL > 0)
                                                    color[i] += (( NdotL * temp.material->diffuseColor[0][i] * lights.at(j).intensity * lights.at(j).color[i]  * (1 - temp.transparency ))/ number_of_shadow_rays);
                                                if(cos_theta > 0)
                                                    color[i] += (( pow(cos_theta, 50) * temp.material->specularColor[0][i]* lights.at(j).intensity * lights.at(j).color[i]) / number_of_shadow_rays);
                                            }
                                        }

                                    }

                    }

                    }

                        }
                }
                SbVec3f refColor(0.0,0.0,0.0);
                SbVec3f refracColor(0.0,0.0,0.0);
                // if the current depth of recustion is less than the maximum depth,
                //reflect the ray and add the color returned dude to the result of reflection
                //std::cout<<"here";
                if(refraction_on && recursionDepth < 2){
                    if(temp.isTransparent){
                        SbVec3f T;
                        if(refract(ray_direction, &normal_at_intersection, &T)){
                            T.normalize();
                            SbVec3f poi;
                            poi = point_of_intersection + (epsilon * T);
                            shade(&poi, &T, &refracColor, recursionDepth+1);
                            color = color + (temp.transparency * refracColor);
                        }

                    }
                }
                if(reflection_on && recursionDepth < 2){

                    if(temp.isShiny){//} && !temp.isTransparent){
                        // compute replection of the ray, R1
                        SbVec3f R1;
                        R1 = reflect(&normal_at_intersection, ray_direction);
                        SbVec3f poi;
                        poi = point_of_intersection + (epsilon * R1);
                        shade(&poi, &R1, &refColor, recursionDepth+1);
                        color = color + ((1 - temp.transparency) * temp.shininess * refColor);

                    }
                }

                should_color = true;
            }

        }
    }
    *retColor = color;
    return should_color;
}
Пример #26
0
void ParticleSystemModel::Emitter::spawnParticles(ParticleSystem* system, int newParticlesToEmit, SimTime absoluteTime, SimTime relativeTime, SimTime deltaTime, int emitterIndex) const {
    // Give up and just place a particle anywhere in the noise field if we can't find
    // a good location by rejection sampling after this many tries.
    const int MAX_NOISE_SAMPLING_TRIES = 20;

    Random& rng = Random::common();
    Noise& noise = Noise::common();
    
    debugAssert(notNull(m_spawnShape));

    for (int i = 0; i < newParticlesToEmit; ++i) {
        ParticleSystem::Particle particle;
        particle.emitterIndex = emitterIndex;

        for (int j = 0; j < MAX_NOISE_SAMPLING_TRIES; ++j) {
            switch (m_specification.location) {
            case SpawnLocation::FACES:
                alwaysAssertM(m_spawnShape->type() == Shape::Type::MESH, "SpawnLocation::FACES requires a mesh");
                {
                    const shared_ptr<MeshShape>& mesh = dynamic_pointer_cast<MeshShape>(m_spawnShape);
                    const Array<int>& indexArray = mesh->indexArray();
                    const Array<Point3>& vertexArray = mesh->vertexArray();
                    const int i = rng.integer(0, indexArray.size() / 3 - 1) * 3;
                    particle.position = (vertexArray[indexArray[i]] + vertexArray[indexArray[i + 1]] + vertexArray[indexArray[i + 2]]) / 3.0f;
                }
                break;

            case SpawnLocation::VERTICES:
                alwaysAssertM(m_spawnShape->type() == Shape::Type::MESH, "SpawnLocation::VERTICES requires a mesh");
                {
                    const shared_ptr<MeshShape>& mesh = dynamic_pointer_cast<MeshShape>(m_spawnShape);
                    particle.position = mesh->vertexArray().randomElement();
                }
                break;

            case SpawnLocation::SURFACE:
                m_spawnShape->getRandomSurfacePoint(particle.position);
                break;

            case SpawnLocation::VOLUME:
                particle.position = m_spawnShape->randomInteriorPoint();
                if (particle.position.isNaN()) {
                    // For poorly formed meshes...or even good ones with really bad luck...
                    // sometimes randomInteriorPoint will fail. In this case, generate a surface
                    // point, which is technically "on the interior" still, just poorly distributed.
                    m_spawnShape->getRandomSurfacePoint(particle.position);
                }
                break;
            } // switch

            // Unique values every 5m for the lowest frequencies
            if (m_specification.noisePower == 0.0f) {
                // Accept any generated position
                break;
            } else { 
                const Vector3int32 intPos(particle.position * ((1 << 16) / (5 * units::meters())));
                const float acceptProbability = pow(max(0.0f, noise.sampleFloat(intPos.x, intPos.y, intPos.z, 5)), m_specification.noisePower);

                if (rng.uniform() <= acceptProbability) {
                    // An acceptable position!
                    break;
                }        
            }
        }

        particle.angle = rng.uniform(0.0f, 2.0f * pif());
        particle.radius = fabs(rng.gaussian(m_specification.radiusMean, sqrt(m_specification.radiusVariance)));

        if (m_specification.coverageFadeInTime == 0.0f) {
            particle.coverage = 1.0f;
        } else {
            particle.coverage = 0.0f;
        }

        particle.userdataFloat = 0.0f;
        particle.mass = m_specification.particleMassDensity * (4.0f / 3.0f) * pif() * particle.radius * particle.radius * particle.radius;

        if (m_specification.velocityConeAngleDegrees >= 180) {
            particle.velocity = Vector3::random(rng);
        } else if (m_specification.velocityConeAngleDegrees > 0) {
            const Cone emissionCone(Point3(), 
                m_specification.velocityDirectionMean, 
                m_specification.velocityConeAngleDegrees * 0.5f);
            particle.velocity = emissionCone.randomDirectionInCone(rng);
        } else {
            particle.velocity = m_specification.velocityDirectionMean;
        }
        particle.velocity *= fabs(rng.gaussian(m_specification.velocityMagnitudeMean, m_specification.velocityMagnitudeVariance));
        particle.angularVelocity = rng.gaussian(m_specification.angularVelocityMean, m_specification.angularVelocityVariance);

        particle.spawnTime = absoluteTime;
        particle.expireTime = absoluteTime + fabs(rng.gaussian(m_specification.particleLifetimeMean, m_specification.particleLifetimeVariance));

        particle.dragCoefficient = m_specification.dragCoefficient;
        particle.material = m_material;

        particle.userdataInt = 0;

        if (system->particlesAreInWorldSpace()) {
            // Transform to world space
            particle.position = system->frame().pointToWorldSpace(particle.position);
            particle.velocity = system->frame().vectorToWorldSpace(particle.velocity);
        }

        // Directly add to the particle system
        system->m_particle.append(particle);

    } // for new particles

    if (newParticlesToEmit > 0) {
        system->markChanged();
    }
}
Пример #27
0
void Microphone::Triangulate() {
	vertices.clear();
	edges.clear();
	polygons.clear();

	ExCone			base(bH, bR, bR, bR * 0.824f, precision);
	Pyramid			buttonL(bH * 0.6f, bW * 0.575f, bW, bW * 0.3f, bW, -bW * 0.1375f),
					buttonR(bH * 0.6f, bW * 0.575f, bW, bW * 0.3f, bW, -bW * 0.1375f);
	
	Cone			shroudLow(uH * 0.21127f, uR, uR, precision),
					bridge   (uH * 0.084537f, uR * 0.66667f, uR * 0.41667f, precision),
					shroudHi (uH - uG - shroudLow.getHeight() - uH * .04f - bridge.getHeight(), uR, uR, precision),
					upright	 (uH - bridge.getHeight(), uR * 0.66667f, uR * 0.66667f, precision);

	Pyramid			handleBridgeUp	(uH * 0.09155f, uR * 0.653f, hI, uR * 0.653f, hI),
					handleBridgeDown(uH * 0.077f,   uR * 0.653f, hI, uR * 0.653f, hI),
					handle			(uH * 0.7598f,  uR * 0.792f, uR * 0.5418f, uR * 0.5418f, uR * 0.5418f, uR * 0.125f),
					handleTop		(uH * 0.05647f, uR * 0.792f, uR * 0.5418f, uR * 0.792f,  uR * 0.5418f,-uR * 0.3542f);

	Hole			head	 (hD,  hR,	 cR, hR, cR, precision),
					headFront(hD / 10.f, hR * 1.075f, cR * 0.9f, hR * 1.075f, cR * 0.9f, precision),
					headBack (hD / 10.f, hR * 1.075f, cR * 0.9f, hR * 1.075f, cR * 0.9f, precision);
	Cone			core	 (hD * 1.43333f,  cR, cR, precision);

	base.Yaw(-(FLOAT)M_PI_2);
	base.Transform();

	buttonL.Translate(-bR * 0.2588f, bR * 0.824f, bH * 1.1f);
	buttonL.Pitch((FLOAT)M_PI);
	buttonL.Transform();

	buttonR.Translate(bR * 0.2588f, bR * 0.824f, bH * 1.1f);
	buttonR.Pitch((FLOAT)M_PI);
	buttonR.Transform();

	upright.Fly(bH);
	upright.Transform();

	shroudLow.Fly(base.getHeight() + uH * .04f);
	shroudLow.Transform();

	shroudHi.Fly(shroudLow.getPosition().z + shroudLow.getHeight() + uG);
	shroudHi.Transform();

	bridge.Fly(shroudHi.getPosition().z + shroudHi.getHeight());
	bridge.Transform();

	handleBridgeUp.Fly(uH * 0.8f);
	handleBridgeUp.Follow(uR + hI / 2);
	handleBridgeUp.Transform();

	handleBridgeDown.Fly(bH + uH * 0.15f);
	handleBridgeDown.Follow(handleBridgeUp.getPosition().x);
	handleBridgeDown.Transform();

	handle.Translate(uR * 1.5f + hI, bR * 0.0059f, uH * .95f);
	handle.Pitch((FLOAT)M_PI);
	handle.Yaw((FLOAT)M_PI_2);
	handle.Transform();

	handleTop.Translate(handle.getPosition().x, handle.getPosition().y, handle.getPosition().z);
	handleTop.Yaw((FLOAT)M_PI_2);
	handleTop.Transform();

	head.Fly(bridge.getPosition().z + bridge.getHeight() + hR);
	head.Strafe(-hD/2);
	head.Pitch((FLOAT)M_PI_2);
	head.Roll((FLOAT)M_PI_2);
	head.Transform();

	headFront.Fly(head.getPosition().z);
	headFront.Strafe(-head.getPosition().y);
	headFront.Pitch((FLOAT)M_PI_2);
	headFront.Roll((FLOAT)M_PI_2);
	headFront.Transform();

	headBack.Translate(head.getPosition());
	headBack.Pitch((FLOAT)M_PI_2);
	headBack.Roll((FLOAT)M_PI_2);
	headBack.Transform();

	core.Fly(head.getPosition().z);
	core.Strafe(-core.getHeight() / 2.1f);
	core.Pitch((FLOAT)M_PI_2);
	core.Roll((FLOAT)M_PI_2);
	core.Transform();

	addMesh(MIC_BASE,		base);
	addMesh(MIC_BUTTON_L,	buttonL);
	addMesh(MIC_BUTTON_R,	buttonR);
	addMesh(MIC_UPRIGHT,	upright);
	addMesh(MIC_SHROUD_LOW,	shroudLow);
	addMesh(MIC_SHROUD_HI,	shroudHi);
	addMesh(MIC_BRIDGE,		bridge);
	addMesh(MIC_HANDLE_BU,	handleBridgeUp);
	addMesh(MIC_HANDLE_BD,	handleBridgeDown);
	addMesh(MIC_HANDLE,		handle);
	addMesh(MIC_HANDLE_TOP,	handleTop);
	addMesh(MIC_HEAD,		head);
	addMesh(MIC_HEAD_FRONT,	headFront);
	addMesh(MIC_HEAD_BACK,	headBack);
	addMesh(MIC_CORE,		core);

	Transform();
	vertices.shrink_to_fit();
	edges.shrink_to_fit();
	polygons.shrink_to_fit();

//	flipNormals(0, polygons.size());
}
Пример #28
0
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
	std::srand(static_cast<unsigned int>(std::time(NULL)));

	// Define some constants

	const int gameWidth = 800;
	const int gameHeight = 600;
	const int runSpeed = 200;
	const int gravity = 200;

	sf::Sprite backgroundSprite;
	sf::Texture backgroundTexture;
	backgroundTexture.loadFromFile("background.png");
	backgroundSprite.setTexture(backgroundTexture);



	// Create the window of the application
	sf::RenderWindow window(sf::VideoMode(gameWidth, gameHeight, 32), "Zooki");
	window.setVerticalSyncEnabled(true);


	// Create items
	Zooki zooki;
	Igloo igloo;
	Cone cone;
	TitleScreen titleScreen;

	titleScreen.setText();


	//HardCode Level. Will be replaced with loading a level////////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Loading ice texture
	sf::Texture iceTexture;
	iceTexture.loadFromFile("ice.jpg");
	// Creating a vector because we have more blocks and we will need them into a container
	std::vector<sf::Sprite> ice;
	// Add ice blocks to the container
	ice.resize(8);
	for (std::size_t i = 0; i<7; ++i)
	{
		ice[i].setTexture(iceTexture);
		ice[i].setPosition(128 * i, 450);
	}
	// Last ice block will bo above the first one
	ice[7].setTexture(iceTexture);
	ice[7].setPosition(0, 350);

	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	// Define the paddles properties
	sf::Clock AITimer;
	const sf::Time AITime = sf::seconds(0.1f);
	const float paddleSpeed = 400.f;
	float rightPaddleSpeed = 0.f;


	sf::Clock clock;
	bool isPlaying = false;
	while (window.isOpen())
	{
		// Handle events
		sf::Event event;
		while (window.pollEvent(event))
		{
			// Window closed or escape key pressed: exit
			if ((event.type == sf::Event::Closed) ||
				((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
			{
				window.close();
				break;
			}

			// Space key pressed: play
			if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Space))
			{
				if (!isPlaying)
				{
					// (re)start the game
					isPlaying = true;
					clock.restart();

					// Reset position of zooki
					zooki.resetPos(22.5, 200);
					zooki.Update();
					zooki.has_cones = false;
					zooki.onGround = false;
					cone.collected = false;					
				}
			}
		}

		if (isPlaying)
		{
			float deltaTime = clock.restart().asSeconds();

			// Move Zooki

			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
			{
				zooki.moveLeft(deltaTime,runSpeed);
			}
			else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
			{
				zooki.moveRight(deltaTime,runSpeed);
			}
			else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
			{
				zooki.jump();
			}
			else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
			{
				zooki.slide();
			}

			if (zooki.onGround == false)
			{
				zooki.fall(deltaTime, gravity);
			}

			zooki.Update();
			igloo.Update();
			cone.Update();



			//check if touching igloo
			sf::FloatRect area;
			if (zooki.zookiSprite.getGlobalBounds().intersects(igloo.iglooSprite.getGlobalBounds(), area))
			{
				if (zooki.has_cones)
				{
					isPlaying = false;
				}
				
			}

			//check if touching cone
			sf::FloatRect area2;
			if (zooki.zookiSprite.getGlobalBounds().intersects(cone.coneSprite.getGlobalBounds(), area))
			{
				zooki.gotCone();
				cone.collected = true;
			}

			//check if touching ground
			zooki.onGround = false;
			for (std::size_t i = 0; i<ice.size(); ++i)
			{
				// Affected area
				sf::FloatRect area;
				if (zooki.zookiSprite.getGlobalBounds().intersects(ice[i].getGlobalBounds(), area))
				{
					// Verifying if we need to apply collision to the vertical axis, else we apply to horizontal axis
					if (area.width > area.height)
					{
						if (area.contains({ area.left, zooki.zookiSprite.getPosition().y }))
						{
							// Up side crash
							zooki.zookiSprite.setPosition({ zooki.zookiSprite.getPosition().x, zooki.zookiSprite.getPosition().y + area.height });
						}
						else
						{
							// Down side crash
							zooki.onGround = true;
							zooki.zookiSprite.setPosition({ zooki.zookiSprite.getPosition().x, zooki.zookiSprite.getPosition().y - area.height });
						}
					}
					//else if (area.width < area.height) //weird bug where you can't go back left, need to debug
					//{
					//	if (area.contains({ zooki.zookiSprite.getPosition().x + zooki.zookiSprite.getGlobalBounds().width - 1.f, area.top + 1.f }))
					//	{
					//		//Right side crash
					//		zooki.zookiSprite.setPosition({ zooki.zookiSprite.getPosition().x - area.width, zooki.zookiSprite.getPosition().y });
					//	}
					//	else
					//	{
					//		//Left side crash
					//		zooki.zookiSprite.setPosition({ zooki.zookiSprite.getPosition().x + area.width, zooki.zookiSprite.getPosition().y });
					//	}
					//}
				}
			}




		}

		// Clear the window
		window.clear(sf::Color::Blue);

		if (isPlaying)
		{
			window.draw(backgroundSprite);
			
			for (std::size_t i = 0; i<ice.size(); ++i)
			{
				window.draw(ice[i]);
			}
			window.draw(zooki.zookiSprite);
			window.draw(igloo.iglooSprite);
			if (!cone.collected)
			{
				window.draw(cone.coneSprite);
			}
			
		}
		else{
			window.clear(sf::Color::Green);
			window.draw(titleScreen.title);
			window.draw(titleScreen.play);


		}


		// Display things on screen
		window.display();

	}

	return EXIT_SUCCESS;
}
Пример #29
0
// copy constructor
Cone::Cone(Cone const & other) {
    type_ = other.type();
    options_ = other.options()->clone();
}
Пример #30
0
Float RotateGameObject(Script * script)
{
	if (script->VerifyArguments(3) == true)
	{
		Word * rotatePosWord = script->GetNextWord();
		Point2D rotatePosition(0, 0);
		Point2D * rotatePos = (Point2D *)(uint32)rotatePosWord->value;
		if (rotatePos != NULL)
		{
			rotatePosition.SetValues(rotatePos->GetX(), rotatePos->GetY());
		}

		Word * angleWord = script->GetNextWord();

		Word * directionWord = script->GetNextWord();
		Vector3D direction(0, 0, 0);
		Point2D * dirVector = (Point2D *)(uint32)directionWord->value;
		if (dirVector != NULL)
		{
			direction.SetValues(dirVector->GetX(), dirVector->GetY(), 0);
		}

		GameObject * source = (GameObject *)script->GetSource();
		Shape * shape = source->GetShape();
		
		if ((rotatePos != NULL) && (source != NULL) && (source->CheckType(OBJ_TYPE_GAME_OBJECT) == true) && (shape != NULL))
		{
			Float distance = CalculateDistance(rotatePosition, source->GetPosition());
			if (angleWord->value != NULL)
			{
				Vector3D sourceDirection(rotatePosition, source->GetPosition());
				Float angle = sourceDirection.GetZeroAngleD() + angleWord->value;
				
				source->SetPosition(rotatePosition.GetX() + (distance * CosD(angle)),
									rotatePosition.GetY() + (distance * SinD(angle)));

				direction.SetValues(rotatePosition, source->GetPosition());
				direction.SetUnitVector();
			}
			else if (dirVector != NULL)
			{
				direction -= rotatePosition;
				direction.SetUnitVector();

				source->SetPosition(rotatePosition.GetX() + (direction.GetX() * distance),
									rotatePosition.GetY() + (direction.GetY() * distance));
			}
			else
			{
				return false;
			}

			if ((shape->GetType() == SHAPE_TYPE_LINE) || (shape->GetType() == SHAPE_TYPE_LINE_SEGMENT))
			{
				Line * line = (Line *)shape;
				Line * newLine = (Line *)line->CreateInstance();
				newLine->Translate(source->GetPosition());	

				Vector3D v1(rotatePosition, newLine->GetPoint1());
				Vector3D v2(rotatePosition, newLine->GetPoint2());

				Float baseAngle = direction.GetZeroAngleD();

				Float v1Length = v1.GetLength();
				Float v2Length = v2.GetLength();
				Float angle1 = v1.GetZeroAngleD() - baseAngle;
				Float angle2 = v2.GetZeroAngleD() - baseAngle;

				Point2D p1((v1Length * CosD(angle1)),
						   (v1Length * SinD(angle1)));
				Point2D p2((v2Length * CosD(angle2)),
						   (v2Length * SinD(angle2)));

				line->SetValues(p1 + rotatePosition, p2 + rotatePosition);

				line->Translate(!source->GetPosition());

				delete newLine;
			}
			else if (shape->GetType() == SHAPE_TYPE_CONE)
			{
				Cone * cone = (Cone *)shape;
				cone->SetValues(cone->GetVertex(), Vector3D(dirVector->GetX(), dirVector->GetY(), 0), cone->GetHeight(), cone->GetAngle());
			}
			return true;
		}
	}
	return false;
}