Esempio n. 1
0
int main() {
   /* Debugging Code */ 
   //double minX = 0.05859357, maxX = 0.44921857;
   //double minY = 2.03125, maxY = 2.421875;
   //int width = 20, height = 20;

   double minX = -10, maxX = 10, minY = -7.5, maxY = 7.5;
   int width = 512, height = 384;
   Canvas canvas;
   InitCanvas(&canvas, minX, maxX, minY, maxY, width, height);

   Point eye = CreatePoint(0.0, 0.0, -14.0);
   Point blueSphere = CreatePoint(1.0, 1.0, 0.0);
   Point redSphere = CreatePoint(0.5, 1.5, -3.0);
   Point lightPoint = CreatePoint(-100.0, 100.0, -100.0);

   Color blue = CreateColor(0.0, 0.0, 1.0);
   Color red = CreateColor(1.0, 0.0, 0.0);
   Color ambient = CreateColor(1.0, 1.0, 1.0);
   Color lightColor = CreateColor(1.5, 1.5, 1.5);
   
   Finish largeFinish = CreateFinish(0.2, 0.4, 0.5, 0.05);
   Finish smallFinish = CreateFinish(0.4, 0.4, 0.5, 0.05);

   Light light = CreateLight(lightPoint, lightColor);
   Sphere spheres[2];
   spheres[0] = CreateSphere(blueSphere, 2.0, blue, largeFinish);
   spheres[1] = CreateSphere(redSphere, 0.5, red, smallFinish);
   
   castAllRays(&canvas, eye, spheres, ambient, light, 2);
   return 0;
}
Esempio n. 2
0
void distanceTest2() {
   Point p1 = CreatePoint(12.5, 65.3, 102);
   Point p2 = CreatePoint(1, 2, 3);
   printf("\n**Distance Test 2**\n");
   double result = distance(p1, p2);
   printf("Actual: %lf\n", result);
   printf("Expected: 118.06837\n");
}
Esempio n. 3
0
void distanceTest1() {
   Point p1 = CreatePoint(-7.0, -4.0, 3.0);
   Point p2 = CreatePoint(17.0, 6.0, 2.5);

   printf("**Distance Test 1**\n");
   double result = distance(p1, p2);
   printf("Actual: %lf\n", result);
   printf("Expected: 26.004807\n");
}
Esempio n. 4
0
Line CutSquareInHalf(Square s1, Square s2)
{
	Point middle1, middle2;
	Line l;
	middle1=CreatePoint((s1.BottomLeft.x+s1.TopRight.x)/2, (s1.BottomLeft.y+s1.TopRight.y)/2);
	middle2=CreatePoint((s2.BottomLeft.x+s2.TopRight.x)/2, (s2.BottomLeft.y+s2.TopRight.y)/2);
    l=CreateLine(middle1, middle2);
    return l;
}
Esempio n. 5
0
void closestPoint1() {
   Point origin = CreatePoint(0, 0, 0);
   Point p1 = CreatePoint(5, 5, 5);
   Point p2 = CreatePoint(1, 1, 1);
  
   double p1Dist = distance(origin, p1);
   double p2Dist = distance(origin, p2);

   printf("\n**Finding Closest Point 1**\n");
   printf("Expected: p2Dist should be closer/smaller.\n");
   printf("Actual distance: p1 - %lf, p2 - %lf\n", p1Dist, p2Dist);
}
Esempio n. 6
0
void closestPoint2() {
   Point origin = CreatePoint(0, 0, -14);
   Point p1 = CreatePoint(2, 5, 2); //16.88
   Point p2 = CreatePoint(1, 6, 1); //16.18

   double p1Dist = distance(origin, p1);
   double p2Dist = distance(origin, p2);
   
   printf("\n**Finding Closest Point 2**\n");
   printf("Expected: p2Dist should be closer/smaller.\n");
   printf("Actual distance: p1 - %lf, p2 - %lf\n", p1Dist, p2Dist);
}
Esempio n. 7
0
void closestPoint3() {
   Point origin = CreatePoint(0, 0, -14);
   Point p1 = CreatePoint(-1.2, 4.5, 2.3);
   Point p2 = CreatePoint(-1.2, 2.3, 5.6);

   double p1Dist = distance(origin, p1);
   double p2Dist = distance(origin, p2);

   printf("\n**Finding Closest Point 3**\n");
   printf("Expected p1Dist should be closer/smaller.\n");
   printf("Actual distance: p1 - %lf, p2 - %lf\n", p1Dist, p2Dist);
}
void CLogoMarkerSymbol::QueryBoundsFromGeom(OLE_HANDLE hdc, IDisplayTransformationPtr ipTransform, 
	IPolygonPtr ipBoundary, IPointPtr ipPoint)
{
  //Calculate Size, XOffset and YOffset of the shape in Map units.
	double dMapSize, dMapXOffset, dMapYOffset;
	dMapSize = PointsToMap(ipTransform, m_dSize);
  
	if (qaDoubleCompare(m_dXOffset, 0.0))
		dMapXOffset = PointsToMap(ipTransform, m_dXOffset);

  if (qaDoubleCompare(m_dYOffset, 0.0))
		dMapYOffset = PointsToMap(ipTransform, m_dYOffset);
	
	double dX, dY;
	ipPoint->get_X(&dX);
	ipPoint->get_Y(&dY);
	ipPoint->PutCoords(dX + dMapXOffset, dY + dMapYOffset);

  //Set up the device ratio.
  SetupDeviceRatio((HDC)hdc, (IDisplayTransformationPtr)ipTransform);
	IPointCollectionPtr ipPtColl(ipBoundary);
	ISegmentCollectionPtr ipSegColl(ipBoundary);
	double dVal, dRad; //dVal is the measurement of the short side of a Triangles are based on.
  dRad = dMapSize / 2.0;
  dVal = sqrt((dRad * dRad / 2.0));
	ipPoint->get_X(&dX);
	ipPoint->get_Y(&dY);
	IPointPtr ipPt;
	CreatePoint((IPointPtr*)&ipPt, dX + dVal, dY - dVal);
  ipPtColl->AddPoint(ipPt);
	CreatePoint((IPointPtr*)&ipPt, dX - dVal, dY - dVal);
  ipPtColl->AddPoint(ipPt);
	CreatePoint((IPointPtr*)&ipPt, dX - dVal, dY + dVal);
  ipPtColl->AddPoint(ipPt);
	ICircularArcPtr ipCArc;
	IPointPtr ipFPt, ipTPt;
	ipPtColl->get_Point(2, &ipFPt);
	ipPtColl->get_Point(0, &ipTPt);
	CreateCArcCenterFromTo((ICircularArcPtr*)&ipCArc, ipPoint, ipFPt, ipTPt);
  ipSegColl->AddSegment((ISegmentSamplePtr)ipCArc);

  //Account for rotation also.
  if (qaDoubleCompare(m_dAngle, 0.0))
	{
		ITransform2DPtr ipTrans2D(ipBoundary);
    ipTrans2D->Rotate(ipPoint, Radians(m_dAngle));
  }
}
Esempio n. 9
0
Sphere* CreateSpheres() {
	Sphere* spheres = new Sphere[NUM_SPHERES]();
   int i=0, j=0, k=0, num=0;

   while (num < NUM_SPHERES) {
      for (i=0; i < 6 && num < NUM_SPHERES; i++) {
         for (j=0; j < 5 && num < NUM_SPHERES; j++) {
            spheres[num].radius = 30. - rand() % 10;
            spheres[num].center = CreatePoint(j * 80. - 80. + rand() % 15,
                                              i * 80. - 200. + rand() % 15,
                                              -700. - k * 100 + rand() % 15);
            spheres[num].ambient = CreateColor(std::min((i + j) * .15, 1.),
                                               std::min((j + k) * .15, 1.),
                                               std::max(1. - (k + i) * .15, 0.));
            spheres[num].diffuse = CreateColor(std::min((i + j) * .15, 1.),
                                               std::min((j + k) * .15, 1.),
                                               std::max(1. - (k + i) * .15, 0.));
            spheres[num].specular = CreateColor(1., 1., 1.);
            num++;
         }
      }
      k++;
   }

	return spheres;
}
Esempio n. 10
0
void CInMapDraw::MousePress(int x, int y, int button)
{
	float3 pos=GetMouseMapPos();
	if(pos.x<0)
		return;

	switch(button){
	case SDL_BUTTON_LEFT:
		if(lastLeftClickTime>gu->gameTime-0.3){
			waitingPoint=pos;
			game->userWriting=true;
			wantLabel=true;
			game->userPrompt="Label: ";
			game->ignoreChar='\xA7';		//should do something better here
		}
		lastLeftClickTime=gu->gameTime;
		break;
	case SDL_BUTTON_RIGHT:
		ErasePos(pos);
		break;
	case SDL_BUTTON_MIDDLE:{
		CreatePoint(pos,"");
		break;}
	}
	lastPos=pos;
}
Esempio n. 11
0
OrderedTaskPoint*
AbstractTaskFactory::CreateMutatedPoint(const OrderedTaskPoint &tp,
                                        const TaskPointFactoryType newtype) const
{
  auto ozsize = GetOZSize(tp.GetObservationZone());
  return CreatePoint(newtype, tp.GetWaypoint(), ozsize, ozsize, ozsize);
}
Esempio n. 12
0
struct Cluster AddIndex(struct Cluster Cluster, int i)
{
	struct Indexes *Index;
	struct Indexes *root;
	root = Cluster.root;
	if(!(root))
		Cluster.root = CreatePoint(i);
	else
	{
		Index = CreatePoint(i);
		while(GoNext(root))
			root = GoNext(root);
		root->Next_Point = Index;
	}
	return Cluster;
}
Esempio n. 13
0
void Draw_Dxf::addPoint(const DL_PointData& data)
{

    RGBA color = RGBA(150,150,150);

    Shape* p = CreatePoint(_painter,RGBA(200,0,0),(FLOAT)data.x,(FLOAT)data.y);
    p->regen();

    TCHAR* layerName;

    if(_isBlockOpen) _block->insert(p);
    else {
        switch(_entityType) {
        case NONE :
            for(UINT i=0; i<_layers->size(); i++) {
                layerName = _layers->at(i)->getName();
                if(0 == _tcscmp(layerName,String2TCHAR(attributes.getLayer()))) {
                    _layers->at(i)->insert(p);
                    _layers->at(i)->getLineColor(color);
                    break;
                }
            }
            break;
        }
    }

    INT32 clValue = attributes.getColor();
    if(clValue != 256) color = CL2RGBA(clValue);
    p->setLineColor(color);

}
Esempio n. 14
0
//Draws the specified texture
//param:texture->the index given from load texture
//param:color->the tint to apply to the texture
//param:sourceRect->the rectangle to pull a smaller image from the texture with. NULL for the whole texture
//param:position->the point to draw to
//param:angle->the rotation to apply
//param:scale->the scale to apply. This is uniform across x and y
//param:flip->SDL_RendererFlip::None/FlipHorizontal/FlipVertical. If you want both Flip Horizontal and Flip Vertical,
//use the bitwise operator '|'
//param:origin->Origin to rotate around. If NULL, uses center of destRect created by position and scale
//param:layerDepth->The depth to draw the image at
//returns -1 on error, 0 for success
int SpriteBatch::DrawTexture(Uint32 texture, SDL_Color color, const SDL_Rect* sourceRect, const SDL_Point* position,
		float angle, float scale, SDL_RendererFlip flip, const SDL_Point* origin, float layerDepth)
{
	//Check if spritebatch.begin has been called
	if(!begun)
	{
		std::cout<<"Begin must be called before attempting to draw"<<std::endl;
		return -1;
	}

	///create a temporary point
	SDL_Point pos = SDL_Point();

	//if position is null, set our temp to 0,0
	if(!position)
	{
		pos = CreatePoint(0, 0);
	}
	else
	{
		//otherwise set with position
		pos = CreatePoint(position->x, position->y);
	}

	SDL_Rect destRect = SDL_Rect();

	//If we were given a source rectangle
	if(sourceRect)
	{
		//create a dest rectangle using position and source rectangle's dimensions
		destRect = CreateRect(pos.x, pos.y, (int)(sourceRect->w * scale), (int)(sourceRect->h * scale));
	}
	else
	{
		int w = 0;
		int h = 0;

		//get the width and height
		SDL_QueryTexture(textureList[texture], NULL, NULL, &w, &h);
		//create a dest rect using position and the image dimensions
		destRect = CreateRect(pos.x, pos.y, (int)(w * scale), (int)(h * scale));
	}

	//Call other DrawTexture to do the actual drawing
	return DrawTexture(texture, color, sourceRect, &destRect, angle, origin, flip, layerDepth);
}
Esempio n. 15
0
//start the game
void InitialiseGame() {
	srand(ReadTimer());
	mode=1;
	score=0;
	InitialiseWorld();
	refreshCount=0;
	resetCount=50;
	behaviourCount=0;
	ResetArrow();
	arrowRefAngle=0;
	cameraPos=CreatePoint(0.0,5.0,0.0);
	cameraAngle=CreatePoint(0.0,0.0,0.0);
	blocked=0;
	lives=3;

	DrawHUD();
}
Esempio n. 16
0
CParticle* CBody::MakeChain(int count, int radius, float r, float angle){
  if(count<2)return nullptr; //fail and bail

  //make space for particles and springs 
  m_nParticleCount = m_nParticleMax = count;
  m_pPt = new CParticle* [m_nParticleMax];
  m_nSpringCount = m_nSpringMax = count-1;
  m_pCtr = new CParticle* [m_nSpringMax];
  m_pSpring = new CSpring* [m_nSpringMax];

  //decide whether to draw springs or sticks
  SpriteType nVertexObject, nEdgeObject;
  ChooseSprites(nVertexObject, nEdgeObject, r);

  //x and y offsets between balls
  const float dx = 2.0f*radius*cos(angle); 
  const float dy = 2.0f*radius*sin(angle);

  //position for first ball
  Vector2 v = Vector2(
    g_nScreenWidth/2.0f - (count-1)*radius, //center chain on screen
    g_nScreenHeight/2.0f);  

  //first ball and spring
  CreateEdgeCenter(0, nEdgeObject);
  CreatePoint(0, nVertexObject, v);

  for(int i=1; i<count-1; i++){ //for the rest of the springs
    //add a ball and a spring, connect previous spring
    CreateEdgeCenter(i, nEdgeObject);
    v.x += dx; v.y += dy; //offset position
    CreatePoint(i, nVertexObject, v);
    ConnectSpring(i-1, i, i-1, r);
  } //for

  //last ball
  v.x += dx; v.y += dy;
  m_pPt[count-1] = m_pPMan->create(nVertexObject, v); 
  ConnectSpring(count-2, count-1, count-2, r);

  //clean up
  m_pEdgeParticle = m_pPt[0];
  delete [] m_pCtr;
  return m_pPt[0];
} //MakeChain
Esempio n. 17
0
FinishPoint* 
AbstractTaskFactory::CreateFinish(const TaskPointFactoryType type,
                                  const Waypoint &wp) const
{
  if (!IsValidFinishType(type))
    return NULL;

  return (FinishPoint*)CreatePoint(type, wp);
}
Esempio n. 18
0
IntermediateTaskPoint* 
AbstractTaskFactory::CreateIntermediate(const TaskPointFactoryType type,
                                        const Waypoint &wp) const
{
  if (!IsValidIntermediateType(type))
    return NULL;

  return (IntermediateTaskPoint*)CreatePoint(type, wp);
}
Esempio n. 19
0
//Splash screen
void Splash() {
	ResetTimer(); //we're going to use it for random seed
	//Setup a world with a tank and a pyramid in specific places
	CloseGraphics();
	OpenGraphics();

	Point3d centre;
	world=CreateNewWorld();

	//A tank pointing straight at us
	centre=CreatePoint(0.0,0.0,45.0);
	obj=CreateTank(GREEN, centre, 4.5);
	RotateObjectYAxis(&obj, 2.0 * PI / 360.0 * 195);
	AddObjectToWorld(&world, obj);

	//A yellow pyramid behind the tank and to the right
	centre=CreatePoint(10.0, 0.0, 70.0);
	obj=CreatePyramid(YELLOW, centre, 5.0);
	RotateObjectYAxis(&obj, 3.0*PI/5.0);
	AddObjectToWorld(&world, obj);

	//A blue cube behind the tank and to the left
	centre=CreatePoint(-10.0, 0.0, 60.0);
	obj=CreateCube(BLUE, centre, 5.0);
	RotateObjectYAxis(&obj, 195.0*PI/180.0);
	AddObjectToWorld(&world,obj);

	//Draw world, add splash graphics, prompt to start
	cameraPos=CreatePoint(0.0,5.0,0.0);
	cameraAngle=CreatePoint(0.0,0.0,0.0);
	DrawWorld(&world, cameraPos, cameraAngle);
	SetTextColor(GREEN);
	DrawText(5,25, "by RorschachUK");

	SetTextColor(CYAN);
	DrawText(5,100, "Help");
	DrawText(110,100,"Start");
	DrawImage(logoImage, 5,5,RGBColor(253,255,252,0));
	DrawImage(signatureImage, 135,24,BLACK);

	Show();
	Sleep(100);
	mode=0;
}
Esempio n. 20
0
StartPoint* 
AbstractTaskFactory::CreateStart(const TaskPointFactoryType type,
                                 const Waypoint &wp) const
{
  if (!IsValidStartType(type))
    // error, invalid type!
    return NULL;

  return (StartPoint*)CreatePoint(type, wp);
}
Esempio n. 21
0
CParticle* CBody::MakeWheel(int sides, int radius, float r){

  //make space for particles and springs 
  m_nParticleCount = m_nParticleMax = sides+1;
  m_pPt = new CParticle* [m_nParticleMax];
  m_nSpringCount = m_nSpringMax = 2*sides;
  m_pCtr = new CParticle* [m_nSpringMax];
  m_pSpring = new CSpring* [m_nSpringMax];

  //decide whether to draw springs or sticks
  SpriteType nVertexObject, nEdgeObject;
  ChooseSprites(nVertexObject, nEdgeObject, r);

  Vector2 v = Vector2( //position
    g_nScreenWidth/2.0f,  g_nScreenHeight/2.0f + radius/2.0f); 

  //springs
  for(int i=0; i<2*sides; i++)
    CreateEdgeCenter(i, nEdgeObject);

  v = Vector2( //position
    g_nScreenWidth/2.0f,  g_nScreenHeight/2.0f + radius/2.0f);

  //balls
  CreatePoint(0, nVertexObject, v);
  for(int i=0; i<sides; i++){
    float theta = i * 2.0f * XM_PI/sides;
    Vector2 vBall = Vector2(v.x + radius*cos(theta), v.y + radius*sin(theta));    
    CreatePoint(i+1, nVertexObject, vBall);
  } //for

  //springs
  for(int i=0; i<sides; i++){
    ConnectSpring(0, i+1, i, r); //spoke
    ConnectSpring(i, i+1, sides+i-1, r); //rim
  } //for
  ConnectSpring(sides, 1, 2*sides-1, r); //rim
  
  //clean up
  delete [] m_pCtr;
  m_pEdgeParticle = m_pPt[1];
  return m_pPt[1];
} //MakeWheel
Esempio n. 22
0
void main()
{
	Point al, ar, bl, br;
	Square s1, s2;
	Line l;
	//printf("hello");

	al=CreatePoint(2, 2);
	ar=CreatePoint(4, 4);
	bl=CreatePoint(-4, 0);
	br=CreatePoint(-2, 2);
	
	s1=CreateSquare(al, ar);
	s2=CreateSquare(bl, br);

	l=CutSquareInHalf(s1, s2);
	printf("Line is %lfx + %lf = y\n", l.slope, l.y_intercept);

}
Esempio n. 23
0
PointLight* LightInit() {
   PointLight* temp = new PointLight();

   temp->ambient = CreateColor(0.2, 0.2, 0.2);
   temp->diffuse = CreateColor(0.6, 0.6, 0.6);
   temp->specular = CreateColor(0.9, 0.9, 0.9);

   //temp->position = CreatePoint(0, 200, 0);
   temp->position = CreatePoint(-1 * WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, -1 * WINDOW_WIDTH / 2);

   return temp;
}
Esempio n. 24
0
//Place the tank somewhere suitable - not too easy, not too close, not too far away, not straight ahead
void PlaceTank(Point3d cameraPosition, Point3d cameraAngle) {
	world.objects[tankObjectIndex]=tank;
	RotateObjectYAxis(&(world.objects[tankObjectIndex]), Random(-PI/2.0, PI/2.0));
	double distance = Random(50.0, 100.0);	//At least 50 from us, at most 100
	double angle = Random(45.0 / 360.0 * 2 * PI, 315.0 / 360.0 * 2.0 * PI);	//45-315 degrees
	Point3d tankPos = CreatePoint(cameraPosition.x + distance * qsin(angle + cameraAngle.y), 0, cameraPosition.z + distance * qcos(angle + cameraAngle.y));
	MoveObject(&(world.objects[tankObjectIndex]), tankPos);
	if (world.objects[tankObjectIndex].centre.z<0) {
		//behind us - face away
		RotateObjectYAxis(&(world.objects[tankObjectIndex]),PI);
	}
}
Esempio n. 25
0
CParticle* CBody::MakeSquare(int radius, float r){
  //make space for particles and springs 
  m_nParticleCount = m_nParticleMax = 4;
  m_pPt = new CParticle* [m_nParticleMax];
  m_nSpringCount = m_nSpringMax = 6;
  m_pCtr = new CParticle* [m_nSpringMax];
  m_pSpring = new CSpring* [m_nSpringMax];
  
 
  //decide whether to draw springs or sticks
  SpriteType nVertexObject, nEdgeObject;
  ChooseSprites(nVertexObject, nEdgeObject, r);

  Vector2 v = Vector2( //position
    g_nScreenWidth/2.0f - radius,  g_nScreenHeight/2.0f + radius); 

  //edge objects
  for(int i=0; i<6; i++)
    CreateEdgeCenter(i, nEdgeObject);

  //balls
  CreatePoint(0, nVertexObject, v);
  v.x += 2*radius; CreatePoint(1, nVertexObject, v);
  v.y -= 2*radius; CreatePoint(2, nVertexObject, v);
  v.x -= 2*radius; CreatePoint(3, nVertexObject, v);
  
  //tie springs to balls
  ConnectSpring(0, 1, 0, r); 
  ConnectSpring(1, 2, 1, r); 
  ConnectSpring(2, 3, 2, r); 
  ConnectSpring(3, 0, 3, r); 
  ConnectSpring(0, 2, 4, r); 
  ConnectSpring(1, 3, 5, r);
  
  //clean up
  delete [] m_pCtr;
  m_pEdgeParticle = m_pPt[0];
  return m_pPt[0];
} //MakeSquare
Esempio n. 26
0
CParticle* CBody::MakeTriangle(int radius, float r){ 
  //make space for particles and springs 
  m_nParticleCount = m_nParticleMax = 3;
  m_pPt = new CParticle* [m_nParticleMax];
  m_nSpringCount = m_nSpringMax = 3;
  m_pCtr = new CParticle* [m_nSpringMax];
  m_pSpring = new CSpring* [m_nSpringMax];
  
  //decide whether to draw springs or sticks
  SpriteType nVertexObject, nEdgeObject;
  ChooseSprites(nVertexObject, nEdgeObject, r);

  Vector2 v = Vector2( //default position
    g_nScreenWidth/2.0f,  g_nScreenHeight/2.0f + radius); 

  //edge objects
  for(int i=0; i<3; i++)
    CreateEdgeCenter(i, nEdgeObject);

  //balls
  CreatePoint(0, nVertexObject, v);
  v.x +=  radius;
  v.y -= radius * tan(XM_PI/3.0f);
  CreatePoint(1, nVertexObject, v);
  v.x -= 2.0f * radius;
  CreatePoint(2, nVertexObject, v);
  
  //tie springs to balls
  ConnectSpring(0, 1, 0, r); 
  ConnectSpring(1, 2, 1, r); 
  ConnectSpring(2, 0, 2, r); 

  //clean up
  m_pEdgeParticle = m_pPt[0];
  delete [] m_pCtr;
  return m_pPt[0];
} //MakeTriangle
//Gets the size of the message when used with the specified font
//param:fontIndex->The index of the font to use
//param:message->The message to measure
//returns a pointer to an SDL_Point object. REMEMBER TO DELETE WHEN FINISHED
SDL_Point SpriteFont::GetMessageSize(int fontIndex, std::string message)
{
	//Check message size
	if(message.size() <= 0)
	{
		std::cout<<"GetMessageSize error: No message to measure"<<std::endl;
		return CreatePoint(0, 0);
	}

	//Try block to make sure index is valid
	try
	{
		//Get the font to measure
		TTF_Font* font = fontList.at(fontIndex);

		//Make sure its not null
		if(font)
		{			
			SDL_Point returnPoint = SDL_Point();
			//Size up the message
			TTF_SizeText(font, message.c_str(), &returnPoint.x, &returnPoint.y);

			return returnPoint;
		}
		else
		{
			std::cout<<"GetMessageSize error: Provided index is NULL"<<std::endl;
			return CreatePoint(0, 0);
		}
	}
	catch(std::out_of_range problem)
	{
		//display invalid index
		std::cout<<"GetMessageSize error: font index invalid"<<std::endl;
		return CreatePoint(0, 0);
	}
}
Esempio n. 28
0
Camera* CameraInit() {
   
   Camera* temp = new Camera();
   temp->eye = CreatePoint(0, 0, 0);
   temp->lookAt = CreatePoint(0, 0, SCREEN_DISTANCE);
   temp->lookUp = CreatePoint(0, 1, 0);

   temp->u = CreatePoint(1, 0, 0);
   temp->v = CreatePoint(0, 1, 0);
   temp->w = CreatePoint(0, 0, 1);
   
   return temp;
}
void MenuButton::Draw() {
	int heightOffset = 4; // without offset, font is a little to high

	// draw the background rectangle
	spriteBatch->DrawFilledRect(
		&CreateRect(x, y, width, height),
		bg
	);

	// draw the text
	spriteBatch->DrawString(
		font,
		text,
		StringDrawMode::Solid,
		fg,
		CreateColor(0, 0, 0, 255),
		width,
		&CreatePoint(x + width / 2 - spriteFont->GetMessageSize(0, text).x / 2, y + heightOffset + height / 2 - spriteFont->GetMessageSize(0, text).y / 2)
	);
}
Esempio n. 30
0
void ParseCommands(const std::vector<std::vector<std::string>>& commands, std::vector<std::shared_ptr<CShape>>& figures, std::vector<std::shared_ptr<sf::Shape>>& drawableFigures)
{
	for (const auto& command : commands)
	{
		try
		{
			std::cout << "> Parsing:" << std::endl;
			std::copy(command.begin(), command.end(), std::ostream_iterator<std::string>(std::cout, " "));
			std::cout << std::endl;
			if (command[0] == "rectangle")
			{
				CreateRectangle(command, figures, drawableFigures);
			}
			else if (command[0] == "circle")
			{
				CreateCircle(command, figures, drawableFigures);
			}
			else if (command[0] == "line")
			{
				CreateLine(command, figures, drawableFigures);
			}
			else if (command[0] == "triangle")
			{
				CreateTriangle(command, figures, drawableFigures);
			}
			else if (command[0] == "point")
			{
				CreatePoint(command, figures, drawableFigures);
			}
			else
			{
				throw std::exception("\tError: Invalid command");
			}
		}
		catch (const std::exception& error)
		{
			std::cout << error.what() << std::endl;
		}
	}
}