コード例 #1
0
ファイル: validation.cpp プロジェクト: petersung21/Janggi
int validation::chooser(Tile *temp)
{
    switch(temp->pieceName)
    {

    case 'R': flag=validateJa(temp);
              break;

    case 'H': flag=validateJang(temp);
              break;

    case 'K': flag=validateWang(temp);
              break;

    case 'Q': flag=validateHoo(temp);
              break;

    case 'B': flag=validateSang(temp);
              break;

    }

    orange();

    return flag;
}
コード例 #2
0
ファイル: validation.cpp プロジェクト: hanemay/H-Chess
int validation::chooser(Tile *temp)
{
    switch(temp->pieceName)
    {
    case 'P': flag=validatePawn(temp);
              break;

    case 'R': flag=validateRook(temp);
              break;

    case 'H': flag=validateHorse(temp);
              break;

    case 'K':  flag=validateKing(temp);
                break;

    case 'Q': flag=validateQueen(temp);
              break;

    case 'B': flag=validateBishop(temp);
              break;

    }
    orange();
    return flag;
}
コード例 #3
0
ファイル: Main.cpp プロジェクト: bittailor/BtArduino
int main() {
   init();

//   Serial.begin(9600);

   uint8_t address = 1;

   Bt::Ui::Color red   (255,  0,  0);
   Bt::Ui::Color orange(238,154,  0);
   Bt::Ui::Color green (  0,255,  0);
   Bt::Ui::Color black (  0,  0,  0);

   Bt::Ui::Colorduino colorduino(1);
   colorduino.fill(red);
   colorduino.repaint();
   Bt::Ui::RgbScreenServer server(colorduino);
   colorduino.fill(orange);
   colorduino.repaint();

   Bt::Com::Twi twi;
   Bt::Com::TwoWireServer<Bt::Com::Twi> twiServer(twi,address,server);

   // show the address of this colorduino
   colorduino.fill(black);
   drawAddress(address,colorduino,green);
   colorduino.repaint();

   // colorduino and communication is interrupt driven
   while(true) {
      delay(100);
   }

   return 0;
}
コード例 #4
0
void 												
World::build(void) {
	int num_samples = 1; 
	
	// view plane  
	  
	vp.set_hres(400);
	vp.set_vres(400);
	vp.set_pixel_size(0.5);
	vp.set_samples(num_samples);
	
	// the ambient light here is the same as the default set in the World
	// constructor, and can therefore be left out
	
	Ambient* ambient_ptr = new Ambient;
	ambient_ptr->scale_radiance(1.0);
	set_ambient_light(ambient_ptr); 

	background_color = black;			// default color - this can be left out
	
	tracer_ptr = new RayCast(this); 

	
	// camera
	
	Pinhole* pinhole_ptr = new Pinhole;
	pinhole_ptr->set_eye(0, 0, 500); 
	pinhole_ptr->set_lookat(0.0);
	pinhole_ptr->set_view_distance(600.0);
	pinhole_ptr->compute_uvw();     
	set_camera(pinhole_ptr);

	
	// light
	
	Directional* light_ptr1 = new Directional;
	light_ptr1->set_direction(100, 100, 200);
	light_ptr1->scale_radiance(3.0); 	
	add_light(light_ptr1);
	
	
	// colors

	RGBColor yellow(1, 1, 0);										// yellow
	RGBColor brown(0.71, 0.40, 0.16);								// brown
	RGBColor darkGreen(0.0, 0.41, 0.41);							// darkGreen
	RGBColor orange(1, 0.75, 0);									// orange
	RGBColor green(0, 0.6, 0.3);									// green
	RGBColor lightGreen(0.65, 1, 0.30);								// light green
	RGBColor darkYellow(0.61, 0.61, 0);								// dark yellow
	RGBColor lightPurple(0.65, 0.3, 1);								// light purple
	RGBColor darkPurple(0.5, 0, 1);									// dark purple
	RGBColor grey(0.25);											// grey
	
	
	// Matte material reflection coefficients - common to all materials
	
	float ka = 0.25;
	float kd = 0.75;
	
	
	// spheres
	
	Matte* matte_ptr1 = new Matte;   
	matte_ptr1->set_ka(ka);	
	matte_ptr1->set_kd(kd);
	matte_ptr1->set_cd(yellow);				
	Sphere*	sphere_ptr1 = new Sphere(Point3D(5, 3, 0), 30); 
	sphere_ptr1->set_material(matte_ptr1);	   							// yellow
	add_object(sphere_ptr1);
	
	Matte* matte_ptr2 = new Matte;
	matte_ptr2->set_ka(ka);	
	matte_ptr2->set_kd(kd);
	matte_ptr2->set_cd(brown);
	Sphere*	sphere_ptr2 = new Sphere(Point3D(45, -7, -60), 20); 
	sphere_ptr2->set_material(matte_ptr2);								// brown
	add_object(sphere_ptr2);
	

	Matte* matte_ptr3 = new Matte;
	matte_ptr3->set_ka(ka);	
	matte_ptr3->set_kd(kd);
	matte_ptr3->set_cd(darkGreen);	
	Sphere*	sphere_ptr3 = new Sphere(Point3D(40, 43, -100), 17); 
	sphere_ptr3->set_material(matte_ptr3);								// dark green
	add_object(sphere_ptr3);
	
	Matte* matte_ptr4 = new Matte;
	matte_ptr4->set_ka(ka);	
	matte_ptr4->set_kd(kd);
	matte_ptr4->set_cd(orange);
	Sphere*	sphere_ptr4 = new Sphere(Point3D(-20, 28, -15), 20); 
	sphere_ptr4->set_material(matte_ptr4);								// orange
	add_object(sphere_ptr4);
	
	Matte* matte_ptr5 = new Matte;
	matte_ptr5->set_ka(ka);	
	matte_ptr5->set_kd(kd);
	matte_ptr5->set_cd(green);
	Sphere*	sphere_ptr5 = new Sphere(Point3D(-25, -7, -35), 27); 			
	sphere_ptr5->set_material(matte_ptr5);								// green
	add_object(sphere_ptr5);
	
	Matte* matte_ptr6 = new Matte;
	matte_ptr6->set_ka(ka);	
	matte_ptr6->set_kd(kd);
	matte_ptr6->set_cd(lightGreen);
	Sphere*	sphere_ptr6 = new Sphere(Point3D(20, -27, -35), 25); 
	sphere_ptr6->set_material(matte_ptr6);								// light green
	add_object(sphere_ptr6);
	
	Matte* matte_ptr7 = new Matte;
	matte_ptr7->set_ka(ka);	
	matte_ptr7->set_kd(kd);
	matte_ptr7->set_cd(green);
	Sphere*	sphere_ptr7 = new Sphere(Point3D(35, 18, -35), 22); 
	sphere_ptr7->set_material(matte_ptr7);   							// green
	add_object(sphere_ptr7);
	
	Matte* matte_ptr8 = new Matte;
	matte_ptr8->set_ka(ka);	
	matte_ptr8->set_kd(kd);
	matte_ptr8->set_cd(brown);
	Sphere*	sphere_ptr8 = new Sphere(Point3D(-57, -17, -50), 15);  
	sphere_ptr8->set_material(matte_ptr8);								// brown
	add_object(sphere_ptr8);
	
	Matte* matte_ptr9 = new Matte;
	matte_ptr9->set_ka(ka);	
	matte_ptr9->set_kd(kd);
	matte_ptr9->set_cd(lightGreen);
	Sphere*	sphere_ptr9 = new Sphere(Point3D(-47, 16, -80), 23); 
	sphere_ptr9->set_material(matte_ptr9);								// light green
	add_object(sphere_ptr9);
		
	Matte* matte_ptr10 = new Matte;
	matte_ptr10->set_ka(ka);	
	matte_ptr10->set_kd(kd);
	matte_ptr10->set_cd(darkGreen);	
	Sphere*	sphere_ptr10 = new Sphere(Point3D(-15, -32, -60), 22); 
	sphere_ptr10->set_material(matte_ptr10);     						// dark green
	add_object(sphere_ptr10);
	
	Matte* matte_ptr11 = new Matte;
	matte_ptr11->set_ka(ka);	
	matte_ptr11->set_kd(kd);
	matte_ptr11->set_cd(darkYellow);
	Sphere*	sphere_ptr11 = new Sphere(Point3D(-35, -37, -80), 22); 
	sphere_ptr11->set_material(matte_ptr11);							// dark yellow
	add_object(sphere_ptr11);
	
	Matte* matte_ptr12 = new Matte;
	matte_ptr12->set_ka(ka);	
	matte_ptr12->set_kd(kd);
	matte_ptr12->set_cd(darkYellow);
	Sphere*	sphere_ptr12 = new Sphere(Point3D(10, 43, -80), 22); 
	sphere_ptr12->set_material(matte_ptr12);							// dark yellow
	add_object(sphere_ptr12);
	
	Matte* matte_ptr13 = new Matte;
	matte_ptr13->set_ka(ka);	
	matte_ptr13->set_kd(kd);
	matte_ptr13->set_cd(darkYellow);		
	Sphere*	sphere_ptr13 = new Sphere(Point3D(30, -7, -80), 10); 
	sphere_ptr13->set_material(matte_ptr13);
	add_object(sphere_ptr13);											// dark yellow (hidden)
	
	Matte* matte_ptr14 = new Matte;
	matte_ptr14->set_ka(ka);	
	matte_ptr14->set_kd(kd);
	matte_ptr14->set_cd(darkGreen);	
	Sphere*	sphere_ptr14 = new Sphere(Point3D(-40, 48, -110), 18); 
	sphere_ptr14->set_material(matte_ptr14); 							// dark green
	add_object(sphere_ptr14);
	
	Matte* matte_ptr15 = new Matte;
	matte_ptr15->set_ka(ka);	
	matte_ptr15->set_kd(kd);
	matte_ptr15->set_cd(brown);	
	Sphere*	sphere_ptr15 = new Sphere(Point3D(-10, 53, -120), 18); 
	sphere_ptr15->set_material(matte_ptr15); 							// brown
	add_object(sphere_ptr15);
	
	Matte* matte_ptr16 = new Matte;
	matte_ptr16->set_ka(ka);	
	matte_ptr16->set_kd(kd);
	matte_ptr16->set_cd(lightPurple);
	Sphere*	sphere_ptr16 = new Sphere(Point3D(-55, -52, -100), 10); 
	sphere_ptr16->set_material(matte_ptr16);							// light purple
	add_object(sphere_ptr16);
	
	Matte* matte_ptr17 = new Matte;
	matte_ptr17->set_ka(ka);	
	matte_ptr17->set_kd(kd);
	matte_ptr17->set_cd(brown);
	Sphere*	sphere_ptr17 = new Sphere(Point3D(5, -52, -100), 15); 		
	sphere_ptr17->set_material(matte_ptr17);							// browm
	add_object(sphere_ptr17);
	
	Matte* matte_ptr18 = new Matte;
	matte_ptr18->set_ka(ka);	
	matte_ptr18->set_kd(kd);
	matte_ptr18->set_cd(darkPurple);
	Sphere*	sphere_ptr18 = new Sphere(Point3D(-20, -57, -120), 15); 
	sphere_ptr18->set_material(matte_ptr18);							// dark purple
	add_object(sphere_ptr18);
	
	Matte* matte_ptr19 = new Matte;
	matte_ptr19->set_ka(ka);	
	matte_ptr19->set_kd(kd);
	matte_ptr19->set_cd(darkGreen);
	Sphere*	sphere_ptr19 = new Sphere(Point3D(55, -27, -100), 17); 
	sphere_ptr19->set_material(matte_ptr19);							// dark green
	add_object(sphere_ptr19);

	Matte* matte_ptr20 = new Matte;
	matte_ptr20->set_ka(ka);	
	matte_ptr20->set_kd(kd);
	matte_ptr20->set_cd(brown);
	Sphere*	sphere_ptr20 = new Sphere(Point3D(50, -47, -120), 15); 
	sphere_ptr20->set_material(matte_ptr20);							// browm
	add_object(sphere_ptr20);
	 
	Matte* matte_ptr21 = new Matte;
	matte_ptr21->set_ka(ka);	
	matte_ptr21->set_kd(kd);
	matte_ptr21->set_cd(lightPurple); 	
	Sphere*	sphere_ptr21 = new Sphere(Point3D(70, -42, -150), 10); 
	sphere_ptr21->set_material(matte_ptr21);							// light purple
	add_object(sphere_ptr21);
	
	Matte* matte_ptr22 = new Matte;
	matte_ptr22->set_ka(ka);	
	matte_ptr22->set_kd(kd);
	matte_ptr22->set_cd(lightPurple);
	Sphere*	sphere_ptr22 = new Sphere(Point3D(5, 73, -130), 12); 
	sphere_ptr22->set_material(matte_ptr22);							// light purple
	add_object(sphere_ptr22);
	
	Matte* matte_ptr23 = new Matte;
	matte_ptr23->set_ka(ka);	
	matte_ptr23->set_kd(kd);
	matte_ptr23->set_cd(darkPurple);
	Sphere*	sphere_ptr23 = new Sphere(Point3D(66, 21, -130), 13); 			
	sphere_ptr23->set_material(matte_ptr23);							// dark purple
	add_object(sphere_ptr23);	
	
	Matte* matte_ptr24 = new Matte;
	matte_ptr24->set_ka(ka);	
	matte_ptr24->set_kd(kd);
	matte_ptr24->set_cd(lightPurple);  
	Sphere*	sphere_ptr24 = new Sphere(Point3D(72, -12, -140), 12); 
	sphere_ptr24->set_material(matte_ptr24);							// light purple
	add_object(sphere_ptr24);
	
	Matte* matte_ptr25 = new Matte;
	matte_ptr25->set_ka(ka);	
	matte_ptr25->set_kd(kd);
	matte_ptr25->set_cd(green);
	Sphere*	sphere_ptr25 = new Sphere(Point3D(64, 5, -160), 11); 			
	sphere_ptr25->set_material(matte_ptr25);					 		// green
	add_object(sphere_ptr25);
	  
	Matte* matte_ptr26 = new Matte;
	matte_ptr26->set_ka(ka);	
	matte_ptr26->set_kd(kd);
	matte_ptr26->set_cd(lightPurple);
	Sphere*	sphere_ptr26 = new Sphere(Point3D(55, 38, -160), 12); 		
	sphere_ptr26->set_material(matte_ptr26);							// light purple
	add_object(sphere_ptr26);
	
	Matte* matte_ptr27 = new Matte;
	matte_ptr27->set_ka(ka);	
	matte_ptr27->set_kd(kd);
	matte_ptr27->set_cd(lightPurple);
	Sphere*	sphere_ptr27 = new Sphere(Point3D(-73, -2, -160), 12); 		
	sphere_ptr27->set_material(matte_ptr27);							// light purple
	add_object(sphere_ptr27);
	 
	Matte* matte_ptr28 = new Matte;
	matte_ptr28->set_ka(ka);	
	matte_ptr28->set_kd(kd);
	matte_ptr28->set_cd(darkPurple);
	Sphere*	sphere_ptr28 = new Sphere(Point3D(30, -62, -140), 15); 
	sphere_ptr28->set_material(matte_ptr28); 							// dark purple
	add_object(sphere_ptr28);
	
	Matte* matte_ptr29 = new Matte;
	matte_ptr29->set_ka(ka);	
	matte_ptr29->set_kd(kd);
	matte_ptr29->set_cd(darkPurple);
	Sphere*	sphere_ptr29 = new Sphere(Point3D(25, 63, -140), 15); 
	sphere_ptr29->set_material(matte_ptr29);							// dark purple
	add_object(sphere_ptr29);
	
	Matte* matte_ptr30 = new Matte;
	matte_ptr30->set_ka(ka);	
	matte_ptr30->set_kd(kd);
	matte_ptr30->set_cd(darkPurple);
	Sphere*	sphere_ptr30 = new Sphere(Point3D(-60, 46, -140), 15);  
	sphere_ptr30->set_material(matte_ptr30); 							// dark purple
	add_object(sphere_ptr30);
	
	Matte* matte_ptr31 = new Matte;
	matte_ptr31->set_ka(ka);	
	matte_ptr31->set_kd(kd);
	matte_ptr31->set_cd(lightPurple);
	Sphere*	sphere_ptr31 = new Sphere(Point3D(-30, 68, -130), 12); 
	sphere_ptr31->set_material(matte_ptr31); 							// light purple
	add_object(sphere_ptr31);
	
	Matte* matte_ptr32 = new Matte;
	matte_ptr32->set_ka(ka);	
	matte_ptr32->set_kd(kd);
	matte_ptr32->set_cd(green);
	Sphere*	sphere_ptr32 = new Sphere(Point3D(58, 56, -180), 11);   
	sphere_ptr32->set_material(matte_ptr32);							//  green
	add_object(sphere_ptr32);
	
	Matte* matte_ptr33 = new Matte;
	matte_ptr33->set_ka(ka);	
	matte_ptr33->set_kd(kd);
	matte_ptr33->set_cd(green);
	Sphere*	sphere_ptr33 = new Sphere(Point3D(-63, -39, -180), 11); 
	sphere_ptr33->set_material(matte_ptr33);							// green 
	add_object(sphere_ptr33);
	
	Matte* matte_ptr34 = new Matte;
	matte_ptr34->set_ka(ka);	
	matte_ptr34->set_kd(kd);
	matte_ptr34->set_cd(lightPurple);
	Sphere*	sphere_ptr34 = new Sphere(Point3D(46, 68, -200), 10); 	
	sphere_ptr34->set_material(matte_ptr34);							// light purple
	add_object(sphere_ptr34);
	
	Matte* matte_ptr35 = new Matte;
	matte_ptr35->set_ka(ka);	
	matte_ptr35->set_kd(kd);
	matte_ptr35->set_cd(lightPurple);
	Sphere*	sphere_ptr35 = new Sphere(Point3D(-3, -72, -130), 12); 
	sphere_ptr35->set_material(matte_ptr35);							// light purple
	add_object(sphere_ptr35);
	
	
	// vertical plane
	
	Matte* matte_ptr36 = new Matte;
	matte_ptr36->set_ka(ka);	
	matte_ptr36->set_kd(kd);
	matte_ptr36->set_cd(grey);
	Plane* plane_ptr = new Plane(Point3D(0, 0, -150), Normal(0, 0, 1));
	plane_ptr->set_material(matte_ptr36);
	add_object (plane_ptr);
}
コード例 #5
0
//------------------------------------------------------------------------
void CWaveDisplay::draw(CDrawContext* pContext)
{
    CPoint offset(38, 16);

    CRect R(0, 0, getViewSize().getWidth(), getViewSize().getHeight());
    back->draw(pContext, R.offset(offset), offset);

    R(615 - getViewSize().left, 240 - getViewSize().top, 615 + heads->getWidth() - getViewSize().left, 240 + heads->getHeight() / 4 - getViewSize().top);
    heads->draw(pContext, R.offset(offset), CPoint(0, (display * heads->getHeight()) / 4));

    pContext->setDrawMode(CDrawMode(kAntiAliasing));

    // trig-line
    long triggerType = (long)(effect->getParameter(CSmartelectronixDisplay::kTriggerType) * CSmartelectronixDisplay::kNumTriggerTypes + 0.0001);

    if (triggerType == CSmartelectronixDisplay::kTriggerRising || triggerType == CSmartelectronixDisplay::kTriggerFalling) {
        long y = 1 + (long)((1.f - effect->getParameter(CSmartelectronixDisplay::kTriggerLevel)) * (getViewSize().getHeight() - 2));

        CColor grey(229, 229, 229);
        pContext->setFrameColor(grey);
        pContext->drawLine(CPoint(0, y).offset(offset), CPoint(getViewSize().getWidth() - 1, y).offset(offset));
    }

    // zero-line
    CColor orange(179, 111, 56);
    pContext->setFrameColor(orange);
    pContext->drawLine(CPoint(0, getViewSize().getHeight() * 0.5 - 1).offset(offset), CPoint(getViewSize().getWidth() - 1, getViewSize().getHeight() * 0.5 - 1).offset(offset));

    // waveform
    const std::vector<CPoint>& points = (effect->getParameter(CSmartelectronixDisplay::kSyncDraw) > 0.5f) ? effect->getCopy() : effect->getPeaks();
    double counterSpeedInverse = pow(10.f, effect->getParameter(CSmartelectronixDisplay::kTimeWindow) * 5.f - 1.5);

    if (counterSpeedInverse < 1.0) //draw interpolated lines!
    {
        CColor blue(64, 148, 172);
        pContext->setFrameColor(blue);

        double phase = counterSpeedInverse;
        double dphase = counterSpeedInverse;

        double prevxi = points[0].x;
        double prevyi = points[0].y;

        for (long i = 1; i < getViewSize().getWidth() - 1; i++) {
            long index = (long)phase;
            double alpha = phase - (double)index;

            double xi = i;
            double yi = (1.0 - alpha) * points[index * 2].y + alpha * points[(index + 1) * 2].y;

            pContext->drawLine(CPoint(prevxi, prevyi).offset(offset), CPoint(xi, yi).offset(offset));
            prevxi = xi;
            prevyi = yi;

            phase += dphase;
        }
    } else {
        CColor grey(118, 118, 118);
        pContext->setFrameColor(grey);

        CPoint p1, p2;
        for (unsigned int i=0; i<points.size()-1; i++)
        {
            p1 = points[i];
            p2 = points[i+1];
            pContext->drawLine(p1.offset(offset), p2.offset(offset));
        }
    }

    //TODO clean this mess up...
    if (where.x != -1) {
        CPoint whereOffset = where;
        whereOffset.offsetInverse(offset);

        pContext->drawLine(CPoint(0, whereOffset.y).offset(offset), CPoint(getViewSize().getWidth() - 1, whereOffset.y).offset(offset));
        pContext->drawLine(CPoint(whereOffset.x, 0).offset(offset), CPoint(whereOffset.x, getViewSize().getHeight() - 1).offset(offset));

        float gain = powf(10.f, effect->getParameter(CSmartelectronixDisplay::kAmpWindow) * 6.f - 3.f);
        float y = (-2.f * ((float)whereOffset.y + 1.f) / (float)OSC_HEIGHT + 1.f) / gain;
        float x = (float)whereOffset.x * (float)counterSpeedInverse;
        char text[256];

        long lineSize = 10;

        CColor color(179, 111, 56);

        pContext->setFontColor(color);
        pContext->setFont(kNormalFontSmaller);

        readout->draw(pContext, CRect(508, 8, 508 + readout->getWidth(), 8 + readout->getHeight()).offset(offset), CPoint(0, 0));

        CRect textRect(512, 10, 652, 10 + lineSize);
        textRect.offset(offset);

        sprintf(text, "y = %.5f", y);
        pContext->drawString(text, textRect, kLeftText, true);
        textRect.offset(0, lineSize);

        sprintf(text, "y = %.5f dB", cf_lin2db(fabsf(y)));
        pContext->drawString(text, textRect, kLeftText, true);
        textRect.offset(0, lineSize * 2);

        sprintf(text, "x = %.2f samples", x);
        pContext->drawString(text, textRect, kLeftText, true);
        textRect.offset(0, lineSize);

        sprintf(text, "x = %.5f seconds", x / effect->getSampleRate());
        pContext->drawString(text, textRect, kLeftText, true);
        textRect.offset(0, lineSize);

        sprintf(text, "x = %.5f ms", 1000.f * x / effect->getSampleRate());
        pContext->drawString(text, textRect, kLeftText, true);
        textRect.offset(0, lineSize);

        if (x == 0)
            sprintf(text, "x = infinite Hz");
        else
            sprintf(text, "x = %.3f Hz", effect->getSampleRate() / x);

        pContext->drawString(text, textRect, kLeftText, true);
    }
}
コード例 #6
0
ファイル: WorldView.cpp プロジェクト: emamanto/vision-sim
void WorldView::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);

    // Green background
    painter.fillRect(0, 0, WIDTH, HEIGHT, Qt::darkGreen);

    // Flip coordinate system to normal one
    painter.translate(0, HEIGHT);
    painter.scale(WIDTH_RATIO, -HEIGHT_RATIO);

    // White lines
    QPen pen(Qt::white);
    pen.setWidth(LINE_WIDTH);
    pen.setJoinStyle(Qt::MiterJoin);

    painter.setPen(pen);

    // Field
    painter.drawRect(FIELD_LEFT_EDGE_X, FIELD_BOTTOM_Y,
                     FIELD_WIDTH, FIELD_HEIGHT);

    // Goal boxes
    painter.drawRect(FIELD_LEFT_EDGE_X, GOALBOX_BOTTOM_Y,
                     GOALBOX_WIDTH, GOALBOX_HEIGHT);

    painter.drawRect(FIELD_RIGHT_EDGE_X-GOALBOX_WIDTH, GOALBOX_BOTTOM_Y,
                     GOALBOX_WIDTH, GOALBOX_HEIGHT);

    painter.drawLine(HALF_FIELD_X, FIELD_BOTTOM_Y,
                     HALF_FIELD_X, FIELD_TOP_Y);

    // Center circle
    painter.drawEllipse(HALF_FIELD_X-CENTER_CIRCLE_RAD,
                        CROSS_Y-CENTER_CIRCLE_RAD,
                        CENTER_CIRCLE_DIAM,
                        CENTER_CIRCLE_DIAM);

    // // Cross
    // painter.drawLine(convertCoords(CENTER_GOAL_X-CROSS_ARM, CROSS_Y),
    //                  convertCoords(CENTER_GOAL_X+CROSS_ARM, CROSS_Y));
    // painter.drawLine(convertCoords(CENTER_GOAL_X, CROSS_Y-CROSS_ARM),
    //                  convertCoords(CENTER_GOAL_X, CROSS_Y+CROSS_ARM));

    // Goalposts
    pen.setColor(Qt::yellow);
    pen.setWidth(GOALPOST_PEN_WIDTH);
    painter.setPen(pen);
    painter.setBrush(Qt::yellow);

    painter.drawEllipse(FIELD_LEFT_EDGE_X-GOALPOST_RAD,
                        BOTTOM_GOALPOST_Y-GOALPOST_RAD,
                        GOALPOST_WIDTH, GOALPOST_WIDTH);
    painter.drawEllipse(FIELD_LEFT_EDGE_X-GOALPOST_RAD,
                        TOP_GOALPOST_Y-GOALPOST_RAD,
                        GOALPOST_WIDTH, GOALPOST_WIDTH);

    painter.drawEllipse(FIELD_RIGHT_EDGE_X-GOALPOST_RAD,
                        BOTTOM_GOALPOST_Y-GOALPOST_RAD,
                        GOALPOST_WIDTH, GOALPOST_WIDTH);
    painter.drawEllipse(FIELD_RIGHT_EDGE_X-GOALPOST_RAD,
                        TOP_GOALPOST_Y-GOALPOST_RAD,
                        GOALPOST_WIDTH, GOALPOST_WIDTH);

    painter.drawLine(FIELD_LEFT_EDGE_X, BOTTOM_GOALPOST_Y,
                     LEFT_GOAL_BACK_X, BOTTOM_GOALPOST_Y);
    painter.drawLine(FIELD_LEFT_EDGE_X, TOP_GOALPOST_Y,
                     LEFT_GOAL_BACK_X, TOP_GOALPOST_Y);
    painter.drawLine(LEFT_GOAL_BACK_X, BOTTOM_GOALPOST_Y,
                     LEFT_GOAL_BACK_X, TOP_GOALPOST_Y);

    painter.drawLine(FIELD_RIGHT_EDGE_X, BOTTOM_GOALPOST_Y,
                     RIGHT_GOAL_BACK_X, BOTTOM_GOALPOST_Y);
    painter.drawLine(FIELD_RIGHT_EDGE_X, TOP_GOALPOST_Y,
                     RIGHT_GOAL_BACK_X, TOP_GOALPOST_Y);
    painter.drawLine(RIGHT_GOAL_BACK_X, BOTTOM_GOALPOST_Y,
                     RIGHT_GOAL_BACK_X, TOP_GOALPOST_Y);

    // Ball-Data from world instance
    QColor orange(255, 140, 0);
    pen.setColor(orange);
    painter.setPen(pen);
    painter.setBrush(orange);

    painter.drawEllipse(world.ballX()-BALL_RAD, world.ballY()-BALL_RAD,
                        2*BALL_RAD, 2*BALL_RAD);


    // Goalie-Data from WorldState instance
    pen.setColor(Qt::darkGray);
    painter.setPen(pen);
    painter.setBrush(Qt::darkGray);

    // To get the right orientation for the goalie ellipse, translates
    // coordinate system to center of the goalie and rotates before
    // drawing
    painter.translate(world.robotX(), world.robotY());
    painter.rotate(-world.robotH());
    painter.drawEllipse(-(0.5*ROBOT_X_SIZE), -(0.5*ROBOT_Y_SIZE),
                        ROBOT_X_SIZE, ROBOT_Y_SIZE);

    // Arrow specifies direction the goalie is facing
    pen.setColor(Qt::darkBlue);
    painter.setPen(pen);
    painter.drawLine(0, ARROW_START, 0, ROBOT_Y_SIZE);
    painter.drawLine(0, ROBOT_Y_SIZE, ARROW_WIDTH,
                     ROBOT_Y_SIZE-ARROW_DEPTH);
    painter.drawLine(0, ROBOT_Y_SIZE, -ARROW_WIDTH,
                     ROBOT_Y_SIZE-ARROW_DEPTH);
}
コード例 #7
0
void 												
World::build(void) {
	int num_samples = 16;

	vp.set_hres(600);
	vp.set_vres(600);
	vp.set_pixel_size(0.5);
	vp.set_samples(num_samples);  
//	vp.set_gamut_display(true);        // for Figure 14.23(b)
	
	tracer_ptr = new RayCast(this);	
	
	Pinhole* pinhole_ptr = new Pinhole;
	pinhole_ptr->set_eye(0, 0, 10000);
	pinhole_ptr->set_lookat(0.0);   
	pinhole_ptr->set_view_distance(15000);	
	pinhole_ptr->compute_uvw(); 
	set_camera(pinhole_ptr);
	
	Directional* light_ptr = new Directional;
	light_ptr->set_direction(100, 100, 200);
	light_ptr->set_color(1.0, 1.0, 1.0); 	
	light_ptr->scale_radiance(4.5); 	  		
	add_light(light_ptr);
	
	
	// colors

	RGBColor yellow(1, 1, 0);										// yellow
	RGBColor brown(0.71, 0.40, 0.16);								// brown
	RGBColor dark_green(0.0, 0.41, 0.41);							// dark_green
	RGBColor orange(1, 0.75, 0);									// orange
	RGBColor green(0, 0.6, 0.3);									// green
	RGBColor light_green(0.65, 1, 0.30);							// light green
	RGBColor dark_yellow(0.61, 0.61, 0);							// dark yellow
	RGBColor light_purple(0.65, 0.3, 1);							// light purple
	RGBColor dark_purple(0.5, 0, 1);								// dark purple
	
	
	// Matt material reflection coefficients
	
	float ka = 0.25;
	float kd = 0.75;
	
	
	// spheres
	
	Matte* matte_ptr1 = new Matte;
	matte_ptr1->set_ka(ka);	
	matte_ptr1->set_kd(kd);
	matte_ptr1->set_cd(yellow);				
	Sphere*	sphere_ptr1 = new Sphere(Point3D(5, 3, 0), 30); 
	sphere_ptr1->set_material(matte_ptr1);	   							// yellow
	add_object(sphere_ptr1);
	
	Matte* matte_ptr2 = new Matte;
	matte_ptr2->set_ka(ka);	
	matte_ptr2->set_kd(kd);
	matte_ptr2->set_cd(brown);
	Sphere*	sphere_ptr2 = new Sphere(Point3D(45, -7, -60), 20); 
	sphere_ptr2->set_material(matte_ptr2);								// brown
	add_object(sphere_ptr2);
	

	Matte* matte_ptr3 = new Matte;
	matte_ptr3->set_ka(ka);	
	matte_ptr3->set_kd(kd);
	matte_ptr3->set_cd(dark_green);	
	Sphere*	sphere_ptr3 = new Sphere(Point3D(40, 43, -100), 17); 
	sphere_ptr3->set_material(matte_ptr3);								// dark green
	add_object(sphere_ptr3);
	
	Matte* matte_ptr4 = new Matte;
	matte_ptr4->set_ka(ka);	
	matte_ptr4->set_kd(kd);
	matte_ptr4->set_cd(orange);
	Sphere*	sphere_ptr4 = new Sphere(Point3D(-20, 28, -15), 20); 
	sphere_ptr4->set_material(matte_ptr4);								// orange
	add_object(sphere_ptr4);
	
	Matte* matte_ptr5 = new Matte;
	matte_ptr5->set_ka(ka);	
	matte_ptr5->set_kd(kd);
	matte_ptr5->set_cd(green);
	Sphere*	sphere_ptr5 = new Sphere(Point3D(-25, -7, -35), 27); 			
	sphere_ptr5->set_material(matte_ptr5);								// green
	add_object(sphere_ptr5);
	
	Matte* matte_ptr6 = new Matte;
	matte_ptr6->set_ka(ka);	
	matte_ptr6->set_kd(kd);
	matte_ptr6->set_cd(light_green);
	Sphere*	sphere_ptr6 = new Sphere(Point3D(20, -27, -35), 25); 
	sphere_ptr6->set_material(matte_ptr6);								// light green
	add_object(sphere_ptr6);
	
	Matte* matte_ptr7 = new Matte;
	matte_ptr7->set_ka(ka);	
	matte_ptr7->set_kd(kd);
	matte_ptr7->set_cd(green);
	Sphere*	sphere_ptr7 = new Sphere(Point3D(35, 18, -35), 22); 
	sphere_ptr7->set_material(matte_ptr7);   							// green
	add_object(sphere_ptr7);
	
	Matte* matte_ptr8 = new Matte;
	matte_ptr8->set_ka(ka);	
	matte_ptr8->set_kd(kd);
	matte_ptr8->set_cd(brown);
	Sphere*	sphere_ptr8 = new Sphere(Point3D(-57, -17, -50), 15);  
	sphere_ptr8->set_material(matte_ptr8);								// brown
	add_object(sphere_ptr8);
	
	Matte* matte_ptr9 = new Matte;
	matte_ptr9->set_ka(ka);	
	matte_ptr9->set_kd(kd);
	matte_ptr9->set_cd(light_green);
	Sphere*	sphere_ptr9 = new Sphere(Point3D(-47, 16, -80), 23); 
	sphere_ptr9->set_material(matte_ptr9);								// light green
	add_object(sphere_ptr9);
		
	Matte* matte_ptr10 = new Matte;
	matte_ptr10->set_ka(ka);	
	matte_ptr10->set_kd(kd);
	matte_ptr10->set_cd(dark_green);	
	Sphere*	sphere_ptr10 = new Sphere(Point3D(-15, -32, -60), 22); 
	sphere_ptr10->set_material(matte_ptr10);     						// dark green
	add_object(sphere_ptr10);
	
	Matte* matte_ptr11 = new Matte;
	matte_ptr11->set_ka(ka);	
	matte_ptr11->set_kd(kd);
	matte_ptr11->set_cd(dark_yellow);
	Sphere*	sphere_ptr11 = new Sphere(Point3D(-35, -37, -80), 22); 
	sphere_ptr11->set_material(matte_ptr11);							// dark yellow
	add_object(sphere_ptr11);
	
	Matte* matte_ptr12 = new Matte;
	matte_ptr12->set_ka(ka);	
	matte_ptr12->set_kd(kd);
	matte_ptr12->set_cd(dark_yellow);
	Sphere*	sphere_ptr12 = new Sphere(Point3D(10, 43, -80), 22); 
	sphere_ptr12->set_material(matte_ptr12);							// dark yellow
	add_object(sphere_ptr12);
	
	Matte* matte_ptr13 = new Matte;
	matte_ptr13->set_ka(ka);	
	matte_ptr13->set_kd(kd);
	matte_ptr13->set_cd(dark_yellow);		
	Sphere*	sphere_ptr13 = new Sphere(Point3D(30, -7, -80), 10); 
	sphere_ptr13->set_material(matte_ptr13);
	add_object(sphere_ptr13);											// dark yellow (hidden)
	
	Matte* matte_ptr14 = new Matte;
	matte_ptr14->set_ka(ka);	
	matte_ptr14->set_kd(kd);
	matte_ptr14->set_cd(dark_green);	
	Sphere*	sphere_ptr14 = new Sphere(Point3D(-40, 48, -110), 18); 
	sphere_ptr14->set_material(matte_ptr14); 							// dark green
	add_object(sphere_ptr14);
	
	Matte* matte_ptr15 = new Matte;
	matte_ptr15->set_ka(ka);	
	matte_ptr15->set_kd(kd);
	matte_ptr15->set_cd(brown);	
	Sphere*	sphere_ptr15 = new Sphere(Point3D(-10, 53, -120), 18); 
	sphere_ptr15->set_material(matte_ptr15); 							// brown
	add_object(sphere_ptr15);
	
	Matte* matte_ptr16 = new Matte;
	matte_ptr16->set_ka(ka);	
	matte_ptr16->set_kd(kd);
	matte_ptr16->set_cd(light_purple);
	Sphere*	sphere_ptr16 = new Sphere(Point3D(-55, -52, -100), 10); 
	sphere_ptr16->set_material(matte_ptr16);							// light purple
	add_object(sphere_ptr16);
	
	Matte* matte_ptr17 = new Matte;
	matte_ptr17->set_ka(ka);	
	matte_ptr17->set_kd(kd);
	matte_ptr17->set_cd(brown);
	Sphere*	sphere_ptr17 = new Sphere(Point3D(5, -52, -100), 15); 		
	sphere_ptr17->set_material(matte_ptr17);							// browm
	add_object(sphere_ptr17);
	
	Matte* matte_ptr18 = new Matte;
	matte_ptr18->set_ka(ka);	
	matte_ptr18->set_kd(kd);
	matte_ptr18->set_cd(dark_purple);
	Sphere*	sphere_ptr18 = new Sphere(Point3D(-20, -57, -120), 15); 
	sphere_ptr18->set_material(matte_ptr18);							// dark purple
	add_object(sphere_ptr18);
	
	Matte* matte_ptr19 = new Matte;
	matte_ptr19->set_ka(ka);	
	matte_ptr19->set_kd(kd);
	matte_ptr19->set_cd(dark_green);
	Sphere*	sphere_ptr19 = new Sphere(Point3D(55, -27, -100), 17); 
	sphere_ptr19->set_material(matte_ptr19);							// dark green
	add_object(sphere_ptr19);

	Matte* matte_ptr20 = new Matte;
	matte_ptr20->set_ka(ka);	
	matte_ptr20->set_kd(kd);
	matte_ptr20->set_cd(brown);
	Sphere*	sphere_ptr20 = new Sphere(Point3D(50, -47, -120), 15); 
	sphere_ptr20->set_material(matte_ptr20);							// browm
	add_object(sphere_ptr20);
	 
	Matte* matte_ptr21 = new Matte;
	matte_ptr21->set_ka(ka);	
	matte_ptr21->set_kd(kd);
	matte_ptr21->set_cd(light_purple); 	
	Sphere*	sphere_ptr21 = new Sphere(Point3D(70, -42, -150), 10); 
	sphere_ptr21->set_material(matte_ptr21);							// light purple
	add_object(sphere_ptr21);
	
	Matte* matte_ptr22 = new Matte;
	matte_ptr22->set_ka(ka);	
	matte_ptr22->set_kd(kd);
	matte_ptr22->set_cd(light_purple);
	Sphere*	sphere_ptr22 = new Sphere(Point3D(5, 73, -130), 12); 
	sphere_ptr22->set_material(matte_ptr22);							// light purple
	add_object(sphere_ptr22);
	
	Matte* matte_ptr23 = new Matte;
	matte_ptr23->set_ka(ka);	
	matte_ptr23->set_kd(kd);
	matte_ptr23->set_cd(dark_purple);
	Sphere*	sphere_ptr23 = new Sphere(Point3D(66, 21, -130), 13); 			
	sphere_ptr23->set_material(matte_ptr23);							// dark purple
	add_object(sphere_ptr23);	
	
	Matte* matte_ptr24 = new Matte;
	matte_ptr24->set_ka(ka);	
	matte_ptr24->set_kd(kd);
	matte_ptr24->set_cd(light_purple);  
	Sphere*	sphere_ptr24 = new Sphere(Point3D(72, -12, -140), 12); 
	sphere_ptr24->set_material(matte_ptr24);							// light purple
	add_object(sphere_ptr24);
	
	Matte* matte_ptr25 = new Matte;
	matte_ptr25->set_ka(ka);	
	matte_ptr25->set_kd(kd);
	matte_ptr25->set_cd(green);
	Sphere*	sphere_ptr25 = new Sphere(Point3D(64, 5, -160), 11); 			
	sphere_ptr25->set_material(matte_ptr25);					 		// green
	add_object(sphere_ptr25);
	  
	Matte* matte_ptr26 = new Matte;
	matte_ptr26->set_ka(ka);	
	matte_ptr26->set_kd(kd);
	matte_ptr26->set_cd(light_purple);
	Sphere*	sphere_ptr26 = new Sphere(Point3D(55, 38, -160), 12); 		
	sphere_ptr26->set_material(matte_ptr26);							// light purple
	add_object(sphere_ptr26);
	
	Matte* matte_ptr27 = new Matte;
	matte_ptr27->set_ka(ka);	
	matte_ptr27->set_kd(kd);
	matte_ptr27->set_cd(light_purple);
	Sphere*	sphere_ptr27 = new Sphere(Point3D(-73, -2, -160), 12); 		
	sphere_ptr27->set_material(matte_ptr27);							// light purple
	add_object(sphere_ptr27);
	 
	Matte* matte_ptr28 = new Matte;
	matte_ptr28->set_ka(ka);	
	matte_ptr28->set_kd(kd);
	matte_ptr28->set_cd(dark_purple);
	Sphere*	sphere_ptr28 = new Sphere(Point3D(30, -62, -140), 15); 
	sphere_ptr28->set_material(matte_ptr28); 							// dark purple
	add_object(sphere_ptr28);
	
	Matte* matte_ptr29 = new Matte;
	matte_ptr29->set_ka(ka);	
	matte_ptr29->set_kd(kd);
	matte_ptr29->set_cd(dark_purple);
	Sphere*	sphere_ptr29 = new Sphere(Point3D(25, 63, -140), 15); 
	sphere_ptr29->set_material(matte_ptr29);							// dark purple
	add_object(sphere_ptr29);
	
	Matte* matte_ptr30 = new Matte;
	matte_ptr30->set_ka(ka);	
	matte_ptr30->set_kd(kd);
	matte_ptr30->set_cd(dark_purple);
	Sphere*	sphere_ptr30 = new Sphere(Point3D(-60, 46, -140), 15);  
	sphere_ptr30->set_material(matte_ptr30); 							// dark purple
	add_object(sphere_ptr30);
	
	Matte* matte_ptr31 = new Matte;
	matte_ptr31->set_ka(ka);	
	matte_ptr31->set_kd(kd);
	matte_ptr31->set_cd(light_purple);
	Sphere*	sphere_ptr31 = new Sphere(Point3D(-30, 68, -130), 12); 
	sphere_ptr31->set_material(matte_ptr31); 							// light purple
	add_object(sphere_ptr31);
	
	Matte* matte_ptr32 = new Matte;
	matte_ptr32->set_ka(ka);	
	matte_ptr32->set_kd(kd);
	matte_ptr32->set_cd(green);
	Sphere*	sphere_ptr32 = new Sphere(Point3D(58, 56, -180), 11);   
	sphere_ptr32->set_material(matte_ptr32);							//  green
	add_object(sphere_ptr32);
	
	Matte* matte_ptr33 = new Matte;
	matte_ptr33->set_ka(ka);	
	matte_ptr33->set_kd(kd);
	matte_ptr33->set_cd(green);
	Sphere*	sphere_ptr33 = new Sphere(Point3D(-63, -39, -180), 11); 
	sphere_ptr33->set_material(matte_ptr33);							// green 
	add_object(sphere_ptr33);
	
	Matte* matte_ptr34 = new Matte;
	matte_ptr34->set_ka(ka);	
	matte_ptr34->set_kd(kd);
	matte_ptr34->set_cd(light_purple);
	Sphere*	sphere_ptr34 = new Sphere(Point3D(46, 68, -200), 10); 	
	sphere_ptr34->set_material(matte_ptr34);							// light purple
	add_object(sphere_ptr34);
	
	Matte* matte_ptr35 = new Matte;
	matte_ptr35->set_ka(ka);	
	matte_ptr35->set_kd(kd);
	matte_ptr35->set_cd(light_purple);
	Sphere*	sphere_ptr35 = new Sphere(Point3D(-3, -72, -130), 12); 
	sphere_ptr35->set_material(matte_ptr35);							// light purple
	add_object(sphere_ptr35);
	
}
コード例 #8
0
ファイル: Game.cpp プロジェクト: xzrunner/t3d
void Game::Init()
{
	Modules::Init();

	Modules::GetLog().Init();

	Modules::GetGraphics().Init(main_window_handle,
		WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP, false);

	Modules::GetInput().Init(main_instance);
	Modules::GetInput().InitKeyboard(main_window_handle);

	Modules::GetSound().Init(main_window_handle);
//	Modules::GetMusic().Init(main_window_handle);

	// hide the mouse
	if (!WINDOWED_APP)
		ShowCursor(FALSE);

	// seed random number generator
	srand(Modules::GetTimer().Start_Clock());

// 	// initialize math engine
// 	Build_Sin_Cos_Tables();

	// build the inverse cosine lookup
	BuildInverseCosTable(dp_inverse_cos, 360);

	gadgets = new bspeditor::Gadgets;
	gadgets->background->Create(0,0,800,600,1, BOB_ATTR_VISIBLE | BOB_ATTR_SINGLE_FRAME, DDSCAPS_SYSTEMMEMORY, 0, 32);
	BmpFile* bitmap = new BmpFile("../../assets/chap13/bspgui02.bmp");
	gadgets->background->LoadFrame(bitmap,0,0,0,BITMAP_EXTRACT_MODE_ABS);
	delete bitmap;

	gadgets->Load();

// 	// load the sounds
// 	beep0_sound_id = DSound_Load_WAV("../menuitem.wav");

	t3d::BOB* textures = bspeditor::Context::Instance()->textures;
	t3d::BmpImg** texturemaps = bspeditor::Context::Instance()->texturemaps;

	textures->Create(0,0,TEXTURE_SIZE,TEXTURE_SIZE,NUM_TEXTURES, BOB_ATTR_VISIBLE | BOB_ATTR_SINGLE_FRAME, DDSCAPS_SYSTEMMEMORY, 0, 32);

	// set visibility
	textures->SetAttrBit(BOB_ATTR_VISIBLE);

	// interate and extract both the off and on bitmaps for each animated button
	for (int index = 0; index < NUM_TEXTURES; index++)
	{
		// load the bitmap to extract imagery
		sprintf(buffer, "../../assets/chap13/bspdemotext128_%d.bmp", index);
		bitmap = new BmpFile(buffer);

		// load the frame for the bob
		textures->LoadFrame(bitmap,index,0,0,BITMAP_EXTRACT_MODE_ABS);

		// load in the frame for the bitmap
		texturemaps[index] = new BmpImg(0,0, TEXTURE_SIZE, TEXTURE_SIZE, 32);
		texturemaps[index]->LoadImage32(*bitmap,0,0,BITMAP_EXTRACT_MODE_ABS);

		// unload the bitmap
		delete bitmap;
	} // end for index

	// initialize the camera with 90 FOV, normalized coordinates
	bspeditor::Context::Instance()->cam = new Camera(
		CAM_MODEL_EULER, // the euler model
		vec4(0,0,0,1),        // initial camera position
		vec4(0,0,0,1),        // initial camera angles
		vec4(0,0,0,1),     // no target
		5.0,            // near and far clipping planes
		12000.0,
		120.0,           // field of view in degrees
		WINDOW_WIDTH,    // size of final screen viewport
		WINDOW_HEIGHT
		);

	// set a scaling vector
	vec4 vscale(.15,.15,.15,1);

#if 0
	// load the object in
	Load_OBJECT4DV2_COB2(&obj_moveable, "rec_flat_textured_01.cob",  
		&vscale, &vpos, &vrot, VERTEX_FLAGS_SWAP_YZ  | VERTEX_FLAGS_INVERT_Z |
		VERTEX_FLAGS_TRANSFORM_LOCAL 
		/* VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD*/,0 );


	// position the scenery objects randomly
	for (index = 0; index < NUM_SCENE_OBJECTS; index++)
	{
		// randomly position object
		scene_objects[index].x = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);
		scene_objects[index].y = RAND_RANGE(-200, 200);
		scene_objects[index].z = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);
	} // end for
#endif


	// set up lights
	LightsMgr& lights = Modules::GetGraphics().GetLights();
	lights.Reset();

	// create some working colors
	Color white(255,255,255,0),
		  gray(100,100,100,0),
		  black(0,0,0,0),
		  red(255,0,0,0),
		  green(0,255,0,0),
		  blue(0,0,255,0),
		  orange(255,128,0,0),
		  yellow(255,255,0,0);

	// ambient light
	lights.Init(AMBIENT_LIGHT_INDEX,   
				LIGHT_STATE_ON,      // turn the light on
				LIGHT_ATTR_AMBIENT,  // ambient light type
				gray, black, black,    // color for ambient term only
				NULL, NULL,            // no need for pos or dir
				0,0,0,                 // no need for attenuation
				0,0,0);                // spotlight info NA

	vec4 dlight_dir(-1,0,-1,1);

	// directional light
	lights.Init(INFINITE_LIGHT_INDEX,  
		LIGHT_STATE_ON,      // turn the light on
		LIGHT_ATTR_INFINITE, // infinite light type
		black, gray, black,    // color for diffuse term only
		NULL, &dlight_dir,     // need direction only
		0,0,0,                 // no need for attenuation
		0,0,0);                // spotlight info NA

	vec4 plight_pos(0,200,0,1);

	// point light
	lights.Init(POINT_LIGHT_INDEX,
		LIGHT_STATE_ON,      // turn the light on
		LIGHT_ATTR_POINT,    // pointlight type
		black, gray, black,   // color for diffuse term only
		&plight_pos, NULL,     // need pos only
		0,.001,0,              // linear attenuation only
		0,0,1);                // spotlight info N

	// point light
	lights.Init(POINT_LIGHT2_INDEX,
		LIGHT_STATE_ON,    // turn the light on
		LIGHT_ATTR_POINT,  // pointlight type
		black, white, black,   // color for diffuse term only
		&plight_pos, NULL,   // need pos only
		0,.002,0,            // linear attenuation only
		0,0,1);              // spotlight info NA

	// create the z buffer
	zbuffer->Create(WINDOW_WIDTH, WINDOW_HEIGHT, ZBUFFER_ATTR_32BIT);

	// reset the editor
	bspeditor::Context::Instance()->Reset();

	// load background image that scrolls 
	bitmap = new BmpFile("../../assets/chap13/red01a.BMP");
	background_bmp = new BmpImg(0,0,800,600,32);
	background_bmp->LoadImage32(*bitmap,0,0,BITMAP_EXTRACT_MODE_ABS);
	delete bitmap;
}
コード例 #9
0
ファイル: ad_send.hpp プロジェクト: migashko/faslib-sandbox
 bool _send( T& t, J, const V& value, type2type<B> )
 {
   typedef B buffer_type;
   buffer_type& buffer = t.get_aspect().template get<_buffer_>();
   return _output( t, J(), value, orange(buffer, true) );
 }
コード例 #10
0
// Rendu de l'environnement (pour la réflexion de l'eau ou non)
void SceneTerrain::RenderEnvironment(bool bWaterReflection, bool bDepthMap)
{
	ResourceManager& res = ResourceManager::getInstance();
	VarManager& var = VarManager::getInstance();
	Camera& cam = Camera::getInstance();

	vec4 white(1.0f, 1.0f, 1.0f, 1.0f);
	vec4 black(0.0f, 0.0f, 0.0f, 1.0f);
	vec4 orange(1.0f, 0.5f, 0.0f, 1.0f);
	vec4 yellow(1.0f, 1.0f, 0.8f, 1.0f);
	float sun_cosy = cosf(m_vSunAngle.y);

	glPushAttrib(GL_ENABLE_BIT);


	if(!bDepthMap)
	{


		
		vec4 vSunColor = white.lerp(orange, yellow, 0.25f + sun_cosy * 0.75f);


		if(cam.getEye().y < var.getf("water_height"))
		{
			bWaterReflection = false;
			var.set("enable_underwater", true);
		}
		else
		{
			var.set("enable_underwater", false);
		}


		// Affichage du ciel et du soleil
		Sky::getInstance().DrawSkyAndSun( Camera::getInstance().getEye(), vec3(m_vSunVector), m_pSkybox->getHandle(), bWaterReflection );



		// Si c'est pour la réflexion, on dessine la scène à l'envers
		if(bWaterReflection) {
			glDisable(GL_CULL_FACE);
			glLoadIdentity();
			
			glScalef(-1.0f, 1.0f, 1.0f);
			cam.RenderLookAt(true, var.getf("water_height"));
		}

		glEnable(GL_LIGHTING);
		glEnable(GL_LIGHT0);
		vec3 zeros(0.0f, 0.0f, 0.0f);
		glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, zeros);
		glLightfv(GL_LIGHT0, GL_POSITION, m_vSunVector);
		glLightfv(GL_LIGHT0, GL_AMBIENT, white);
		glLightfv(GL_LIGHT0, GL_DIFFUSE, vSunColor);
		glLightfv(GL_LIGHT0, GL_SPECULAR, vSunColor);

	}

	// Affichage des maisons à l'arrache
	m_pShaderLighting->Activate();
	{
		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, white/6);
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, white);

		res.getTexture2D("wall_diffuse.jpg")->Bind(0);
		res.getTexture2D("wall_NM_height.tga")->Bind(1);

		m_pShaderLighting->UniformTexture("texDiffuse", 0);
		m_pShaderLighting->UniformTexture("texNormalHeightMap", 1);
		m_pShaderLighting->Uniform("mode", 1);
		m_pShaderLighting->Uniform("enable_shadow_mapping", 0);
		m_pShaderLighting->Uniform("tile_factor", 2.0f);

		glPushMatrix();
		glTranslatef(172.0f, 5.18f, 175.2f);
		res.getMesh("terrain_house.obj")->Draw();
		glPopMatrix();

		glPushMatrix();
		glTranslatef(19.0f, 35.8f, -123.1f);
		res.getMesh("terrain_house.obj")->Draw();
		glPopMatrix();

		glPushMatrix();
		glTranslatef(1.338f, 18.02f, 259.0f);
		res.getMesh("terrain_house.obj")->Draw();
		glPopMatrix();

		glPushMatrix();
		glTranslatef(178.6f, 32.42f, 26.31f);
		res.getMesh("terrain_house.obj")->Draw();
		glPopMatrix();

		res.getTexture2D("wall_NM_height.tga")->Unbind(1);
		res.getTexture2D("wall_diffuse.jpg")->Unbind(0);
	}
	m_pShaderLighting->Deactivate();


	if(!bDepthMap)
	{
		vec4 vGroundAmbient = white.lerp(white*0.2f, black, sun_cosy);
		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, vGroundAmbient);
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, white);
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
		glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50.0f);



		glMatrixMode(GL_TEXTURE);
		glActiveTexture(GL_TEXTURE0);
		glLoadMatrixf( m_matSunModelviewProj );
		glMatrixMode(GL_MODELVIEW);

		// Activation des textures
		GLuint idx=0;
		for(GLuint i=0; i<m_tTextures.size(); i++)
			m_tTextures[i]->Bind(idx++);
		m_pTerrainDiffuseMap->Bind(idx++);
		if(!bDepthMap) {
			for(GLuint i=0; i<TERRAIN_SHADOWMAPS_COUNT; i++)
				m_fboDepthMapFromLight[i].Bind(idx++);
		}

		// Affichage du terrain
		m_pShaderTerrain->Activate();
		{
			m_pShaderTerrain->Uniform("detail_scale", 120.0f);
			m_pShaderTerrain->Uniform("diffuse_scale", 70.0f);

			m_pShaderTerrain->Uniform("water_height", var.getf("water_height"));
			m_pShaderTerrain->Uniform("water_reflection_rendering", bWaterReflection);

			m_pShaderTerrain->Uniform("time", Timer::getInstance().getCurrentTime());

			m_pShaderTerrain->UniformTexture("texNormalHeightMap", 0);
			m_pShaderTerrain->UniformTexture("texDiffuse0", 1);
			m_pShaderTerrain->UniformTexture("texDiffuse1", 2);
			m_pShaderTerrain->UniformTexture("texDiffuse2", 3);
			m_pShaderTerrain->UniformTexture("texWaterCaustics", 4);
			m_pShaderTerrain->UniformTexture("texDiffuseMap", 5);
			m_pShaderTerrain->UniformTexture("texDepthMapFromLight0", 6);
			m_pShaderTerrain->UniformTexture("texDepthMapFromLight1", 7);

			m_pShaderTerrain->Uniform("depth_map_size", 512);

			int ret = m_pTerrain->DrawGround(bWaterReflection);
			var.set(bWaterReflection? "terrain_chunks_reflected_drawn" : "terrain_chunks_drawn", ret);

			m_pTerrain->DrawInfinitePlane(Camera::getInstance().getEye(), 2.0f*var.getf("cam_zfar"));
		}
		m_pShaderTerrain->Deactivate();

		
		// Désactivation des textures
		if(!bDepthMap) {
			for(GLint i=TERRAIN_SHADOWMAPS_COUNT-1; i>=0; i--)
				m_fboDepthMapFromLight[i].Unbind(--idx);
		}
		m_pTerrainDiffuseMap->Unbind(--idx);
		for(GLint i=(GLint)m_tTextures.size()-1; i>=0; i--)
			m_tTextures[i]->Unbind(--idx);
		

		// Affichage de l'herbe
		if(!bWaterReflection)
		{
			glEnable(GL_BLEND);
			m_pShaderGrass->Activate();
			{
				res.getTexture2D("grass_billboards.tga")->Bind(0);
				for(GLuint i=0; i<TERRAIN_SHADOWMAPS_COUNT; i++)
					m_fboDepthMapFromLight[i].Bind(1+i);

				m_pShaderGrass->UniformTexture("texDiffuse", 0);
				m_pShaderGrass->UniformTexture("texDepthMapFromLight0", 1);
				m_pShaderGrass->UniformTexture("texDepthMapFromLight1", 2);
				m_pShaderGrass->Uniform("depth_map_size", 512);

				m_pShaderGrass->Uniform("time", Timer::getInstance().getCurrentTime());
				m_pShaderGrass->Uniform("lod_metric", TERRAIN_GRASS_MAX_DISTANCE);

					m_pTerrain->DrawGrass(bWaterReflection);

				for(GLint i=TERRAIN_SHADOWMAPS_COUNT-1; i>=0; i--)
					m_fboDepthMapFromLight[i].Unbind(1+i);
				res.getTexture2D("grass_billboards.tga")->Unbind(0);
			}
			m_pShaderGrass->Deactivate();
			glDisable(GL_BLEND);
		}

		glMatrixMode(GL_TEXTURE);
		glActiveTexture(GL_TEXTURE0);
		glLoadIdentity();
		glMatrixMode(GL_MODELVIEW);
	}


	m_pShaderTree->Activate();
	{
		glMatrixMode(GL_TEXTURE);
		glActiveTexture(GL_TEXTURE0);
		glLoadMatrixf( Frustum::getInstance().getModelviewInvMatrix() );
		glMatrixMode(GL_MODELVIEW);

		GLuint idx=0;
		res.getTexture2D("palm_texture.tga")->Bind(idx++);
		if(!bDepthMap) {
			for(GLuint i=0; i<TERRAIN_SHADOWMAPS_COUNT; i++)
				m_fboDepthMapFromLight[i].Bind(idx++);
		}


		m_pShaderTree->UniformTexture("texDiffuse", 0);
		m_pShaderTree->UniformTexture("texDepthMapFromLight0", 1);
		m_pShaderTree->UniformTexture("texDepthMapFromLight1", 2);

		m_pShaderTree->Uniform("time", Timer::getInstance().getCurrentTime());

			m_pTerrain->DrawObjects(bWaterReflection);


		res.getTexture2D("palm_texture.tga")->Unbind(--idx);
		if(!bDepthMap) {
			for(GLint i=TERRAIN_SHADOWMAPS_COUNT-1; i>=0; i--)
				m_fboDepthMapFromLight[i].Unbind(--idx);
		}

		glMatrixMode(GL_TEXTURE);
		glActiveTexture(GL_TEXTURE0);
		glLoadIdentity();
		glMatrixMode(GL_MODELVIEW);
	}
	m_pShaderTree->Deactivate();



	glPopAttrib();

}
コード例 #11
0
/** Adds a file to the tree widget
  *
  * \param fi A QFileInfo object pointing the file to add
  *
  */
void RainbruRPG::Gui::QuarantineList::addFile(QFileInfo fi){
  LOGI("Addfile called");
  QBrush red(QColor(250,0,0));
  QBrush orange(QColor(0, 0, 240));
  QBrush green(QColor(0,250,0));

  bool fileInTransfer;

  if (fi.isFile()){

    // Is this file is in storedFile list
    QRegExp rexp(fi.fileName());
    
    if (storedFiles.indexOf(rexp)==-1){
      LOGI("The file is NOT being stored");
      LOGCATS("filename=");
      LOGCATS(fi.fileName().toLatin1());
      LOGCAT();

      LOGCATS("storedFiles=");
      LOGCATS(storedFiles.join(";").toLatin1());
      LOGCAT();

      fileInTransfer=false;
    }
    else{
      LOGI("The file is being stored");
      fileInTransfer=true;
      labStillInTransfer->setVisible(true);

    }

    // adding it to the list
    QTreeWidgetItem *it= new QTreeWidgetItem(tree);
    it->setText(0,fi.fileName() );
    it->setText(1,fileSizeToString(fi.size()) );
   
    // Get the mime-type
    FileTypeGuesser ftg;
    std::string stdFn(fi.absoluteFilePath().toLatin1());
    std::string strMime=ftg.getMimeType(stdFn);
    it->setText(2,strMime.c_str() );

    tQuarantineFileStatus status=ftg.getFileStatus(stdFn);
    std::string strStatus;
    switch(status){
      case QFS_ACCEPTED:
	strStatus="Accepted";
	it->setForeground ( 0, green);
	it->setForeground ( 1, green);
	it->setForeground ( 2, green);
	it->setForeground ( 3, green);
	break;
      case QFS_REFUSED:
	strStatus="Refused";
	it->setForeground ( 0, red);
	it->setForeground ( 1, red);
	it->setForeground ( 2, red);
	it->setForeground ( 3, red);
	break;
      case QFS_UNKNOWN:
	strStatus="Unknown";
	it->setForeground ( 0, orange);
	it->setForeground ( 1, orange);
	it->setForeground ( 2, orange);
	it->setForeground ( 3, orange);
	break;
      case QFS_WRONGEXT:
	strStatus="Wrong extension";
	it->setForeground ( 0, orange);
	it->setForeground ( 1, orange);
	it->setForeground ( 2, orange);
	it->setForeground ( 3, orange);
	break;
      case QFS_TESTEDEXT:
	strStatus="Tested but unlisted extension";
	break;
    default:
	strStatus="ERROR";
	it->setForeground ( 0, red);
	it->setForeground ( 1, red);
	it->setForeground ( 2, red);
	it->setForeground ( 3, red);
    }

    it->setText(3,strStatus.c_str() );

    //    if (fileInTransfer){
    //      it->setText(3,"Still in transfer...");
    //    }

    tree->addTopLevelItem( it );
  }
}
コード例 #12
0
ファイル: visual.cpp プロジェクト: Jarodshow/NEATDoc
/* Create a new backing pixmap of the appropriate size */
int PopulationDrawingArea::configure_event_impl (GdkEventConfigure * /* event */)
  {

    Gdk_Font font ( "-*-courier-bold-*-*-*-*-120-*-*-*-*-*-*");
    list<Generation_viz*>::iterator curgen;
    Generation_viz *lastgen=0;
    list<Species_viz*>::iterator curspec;
    list<Species_viz*>::iterator curspec2;
    Species_viz *samespec=0;
    Gdk_Color red("red");
    Gdk_Color white("white");
    Gdk_Color black("black");
    Gdk_Color blue("blue");
    Gdk_Color cyan("cyan");
    Gdk_Color yellow("yellow");
    Gdk_Color green("green");
    Gdk_Color orange("orange");
    Gdk_Color purple("purple");
    GdkPoint points[4];  //The polygonal area to fill

    get_colormap().alloc(black);
    get_colormap().alloc(white);
    get_colormap().alloc(red);
    get_colormap().alloc(blue);
    get_colormap().alloc(cyan);
    get_colormap().alloc(yellow);
    get_colormap().alloc(green);
    get_colormap().alloc(orange);
    get_colormap().alloc(purple);
    int ypos=3;
    int xpos=3;
    double ypixels=height()-6;
    double xpixels=width()-6;
    int ystep;
    int xstep;
    int num_gens=stop_gen-start_gen+1;  //Total number of generations
    int gen_count;
    int print_number_every=(int) num_gens/10;
    bool y_for_gens;  //Flag for deciding on which axis is which


    //Markers for points where the color should change with fitness
    //Mark 3 is the MEAN
    //Mark 1 and 2 are 2 and 1 std. away respectively, going down
    //Mark 4 and 5 are 1 and 2 std. away respectively, going up
    double mark1,mark2,mark3,mark4,mark5;

    if (num_gens<10) print_number_every=1;
    
    if (width()>height())
      y_for_gens=false;
    else y_for_gens=true;

    mark3=pop->mean_fitness;
    mark2=mark3-(pop->standard_deviation);
    mark1=mark2-(pop->standard_deviation);
    mark4=mark3+(pop->standard_deviation);
    mark5=mark4+(pop->standard_deviation);

    //cout<<"blue "<<mark1<<" cyan "<<mark2<<" green "<<mark3<<" orange "<<mark4<<" purple "<<mark5<<" red"<<endl;

    cout<<"blue "<<mark3<<" black "<<mark5<<" red"<<endl;

    //Computer the step
    if (y_for_gens)
      ystep=(int) floor(ypixels/((double) num_gens));
    else xstep=(int) floor(xpixels/((double) num_gens));

    char text[20];

    win = get_window();
    visual = win.get_visual();

    if (pixmap)
      pixmap.release();
    
    pixmap.create(get_window(),  width(), height());

    if (!gc)
      {
        gc = Gdk_GC(pixmap);
	gc.set_foreground(white);
      }
    //gc = get_style()->get_white_gc();
    gc.set_foreground(white);
    pixmap.draw_rectangle (gc,
			TRUE,
			0, 0,
			width(),
			height());

    //Set the current generation to the start gen
    curgen=(pop->generation_snapshots).begin();
    for(gen_count=1;gen_count<start_gen;gen_count++)
      ++curgen;

    //DRAW THE POPULATION HERE
    for(gen_count=start_gen;gen_count<=stop_gen;gen_count++) {

      //Print the gen_num in the left or bottom column space every few gens
      if ((gen_count%print_number_every)==0) {
	gc.set_foreground(black);
	itoa(gen_count,text);
	if (y_for_gens) 
	  pixmap.draw_text      (font,
				 gc,
				 1,
				 ypos+5,
				 text,
				 strlen(text));
	else pixmap.draw_text      (font,
				    gc,
				    xpos-5,
				    height()-10,
				    text,
				    strlen(text));
      }

      //Draw each Species in the current generation
      for(curspec=((*curgen)->species_list).begin();curspec!=((*curgen)->species_list).end();++curspec) {
	
	//Determine the line color for this species
	if (((*curspec)->max_fitness)<mark1) {
	    gc.set_foreground(blue);
	    //gc.set_line_width(1);
	}
	else if (((*curspec)->max_fitness)<mark2) {
	    gc.set_foreground(blue);
	    //gc.set_line_width(1);
	}
	else if (((*curspec)->max_fitness)<mark3) {
	    gc.set_foreground(blue);
	    //gc.set_line_width(2);
	}
	else if (((*curspec)->max_fitness)<mark4) {
	    gc.set_foreground(black);
	    //gc.set_line_width(2);
	}
	else if (((*curspec)->max_fitness)<mark5) {
	    gc.set_foreground(black);
	    //gc.set_line_width(3);
	}
	else {
	    gc.set_foreground(red);
	    //gc.set_line_width(3);
	}

	//If this is the first gen, then everything is a straight line
	if (gen_count==start_gen) {
	  //gc.set_foreground(black);
	  //gc.set_line_width(floor(fabs(2*((*curlink)->weight))));
	  if (y_for_gens)
	    pixmap.draw_line(gc,
			     (*curspec)->startx,
			     ypos,
			     (*curspec)->endx, 
			     ypos);
	  else pixmap.draw_line(gc,
				xpos,
				(*curspec)->starty,
				xpos, 
				(*curspec)->endy);
	}
	else {
	  //Check the previous generation for this same Species
	  curspec2=(lastgen->species_list).begin();
	  while ((curspec2!=(lastgen->species_list).end())&&
		 (((*curspec2)->id)!=((*curspec)->id)))
	    ++curspec2;

	  //If it is not found, just draw a horizontal line
	  if (curspec2==(lastgen->species_list).end()) {
	    if (y_for_gens)
	      pixmap.draw_line(gc,
			       (*curspec)->startx,
			       ypos,
			       (*curspec)->endx, 
			       ypos);
	    else pixmap.draw_line(gc,
				  xpos,
				  (*curspec)->starty,
				  xpos, 
				  (*curspec)->endy);

	  }

	  //Otherwise, if it existed before, connect the 2 endpoint pairs
	  else {
 
	    //Instead of just linking lines, draw a filled polygon
	    //contained by them
	    if (y_for_gens) {
	      points[0].x=(*curspec)->startx;
	      points[0].y=ypos;
	      points[1].x=(*curspec)->endx;
	      points[1].y=ypos;
	      points[2].x=(*curspec2)->endx;
	      points[2].y=ypos-ystep;
	      points[3].x=(*curspec2)->startx;
	      points[3].y=ypos-ystep;
	    }
	    else {
	      points[0].x=xpos;
	      points[0].y=(*curspec)->starty;
	      points[1].x=xpos;
	      points[1].y=(*curspec)->endy;;
	      points[2].x=xpos-xstep;
	      points[2].y=(*curspec2)->endy;
	      points[3].x=xpos-xstep;
	      points[3].y=(*curspec2)->starty;
	    }

	    pixmap.draw_polygon    (gc,
				    TRUE,
				    points,
				    4);

    
	    //Make white borders
	    gc.set_foreground(white);
	    gc.set_line_width(1);
	    if (y_for_gens) {
	      pixmap.draw_line(gc,
			       (*curspec)->startx,
			       ypos,
			       (*curspec2)->startx, 
			       ypos-ystep);
	      pixmap.draw_line(gc,
			       (*curspec)->endx,
			       ypos,
			       (*curspec2)->endx, 
			       ypos-ystep);
	    }
	    else {
	      pixmap.draw_line(gc,
			       xpos,
			       (*curspec)->starty,
			       xpos-xstep, 
			       (*curspec2)->starty);
	      pixmap.draw_line(gc,
			       xpos,
			       (*curspec)->endy,
			       xpos-xstep, 
			       (*curspec2)->endy);
	    }


	  }

	  //Print the Species' id for high fitness
	  if ((*curspec)->max_fitness>mark5) {
	    gc.set_foreground(black);
	    itoa((*curspec)->id,text);
	    if (y_for_gens)
	      pixmap.draw_text      (font,
				     gc,
				     (int) ((((*curspec)->endx)+((*curspec)->startx))/2.0),
				     ypos,
				     text,
				     strlen(text));
	    else pixmap.draw_text      (font,
					gc,
					xpos-5,
					(int) ((((*curspec)->endy)+((*curspec)->starty))/2.0)+5.0,
					text,
					strlen(text));
	  }
	    
	  

	}

      }  //End for on curspec

      //Increment pos
      ypos+=ystep;
      xpos+=xstep;
      
      //Remember the last generation
      lastgen=(*curgen);

      ++curgen;

    } //End for on curgen


    //Print labels in a separate loop so they don't get painted over    
    
    //Set the current generation to the start gen
    curgen=(pop->generation_snapshots).begin();
    for(gen_count=1;gen_count<start_gen;gen_count++)
      ++curgen;
    ypos=3;
    xpos=3;
    for(gen_count=start_gen;gen_count<=stop_gen;gen_count++) {
      
      //Draw each Species in the current generation
      for(curspec=((*curgen)->species_list).begin();curspec!=((*curgen)->species_list).end();++curspec) {
	
	if ((*curspec)->max_fitness>mark5) {
	  gc.set_foreground(black);
	  itoa((*curspec)->id,text);
	  if (y_for_gens)
	    pixmap.draw_text      (font,
				   gc,
				   (int) ((((*curspec)->endx)+((*curspec)->startx))/2.0),
				   ypos,
				   text,
				   strlen(text));
	  else pixmap.draw_text      (font,
				      gc,
				      xpos-7,
				      (int) ((((*curspec)->endy)+((*curspec)->starty))/2.0)+5.0,
				      text,
				      strlen(text));
	}
	
      }
      
      //Increment pos
      ypos+=ystep;
      xpos+=xstep;
      
      //Remember the last generation
      lastgen=(*curgen);
      
      ++curgen;
      
    }
    
    return TRUE;
    
  }
コード例 #13
0
ファイル: main.c プロジェクト: suonikeyinsuxiao/trunk
void print()
{
    apple();
    orange();
}
コード例 #14
0
ファイル: scalable_font.cpp プロジェクト: Charence/stk-code
//! draws some text and clips it to the specified rectangle if wanted
void ScalableFont::doDraw(const core::stringw& text,
                          const core::rect<s32>& position, video::SColor color,
                          bool hcenter, bool vcenter,
                          const core::rect<s32>* clip,
                          FontCharCollector* charCollector)
{
    if (!Driver) return;

    if (m_shadow)
    {
        m_shadow = false; // avoid infinite recursion

        core::rect<s32> shadowpos = position;
        shadowpos.LowerRightCorner.X += 2;
        shadowpos.LowerRightCorner.Y += 2;

        draw(text, shadowpos, m_shadow_color, hcenter, vcenter, clip);

        m_shadow = true; // set back
    }

    core::position2d<s32> offset = position.UpperLeftCorner;
    core::dimension2d<s32> text_dimension;

    if (m_rtl || hcenter || vcenter || clip)
    {
        text_dimension = getDimension(text.c_str());

        if (hcenter)    offset.X += (position.getWidth() - text_dimension.Width) / 2;
        else if (m_rtl) offset.X += (position.getWidth() - text_dimension.Width);

        if (vcenter)    offset.Y += (position.getHeight() - text_dimension.Height) / 2;
        if (clip)
        {
            core::rect<s32> clippedRect(offset, text_dimension);
            clippedRect.clipAgainst(*clip);
            if (!clippedRect.isValid()) return;
        }
    }

    // ---- collect character locations
    const unsigned int text_size = text.size();
    core::array<s32>               indices(text_size);
    core::array<core::position2di> offsets(text_size);
    std::vector<bool>              fallback(text_size);

    for (u32 i = 0; i<text_size; i++)
    {
        wchar_t c = text[i];

        if (c == L'\r' ||          // Windows breaks
            c == L'\n'    )        // Unix breaks
        {
            if(c==L'\r' && text[i+1]==L'\n') c = text[++i];
            offset.Y += (int)(MaxHeight*m_scale);
            offset.X  = position.UpperLeftCorner.X;
            if (hcenter)
                offset.X += (position.getWidth() - text_dimension.Width) >> 1;
            continue;
        }   // if lineBreak

        bool use_fallback_font = false;
        const SFontArea &area  = getAreaFromCharacter(c, &use_fallback_font);
        fallback[i]            = use_fallback_font;
        offset.X              += area.underhang;
        offsets.push_back(offset);
        // Invisible character. add something to the array anyway so that
        // indices from the various arrays remain in sync
        indices.push_back( Invisible.findFirst(c) < 0  ? area.spriteno
                                                       : -1            );
        offset.X += getCharWidth(area, fallback[i]);
    }   // for i<text_size

    // ---- do the actual rendering
    const int indiceAmount                    = indices.size();
    core::array< SGUISprite >& sprites        = SpriteBank->getSprites();
    core::array< core::rect<s32> >& positions = SpriteBank->getPositions();
    core::array< SGUISprite >* fallback_sprites;
    core::array< core::rect<s32> >* fallback_positions;
    if(m_fallback_font!=NULL)
    {
        fallback_sprites   = &m_fallback_font->SpriteBank->getSprites();
        fallback_positions = &m_fallback_font->SpriteBank->getPositions();
    }
    else
    {
        fallback_sprites   = NULL;
        fallback_positions = NULL;
    }

    const int spriteAmount      = sprites.size();
    for (int n=0; n<indiceAmount; n++)
    {
        const int spriteID = indices[n];
        if (!fallback[n] && (spriteID < 0 || spriteID >= spriteAmount)) continue;
        if (indices[n] == -1) continue;

        //assert(sprites[spriteID].Frames.size() > 0);

        const int texID = (fallback[n] ?
                           (*fallback_sprites)[spriteID].Frames[0].textureNumber :
                           sprites[spriteID].Frames[0].textureNumber);

        core::rect<s32> source = (fallback[n] ?
                                  (*fallback_positions)[(*fallback_sprites)[spriteID].Frames[0].rectNumber] :
                                  positions[sprites[spriteID].Frames[0].rectNumber]);

        const TextureInfo& info = (fallback[n] ?
                                   (*(m_fallback_font->m_texture_files.find(texID))).second :
                                   (*(m_texture_files.find(texID))).second
                                   );
        float char_scale = info.m_scale;

        core::dimension2d<s32> size = source.getSize();

        float scale = (fallback[n] ? m_scale*m_fallback_font_scale : m_scale);
        size.Width  = (int)(size.Width  * scale * char_scale);
        size.Height = (int)(size.Height * scale * char_scale);

        // align vertically if character is smaller
        int y_shift = (size.Height < MaxHeight*m_scale ? (int)((MaxHeight*m_scale - size.Height)/2.0f) : 0);

        core::rect<s32> dest(offsets[n] + core::position2di(0, y_shift), size);

        video::ITexture* texture = (fallback[n] ?
                                    m_fallback_font->SpriteBank->getTexture(texID) :
                                    SpriteBank->getTexture(texID) );

        /*
        if (fallback[n])
        {
            Log::info("ScalableFont", "Using fallback font %s; source area is %d, %d; size %d, %d; dest = %d, %d",
                core::stringc(texture->getName()).c_str(), source.UpperLeftCorner.X, source.UpperLeftCorner.Y,
                source.getWidth(), source.getHeight(), offsets[n].X, offsets[n].Y);
        }
        */

        if (texture == NULL)
        {
            // perform lazy loading

            if (fallback[n])
            {
                m_fallback_font->lazyLoadTexture(texID);
                texture = m_fallback_font->SpriteBank->getTexture(texID);
            }
            else
            {
                lazyLoadTexture(texID);
                texture = SpriteBank->getTexture(texID);
            }

            if (texture == NULL)
            {
                Log::warn("ScalableFont", "Character not found in current font");
                continue; // no such character
            }
        }

        if (m_black_border && charCollector == NULL)
        {
            // draw black border
            video::SColor black(color.getAlpha(),0,0,0);

            for (int x_delta=-2; x_delta<=2; x_delta++)
            {
                for (int y_delta=-2; y_delta<=2; y_delta++)
                {
                    if (x_delta == 0 || y_delta == 0) continue;
                    draw2DImage(texture,
                                dest + core::position2d<s32>(x_delta, y_delta),
                                source,
                                clip,
                                black, true);
                }
            }
        }

        if (fallback[n])
        {
            // TODO: don't hardcode colors?
            video::SColor orange(color.getAlpha(), 255, 100, 0);
            video::SColor yellow(color.getAlpha(), 255, 220, 15);
            video::SColor title_colors[] = {orange, yellow, orange, yellow};

            if (charCollector != NULL)
            {
                charCollector->collectChar(texture,
                    dest,
                    source,
                    title_colors);
            }
            else
            {
                draw2DImage(texture,
                    dest,
                    source,
                    clip,
                    title_colors, true);
            }
        }
        else
        {
            if (charCollector != NULL)
            {
                video::SColor colors[] = { color, color, color, color };
                charCollector->collectChar(texture,
                    dest,
                    source,
                    colors);
            }
            else
            {
                draw2DImage(texture,
                    dest,
                    source,
                    clip,
                    color, true);
            }
#ifdef FONT_DEBUG
            video::IVideoDriver* driver = GUIEngine::getDriver();
            driver->draw2DLine(core::position2d<s32>(dest.UpperLeftCorner.X,  dest.UpperLeftCorner.Y),
                               core::position2d<s32>(dest.UpperLeftCorner.X,  dest.LowerRightCorner.Y),
                               video::SColor(255, 255,0,0));
            driver->draw2DLine(core::position2d<s32>(dest.LowerRightCorner.X, dest.LowerRightCorner.Y),
                               core::position2d<s32>(dest.LowerRightCorner.X, dest.UpperLeftCorner.Y),
                               video::SColor(255, 255,0,0));
            driver->draw2DLine(core::position2d<s32>(dest.LowerRightCorner.X, dest.LowerRightCorner.Y),
                               core::position2d<s32>(dest.UpperLeftCorner.X,  dest.LowerRightCorner.Y),
                               video::SColor(255, 255,0,0));
            driver->draw2DLine(core::position2d<s32>(dest.UpperLeftCorner.X,  dest.UpperLeftCorner.Y),
                               core::position2d<s32>(dest.LowerRightCorner.X, dest.UpperLeftCorner.Y),
                               video::SColor(255, 255,0,0));
#endif
        }
    }
}
コード例 #15
0
 void _clear(V& v)  { orange(v, true); }
コード例 #16
0
//--------------------------------------------------------------
void ofApp::setup(){
    numSmallCircles = 41; //11 purple, 7 blue, 5 top right, 11 sleave, 7 but, 14 bottom
    grabbed = false;
    
    
    ofColor purple (161, 99, 128);
    ofColor pink (214, 73, 89);  // 1 pink
    ofColor lightPink (147,131,17);  //2 light pink
    ofColor yellow (212,179,14);  //3 yellow
    ofColor black (44,53,71);  //4 middle black
    ofColor blue (47,96,137);//5 blue
    ofColor green (28,124,92);//6 green
    ofColor orange (228,95,79);//7 orange bottom circles
    ofColor moreYellow (204, 155, 82);
    ofColor orangeLighter (232,105,92);
    ofColor darkBlue (38,81,126);
    
    //purple circle positions 0-11
    circlePositions.push_back(ofPoint(436, 342)); //0
    circlePositions.push_back(ofPoint(446, 358)); //1
    circlePositions.push_back(ofPoint(438, 385)); //2
    circlePositions.push_back(ofPoint(414,352)); //3
    circlePositions.push_back(ofPoint(429, 369)); //4
    circlePositions.push_back(ofPoint(423, 385)); //5
    circlePositions.push_back(ofPoint(425, 395)); //6
    circlePositions.push_back(ofPoint(402,337)); //7
    circlePositions.push_back(ofPoint(403, 376)); //8
    circlePositions.push_back(ofPoint(389, 392)); //9
    circlePositions.push_back(ofPoint(381, 348)); //10
     circlePositions.push_back(ofPoint(382, 365)); //11

    
    for(int i=0; i<11; i++){
       CirclesWoman tempCircle;
        smallCircles.push_back(tempCircle);
    }
    int width = ofRandom(20,30);
    int height = ofRandom(10,20);
    
    smallCircles[1].setup(width, height, pink, lightPink, black, circlePositions[1]);
    smallCircles[2].setup(width, height, purple, yellow, black, circlePositions[2]);
    smallCircles[3].setup(width, height, yellow, pink, black, circlePositions[3]);
    smallCircles[4].setup(width, height, pink, lightPink, black, circlePositions[4]);
    smallCircles[5].setup(width, height, purple, yellow, black, circlePositions[5]);
    smallCircles[6].setup(width, height, yellow, lightPink, black, circlePositions[6]);
    smallCircles[7].setup(width, height, pink, yellow, yellow, circlePositions[7]);
    smallCircles[8].setup(width, height, pink, yellow, black, circlePositions[8]);
    smallCircles[9].setup(width, height, blue, green, green, circlePositions[9]);
    smallCircles[10].setup(width, height, pink, purple, black, circlePositions[10]);
    smallCircles[11].setup(width, height, purple, yellow, black, circlePositions[11]);
    
    //blue circles
    for(int i=11; i<19; i++){
        CirclesWoman tempBlueCircle;
        tempBlueCircle.randomSetup("blue");
         smallCircles.push_back(tempBlueCircle);
        
    }
    //        setup(int _width, int _height, ofColor color1, ofColor color2, ofColor color3 , ofPoint _position)
    
    for(int i=19; i<26; i++){
        CirclesWoman tempButtCircle;
        tempButtCircle.randomSetup("butt");
        smallCircles.push_back(tempButtCircle);
        
    }
    
    for(int i=26; i<41; i++){
        CirclesWoman tempBottomCircle;
        smallCircles.push_back(tempBottomCircle);
    }
    
    smallCircles[26].setup(13.33, 9.33, orange, moreYellow, moreYellow, ofPoint(447,727));
    smallCircles[27].setup(17.33, 18.833, orange, moreYellow, moreYellow, ofPoint(447,738.5));
    smallCircles[28].setup(17.33, 15.75, orange, moreYellow, green, ofPoint(450,753));
    smallCircles[29].setup(16, 11.875, orange, moreYellow, moreYellow, ofPoint(442,769));
    smallCircles[30].setup(17.33, 14.542, orange, moreYellow, green, ofPoint(429,722));
    smallCircles[31].setup(18.267, 14.751, orange, moreYellow, moreYellow, ofPoint(430,733));
    smallCircles[32].setup(24.99, 18.17, orange, orangeLighter, black, ofPoint(430,748));
    smallCircles[33].setup(19.313, 15.34, darkBlue, darkBlue, black, ofPoint(418,762.566));
    smallCircles[34].setup(18.3, 13.602, orange, moreYellow, moreYellow, ofPoint(415.33,720));
    smallCircles[35].setup(23.54, 16.605, orange, orangeLighter, black, ofPoint(408,736));
    smallCircles[36].setup(22, 14, darkBlue, darkBlue, black, ofPoint(389,722));
    smallCircles[37].setup(21, 14, orange, yellow, yellow, ofPoint(385,740));
    smallCircles[38].setup(21, 14, orange, orangeLighter, black, ofPoint(395,750));
    smallCircles[39].setup(21, 18, orange, moreYellow, moreYellow, ofPoint(382,763));
    smallCircles[40].setup(21, 17, orange, moreYellow, moreYellow, ofPoint(404,765));

    
//<-------------- squiggly lines dress ---------------->
    numLines = 30;
    int startingX = 332;
    int endingX = 500;
    int interval = (endingX-startingX)/numLines;
    for(int i=0; i<numLines; i++){
        SquigglyLine tempSquiggle;
        tempSquiggle.setup(startingX + interval*i);
        lines.push_back(tempSquiggle);
    }
    
//<-------------- images ---------------->
    arm.loadImage("arm.png");
    greenCircle.loadImage("green_circle.png");
    orangeBackground.loadImage("orange_background.jpg");
    heads.loadImage("heads.png");
    spiralBackground.loadImage("under_spirals.png");
    background.loadImage("background.jpg");
    man.loadImage("man.png");
    
//<-------------- little squares dress ---------------->
    numLittleSquares = 120;
    for(int i=0; i<numLittleSquares; i++){
        LittleSquares tempSquare;
        tempSquare.setup();
        dressSquares.push_back(tempSquare);
    }
//<-------------- big circles dress ---------------->
    numBigCirclesDress = 10;
//    for(int i=0; i<numBigCirclesDress; i++){
//        bigCirclesDress tempBigCircle;
//        tempBigCircle.setup();
//        bigCircles.push_back(tempBigCircle);
//        
//        
//    }
//
    for(int i=0; i<numBigCirclesDress; i++){
        bigCirclesDress tempBigCircle;
        bigCircles.push_back(tempBigCircle);
    }

    bigCircles[0].setupFixed(ofPoint(411,488),22,16);
    bigCircles[1].setupFixed(ofPoint(412,637),20,16);
    bigCircles[2].setupFixed(ofPoint(457,330),22,14);
    bigCircles[3].setupFixed(ofPoint(417,543),21,15);
    bigCircles[4].setupFixed(ofPoint(342,500),18,11);
    bigCircles[5].setupFixed(ofPoint(377,519),18,13);
    bigCircles[6].setupFixed(ofPoint(449,548),22,16);
    bigCircles[7].setupFixed(ofPoint(388,590),21,15);
    bigCircles[8].setupFixed(ofPoint(392,649),15,11);
    bigCircles[9].setupFixed(ofPoint(465,726),19,15);
    
    //<-------------- spirals ---------------->
    numSpirals = 12;
    
    for(int i=0; i<numSpirals; i++){
        spiral tempSpiral;
        spirals.push_back(tempSpiral);
        //spirals[i].setupRandom();
    }
    
    spirals[0].setup(ofPoint(495,373), 35,35, 4);
    spirals[1].setup(ofPoint(537,355), 52,52, 4);
    spirals[2].setup(ofPoint(560, 506), 40, 38, 4);
    spirals[3].setup(ofPoint(499, 473), 60, 55, 5);
    spirals[4].setup(ofPoint(520, 438), 35, 32, 4);
    spirals[5].setup(ofPoint(553, 414), 29, 29, 3);
    spirals[6].setup(ofPoint(483, 598), 50, 45, 4);
    spirals[7].setup(ofPoint(540, 619), 40, 35, 4);
     spirals[8].setup(ofPoint(595, 554), 34, 32, 3);
     spirals[9].setup(ofPoint(479, 414), 45, 40, 4);
     spirals[10].setup(ofPoint(534, 537), 54, 44, 6);
     spirals[11].setup(ofPoint(490, 530), 36, 31, 4);
//    int posX = 495;
//    float radius = 35;
//    for(var i=0; i<numSpirals; i++){
//        if(posX < 650){
//            posX += numSpirals[i-1].radius/2
//        }
//        spirals[i].setup(ofPoint());
//    }
    
    
}