Ejemplo n.º 1
0
void myRobot::draw(){

	GLint previousValues[2];
	glGetIntegerv(GL_POLYGON_MODE, previousValues);


	if (wireFrameMode) {
		glPolygonMode(GL_FRONT, GL_LINE);
		glPolygonMode(GL_BACK, GL_LINE);
	}
	
	switch (appearence)
	{
	case 1:
		robotAppearance->apply();
		break;
	case 2: 
		robotAppearance2->apply();
		break;
	case 3: 
		robotAppearance3->apply();
		break;
	default:
		robotAppearance->apply();
		break;
	}

	glPushMatrix();
	glTranslated(translate_coords[0], 0 , translate_coords[2]);
	glRotated(xz_rotate_degree, 0, 1, 0);

	drawFace(0);

	glRotated(90, 0, 1, 0);
	drawFace(1);

	glRotated(90, 0, 1, 0);
	drawFace(2);

	glRotated(90, 0, 1, 0);
	drawFace(3);




	glPopMatrix();

	glPolygonMode(GL_FRONT, previousValues[0]);
	glPolygonMode(GL_BACK, previousValues[1]);


}
Ejemplo n.º 2
0
void drawMesh(carve::mesh::Mesh<3> *mesh, float r, float g, float b, float a) {
  glColor4f(r, g, b, a);

  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  glBegin(GL_TRIANGLES);

  std::vector<carve::mesh::Vertex<3> *> v;

  for (size_t i = 0, l = mesh->faces.size(); i != l; ++i) {
    carve::mesh::Face<3> *f = mesh->faces[i];
    if (f->nVertices() == 3) {
      glNormal3dv(f->plane.N.v);
      f->getVertices(v);
      glVertex(v[0]->v);
      glVertex(v[1]->v);
      glVertex(v[2]->v);
    }
  }
  glEnd();

  for (size_t i = 0, l = mesh->faces.size(); i != l; ++i) {
    carve::mesh::Face<3> *f = mesh->faces[i];
    if (f->nVertices() != 3) {
      drawFace(f, cRGBA(r, g, b, a));
    }
  }
}
Ejemplo n.º 3
0
void glutDisplay (void)

{

    if (!winH)

        return;



    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);



	glMatrixMode (GL_MODELVIEW);

	glLoadIdentity ();

	glTranslatef (0, 0, -50); /* eye position */



    drawFace ();

    drawSphere ();



	glutSwapBuffers();

}
Ejemplo n.º 4
0
void Matatas(double time){
   static double prev_time = 0.0;
   GLuint loc;
   float tmatrix[16];
   float rmatrix[16];
   float mmatrix[16];

   translate(tmatrix, -0.4, 3.0, -7.0);
   rotate(rmatrix, 0.0, 0.0, 4.1);
   matrixMultiply4x4(rmatrix, tmatrix, mmatrix);
   /* 30fps video playback */
   if(time - prev_time > 0.03){
      getNextFrame(matat);
      updateFace(matat.buffer, armface);
      prev_time = time;
      matatpos++;
   }

   glUseProgram(armface->shader);
   loc = glGetUniformLocation(armface->shader, "pmatrix");
   glUniformMatrix4fv(loc, 1, GL_FALSE, pmatrix);
   loc = glGetUniformLocation(armface->shader, "mmatrix");
   glUniformMatrix4fv(loc, 1, GL_FALSE, mmatrix);
   drawFace(armface);

   if(matatpos > 55){
      rewindDepthVideo(matat);
      matatpos = 1;
   }
}
Ejemplo n.º 5
0
/* The last scene. I have made it first. :-)*/
void Headbreak(double time){
   static int i = 0;
   static float rot = 0.0;
   static double prev_time;
   GLuint loc;
   float tmatrix[16];
   float rmatrix[16];
   float mmatrix[16];

   translate(tmatrix, -0.4, 3.0, -7.0);
   rotate(rmatrix, 0.0, 0.0, 4.1);
   matrixMultiply4x4(rmatrix, tmatrix, mmatrix);
   /* 30fps video playback */
   if(time - prev_time > 0.03){
      getNextFrame(head);
      updateFace(head.buffer, face);
      prev_time = time;
      i++;
   }

   glUseProgram(face->shader);
   loc = glGetUniformLocation(face->shader, "pmatrix");
   glUniformMatrix4fv(loc, 1, GL_FALSE, pmatrix);
   loc = glGetUniformLocation(face->shader, "mmatrix");
   glUniformMatrix4fv(loc, 1, GL_FALSE, mmatrix);
   drawFace(face);

   rot += 0.05;
   if(i > 87){
      rewindDepthVideo(head);
      i = 1;
   }
}
		void drawfish()
		{
			glBegin(GL_TRIANGLES);
			glColor3f(1,0,0);
			drawFace(p[0],p[1],p[2]);

			glEnd();
		}
Ejemplo n.º 7
0
//--------------------------------------------------------------
void ofxCubeMap::debugDrawCubemapFaces( float _faceSize, float _border )
{
    for( int i = 0; i < 6; i++ )
    {
        int tmpX = (i * _faceSize) + (i * _border);
        int tmpY = 0;
        drawFace( GL_TEXTURE_CUBE_MAP_POSITIVE_X + i , tmpX, tmpY, _faceSize, _faceSize );
    }
}
Ejemplo n.º 8
0
/**
 * Method for drawing an object
 * @param *object The object to draw in the scene
 */
void Scene::drawObject(objLoader* object)
{
	for(int i = 0; i < object->faceCount; i++)
	{
		glPushMatrix();
		drawFace(object, i);
		glPopMatrix();
	}
}
Ejemplo n.º 9
0
void drawCube(Cube *cube)
{
    int i;

    for(i = 0; i < 6; i++)
    {
        drawFace(&cube->face[i], RENDER_MODE);
    }
}
Ejemplo n.º 10
0
void OpenGLRenderer::drawCube(Texture **textures) {
	glEnable(GL_TEXTURE_2D);
	glDepthMask(GL_FALSE);

	for (uint i = 0; i < 6; i++) {
		drawFace(i, textures[i]);
	}

	glDepthMask(GL_TRUE);
}
Ejemplo n.º 11
0
void TinyGLRenderer::drawCube(Texture **textures) {
	tglEnable(TGL_TEXTURE_2D);
	tglDepthMask(TGL_FALSE);

	for (uint i = 0; i < 6; i++) {
		drawFace(i, textures[i]);
	}

	tglDepthMask(TGL_TRUE);
}
Ejemplo n.º 12
0
void TrackFace::on_recognition_clicked()
{
    TrackFace::capture.open(0);
    string windowName="Track Face";
    cv::namedWindow(windowName.c_str(), cv::WINDOW_AUTOSIZE);
    moveWindow(windowName.c_str(), window_x, window_y);
    setMouseCallback(windowName.c_str(), trackFaceCallBack, NULL);

    while (true)
    {
        cv::Mat frame, buffer;
        if (!capture.isOpened()) break;

        capture >> buffer;
        cv::resize(buffer, frame,Size(buffer.cols/2,buffer.rows/2),0,0,INTER_LINEAR);

        vector<Rect_<int> > faces=haar_faces(frame);

        for (size_t i=0;i<faces.size();i++)
        {
            cv::Mat face_resized=resizeRecognitionFace(frame, faces[i]);

            int prediction=model->predict(face_resized);

            double confidence=0.0;
            model->predict(face_resized, prediction, confidence);

            cout << confidence << endl;

            string box_text="";
            if (confidence<=2400)
                box_text="Prediction is family";
            else box_text="Prediction is stranger";

            //string box_text=format("Prediction is %s", names[prediction].c_str());

            drawFace(frame, faces[i], box_text);
        }

        putText(frame, "Recognizing Face", Point(frame.cols/2-100, 30), FONT_HERSHEY_PLAIN, 1.5, CV_RGB(0,0,255),2.0);

        cv::imshow(windowName.c_str(), frame);
        while (cv::waitKey(5)==27)
        {
            capture.release();
            cv::destroyWindow(windowName.c_str());
        }
    }
}
Ejemplo n.º 13
0
// Draw the rubik's cube to the window with its current rotation, textures, and position.
// To have a multi-texture cube and prevent clipping, additional quads are draw slightly
// raised off the main cube.
void drawRubiksCube() {
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	glLoadIdentity();
	glTranslatef (0, 0, -6);
	
	rotateCube();
	
	glColor3f(0, 0, 0);
	glPushMatrix();
	for( int i = 0; i < 6; i++ ) {
		drawFace(i);
	}
	glPopMatrix();

	SDL_GL_SwapWindow(mainWindow);
}
Ejemplo n.º 14
0
void DrawGame::CircleSprite::draw()
{
  // 显示圆形	
  ofPushMatrix();	 
  ofTranslate(ofPoint(X,Y)); 
  ofRotate(Rot,0,0,1); 
  ofScale(Size,Size,1.0f);   
  drawFill();  
  drawEdge();  
  ofPopMatrix();

  // 显示表情
  ofPushMatrix();
  ofTranslate(ofPoint(X,Y));
  ofRotate(Rot,0,0,1);	 
  ofScale(Size,Size,1.0f);  
  drawFace();
  ofPopMatrix();
}
Ejemplo n.º 15
0
void Marker::render(){
	glPushMatrix();
		glColor3f(mr, mg, mb);
		// Perform transformations here in TRS order
		glTranslatef(px, py, pz);
		//glRotatef(angle,hObj->getDir().x,hObj->getDir().y,hObj->getDir().z);
		drawFace(0, 4, 5, 1); // Draw each face
		drawFace(3, 7, 4, 0);
		drawFace(2, 6, 7, 3);
		drawFace(1, 5, 6, 2);
		drawFace(3, 0, 1, 2);
		drawFace(4, 7, 6, 5);
	glPopMatrix();
}
Ejemplo n.º 16
0
void drawCube(cv::Mat image, geom::Cube cube){
    std::vector<geom::Point2d> points = cube.projectPoints();
    cv::Scalar dark(100,100,100);
    cv::Scalar light(255,255,255);
    
    drawFace(image, points[1], points[3], points[7], points[5], dark);
    drawFace(image, points[7], points[6], points[4], points[5], dark);
    drawFace(image, points[3], points[7], points[6], points[2], dark);
    drawFace(image, points[0], points[4], points[6], points[2], light);
    drawFace(image, points[1], points[3], points[2], points[0], light);
    drawFace(image, points[1], points[5], points[4], points[0], light);
    
    //for (auto point = points.begin(); point != points.end(); ++point) {
    //    cv::circle(image, cv::Point(point->xy[0], point->xy[1]), 5, cv::Scalar(0,255,0), -1);
    //}
}
Ejemplo n.º 17
0
GLuint GLWidget::makeDice( )
{
    GLuint list;
    float w = 0.8;

    list = glGenLists( 1 );

    glNewList( list, GL_COMPILE );


    // one
    drawFace(0,  w);

    // six
    glPushMatrix();
    glRotatef( 180.0, 1.0, 0.0, 0.0 );
    drawFace(5, w);
    glPopMatrix();

    // four on left
    glPushMatrix();
    glRotatef( -90.0, 0.0, 1.0, 0.0 );
    drawFace(3, w);
    glPopMatrix();

    // three on right
    glPushMatrix();
    glRotatef( 90.0, 0.0, 1.0, 0.0 );
    drawFace(2, w);
    glPopMatrix();

    // two
    glPushMatrix();
    glRotatef( 90.0, 1.0, 0.0, 0.0 );
    drawFace(1, w);
    glPopMatrix();

    // five
    glPushMatrix();
    glRotatef( -90.0, 1.0, 0.0, 0.0 );
    drawFace(4, w);
    glPopMatrix();

    glEndList();

    return list;
}
Ejemplo n.º 18
0
void Model::drawObject(bool transparency)
{
    Material* lastMaterial = NULL;

    for(int i = 0; i < (int)objects.size(); i++)
    {
        GroupObject* object = objects[i];

        for(int n = 0; n < (int)object->faces.size(); n++)
        {
            Face* face = object->faces[n];
            Material* material = face->material;

            if(material != lastMaterial)
            {
                if(transparency == false && material->alpha < 1.0f)
                    continue;

                material->Kd[3] = material->alpha;
                glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (GLfloat*)material->Ka);
                glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (GLfloat*)material->Kd);
                glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (GLfloat*)material->Ks);
                glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (GLfloat*)material->Ke);
                glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material->shininess);

                if(material->diffuseMap != NULL)
                {
                    glEnable(GL_TEXTURE_2D);
                    glBindTexture(GL_TEXTURE_2D, material->diffuseMap->texID);
                }
                else
                    glDisable(GL_TEXTURE_2D);

                lastMaterial = material;
            }
            drawFace(*face);
        }
    }
}
Ejemplo n.º 19
0
void MeshCutting::drawPolygonFace(Polyhedron *p)
{
	glBegin(GL_TRIANGLES);
		for (size_t i = 0, l = p->faces.size(); i != l; ++i) {
			carve::poly::Face<3> &f = p->faces[i];
			if (f.nVertices() == 3) {
				glNormal3dv(f.plane_eqn.N.v);
				glVertex3f(f.vertex(0)->v[0], f.vertex(0)->v[1], f.vertex(0)->v[2]);
				glVertex3f(f.vertex(1)->v[0], f.vertex(1)->v[1], f.vertex(1)->v[2]);
				glVertex3f(f.vertex(2)->v[0], f.vertex(2)->v[1], f.vertex(2)->v[2]);
			}
		}
	glEnd();

	for (size_t i = 0, l = p->faces.size(); i != l; ++i) {
		carve::poly::Face<3> &f = p->faces[i];

		if (f.nVertices() != 3) {
			drawFace(&p->faces[i], cRGBA(0.3, 0.6, 0.7, 1.0), false);
		}
	}
}
Ejemplo n.º 20
0
void MeshCutting::drawPolygon(Polyhedron * p)
{
//	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glBegin(GL_TRIANGLES);

	glColor4f(0.3, 0.6, 0.7, 0.8);

	for (size_t i = 0, l = p->faces.size(); i != l; ++i) {
		carve::poly::Face<3> &f = p->faces[i];
		if (f.nVertices() == 3) {
			glNormal3dv(f.plane_eqn.N.v);
			glVertex3f(f.vertex(0)->v[0], f.vertex(0)->v[1], f.vertex(0)->v[2]);
			glVertex3f(f.vertex(1)->v[0], f.vertex(1)->v[1], f.vertex(1)->v[2]);
			glVertex3f(f.vertex(2)->v[0], f.vertex(2)->v[1], f.vertex(2)->v[2]);
		}
	}
	glEnd();

	glColor3f(0,0,1);
	glBegin(GL_LINES);
	for (size_t i = 0, l = p->faces.size(); i != l; ++i) {
		carve::poly::Face<3> &f = p->faces[i];
		for (int j = 0; j < f.nVertices()-1; j++)
		{
			glVertex3f(f.vertex(j)->v[0], f.vertex(j)->v[1], f.vertex(j)->v[2]);
			glVertex3f(f.vertex(j+1)->v[0], f.vertex(j+1)->v[1], f.vertex(j+1)->v[2]);
		}
	}
	glEnd();

	for (size_t i = 0, l = p->faces.size(); i != l; ++i) {
		carve::poly::Face<3> &f = p->faces[i];

		if (f.nVertices() != 3) {
			drawFace(&p->faces[i], cRGBA(0.3, 0.6, 0.7, 1.0), false);
		}
	}

}
Ejemplo n.º 21
0
void OGL_Box::render(){
	glPushMatrix();
		glEnable(GL_TEXTURE_2D);  
		glBindTexture(GL_TEXTURE_2D, texture);
		glColor3f(r, g, b);
		// Perform transformations here in TRS order
		glTranslatef(hObj->getPos().x, hObj->getPos().y, hObj->getPos().z);
		glRotatef(angle,hObj->getDir().x,hObj->getDir().y,hObj->getDir().z);
		drawFace(0, 4, 5, 1); // Draw each face
		drawFace(3, 7, 4, 0);
		drawFace(2, 6, 7, 3);
		drawFace(1, 5, 6, 2);
		drawFace(3, 0, 1, 2);
		drawFace(4, 7, 6, 5);
		glDisable(GL_TEXTURE_2D);
	glPopMatrix();
}
Ejemplo n.º 22
0
void OGL_Level::render(){
	float matSpec[] = {1.0f, 0.0f, 0.0f, 1.0f };
	float matShiny[] = {100.0 };  //128 is max value
	glPushMatrix();
		glMaterialfv(GL_FRONT, GL_AMBIENT, matSpec);
		glMaterialfv(GL_FRONT, GL_SPECULAR, matSpec);
		glMaterialfv(GL_FRONT, GL_SHININESS, matShiny);
		glColor3f(r, g, b);
		// Perform transformations here in TRS order
		glTranslatef(hObj->getPos().x, hObj->getPos().y, hObj->getPos().z);
		glRotatef(angle,hObj->getDir().x,hObj->getDir().y,hObj->getDir().z);
		drawFace(0, 4, 5, 1, 1.0f, 1.0f, 1.0f); // Draw each face
		drawFace(3, 7, 4, 0, 1.0f, 1.0f, 1.0f);
		drawFace(2, 6, 7, 3, 1.0f, 1.0f, 1.0f);
		drawFace(1, 5, 6, 2, 1.0f, 1.0f, 1.0f);
		drawFace(3, 0, 1, 2, 1.0f, 1.0f, 1.0f);
		drawFace(4, 7, 6, 5, 1.0f, 1.0f, 1.0f);
	glPopMatrix();
	glDisable(GL_TEXTURE_2D);
}
Ejemplo n.º 23
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { //window procedure is always defined so
    HDC hDc;
    RECT rect;
    SIZE size;
    PAINTSTRUCT ps;
    COLORREF face_color = RGB(224, 81, 81);
    COLORREF BkButton = RGB(224, 81, 81);
    COLORREF BkColors[] = {RGB(117, 163, 209), RGB(255, 212, 82)};
    COLORREF TextColors[] = {RGB(0, 0, 0), RGB(255, 255, 255)};
    HPEN myPen, hOldPen, hFacePen;
    LPDRAWITEMSTRUCT pdis = (DRAWITEMSTRUCT*)lParam;
    char text[] = "You clicked me!";
    char new_text[] = "Never too late!";
    char szBtnText1[] = "Text";
    char szBtnText2[] = "Rectagle";
    HFONT fontOutputText;

    switch(iMsg)    {
        case WM_CREATE:
            createButtons(hwnd, button_width, button_height);
            break;

        case WM_GETMINMAXINFO:
            MinMaxInfo = (PMINMAXINFO)lParam;
            MinMaxInfo->ptMinTrackSize.x = 300;
            MinMaxInfo->ptMinTrackSize.y = 350;
            MinMaxInfo->ptMaxTrackSize.x = 900;
            MinMaxInfo->ptMaxTrackSize.y = 600;
            break;

        case WM_COMMAND:
            switch(LOWORD(wParam)) {
                case COLOR_BUTTON:
                    Bkcounter++;
                    Bkcounter = Bkcounter % ARRAYSIZE(BkColors);
                    myBrush = CreateSolidBrush(BkColors[Bkcounter]);
                    break;
                case TEXT_COLOR_BUTTON:
                    Text_bk_color++;
                    Text_bk_color = Text_bk_color % ARRAYSIZE(TextColors);
                    break;
                case TEXT_BUTTON:
                    bText = !bText;
                    break;
                case RECTANGLE_BUTTON:
                    bRectangle = !bRectangle;
                    break;
                case MOOD_BUTTON:
                    bgoodMood = !bgoodMood;
                    break;
            }

            hDc = (HDC) GetDC(hwnd);
            InvalidateRect (hwnd, NULL, TRUE);
            ReleaseDC(hwnd, hDc);
            break;

        case WM_CLOSE:
            if (MessageBox(NULL, "Are you sure you want to quit?",
                           "Confirmation", MB_ICONQUESTION | MB_YESNO) == IDYES)
                DestroyWindow(hwnd);
            break;

        case WM_DRAWITEM:
            if ((UINT)wParam == TEXT_BUTTON) {
                GetTextExtentPoint32(pdis->hDC, szBtnText1, (int) strlen(szBtnText1), &size);
                SetTextColor(pdis->hDC, RGB(51, 51, 51));
                SetBkColor(pdis->hDC, BkButton);

                ExtTextOut(
                    pdis->hDC,
                    ((pdis->rcItem.right - pdis->rcItem.left) - size.cx) / 2,
                    ((pdis->rcItem.bottom - pdis->rcItem.top) - size.cy) / 2,
                    ETO_OPAQUE | ETO_CLIPPED,
                    &pdis->rcItem,
                    szBtnText1,
                    strlen(szBtnText1),
                    NULL);

            } else if((UINT)wParam == RECTANGLE_BUTTON)  {
                GetTextExtentPoint32(pdis->hDC, szBtnText2, (int) strlen(szBtnText2), &size);
                SetTextColor(pdis->hDC, RGB(51, 51, 51));
                SetBkColor(pdis->hDC, BkButton);

                ExtTextOut(
                        pdis->hDC,
                        ((pdis->rcItem.right - pdis->rcItem.left) - size.cx) / 2,
                        ((pdis->rcItem.bottom - pdis->rcItem.top) - size.cy) / 2,
                        ETO_OPAQUE | ETO_CLIPPED,
                        &pdis->rcItem,
                        szBtnText2,
                        strlen(szBtnText2),
                        NULL);
            }
            DrawEdge(
                    pdis->hDC,
                    &pdis->rcItem,
                    (pdis->itemState & ODS_SELECTED ? EDGE_SUNKEN : EDGE_BUMP ),
                    BF_RECT);
            return TRUE;
            break;

        case WM_DESTROY:
            PostQuitMessage(0);
            break;

        case WM_PAINT:
            myBrush = CreateSolidBrush(BkColors[Bkcounter]);
            hDc = BeginPaint (hwnd, &ps) ;
            GetClientRect (hwnd, &rect) ;
            FillRect(hDc, &rect,  myBrush);
            SetBkColor(hDc, BkColors[Bkcounter]);
            SetTextColor(hDc, TextColors[Text_bk_color]);
            DrawText (hDc, TEXT ("Done with Pride and Prejudice by Victor"),
                      -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
            if (bRectangle) {
                COLORREF rectangleColor = RGB(217, 65, 30);
                myPen = CreatePen(PS_SOLID, 2, rectangleColor);
                hOldPen = (HPEN)SelectObject(hDc, myPen);
                Rectangle(hDc, 130, 60, 255, 100);
                rect.left = 131;
                rect.top = 61;
                rect.right = 253;
                rect.bottom = 98;
                FillRect(hDc, &rect,  myBrush);
                SelectObject(hDc, hOldPen);
                DeleteObject(myPen);
            }
            if (bText) {
                TextOut(hDc, 140, 70, text, ARRAYSIZE(text));
            }
            fontOutputText = CreateFont(20,0,0,0,0,0,0,0,0,0,0,0,0,TEXT("Tahoma"));
            SelectObject(hDc, fontOutputText);
            TextOut(hDc, 140, 140, new_text, ARRAYSIZE(new_text));
            drawFace(hDc, hFacePen, hOldPen, face_color);
            EndPaint (hwnd, &ps);
            return 0 ;

        default:
            return DefWindowProc(hwnd, iMsg, wParam, lParam);
    }

    return 0;
};
Ejemplo n.º 24
0
// We are going to override (is that the right word?) the draw()
// method of ModelerView to draw out SampleModel
void SampleModel::draw()
{
	// This call takes care of a lot of the nasty projection 
	// matrix stuff.  Unless you want to fudge directly with the 
	// projection matrix, don't bother with this ...
	ModelerView::draw();

	/*************************************************
	**
	**	NOW SAVE THE CURRENT MODELVIEW MATRIX
	**
	**	At this point in execution, the MODELVIEW matrix contains
	**  ONLY the camera transformation.  We need to save this camera
	**  transformation so that we can use it later (for reasons
	**  explained below).
	**
	*****************************************************/
	cameraMatrix = getModelViewMatrix();

	// draw the sample model
	setAmbientColor(.1f, .1f, .1f);

	//glPushMatrix();

	//glPopMatrix();

	glPushMatrix(); // push identity
	glTranslated(VAL(XPOS), VAL(YPOS), VAL(ZPOS)); // values set by the sliders

	if (VAL(NINJATURTLE))
		setDiffuseColor(COLOR_GREEN);
	else
		setDiffuseColor(.940f, .816f, .811f);

	if (animate)
		glRotated(animHeadAngle, 0.0, 1.0, 0.0);
	if (VAL(EYEBANDANA))
		drawEyeBandana();

	if (!VAL(NINJATURTLE))
		setDiffuseColor(.940f, .816f, .811f);
	drawHead();
	
	if (!VAL(NINJATURTLE)) {
		setDiffuseColor(0, 0, 0);
		drawFace();
		setDiffuseColor(.940f, .816f, .811f);
		drawNeck();
	}

	drawUpperTorso();
	drawLowerTorso();

	if (!VAL(NINJATURTLE))
		setDiffuseColor(.940f, .816f, .811f);
	drawRightHandJoint();
	glPushMatrix();
	if (animate)
		glRotated(animUpperArmAngle, 1.0, 0, 0);
	drawUpperRightHand();
	drawLowerRightHand();
	drawRightHand();
	glPopMatrix();


	drawLeftHandJoint();
	glPushMatrix();
	if (animate)
		glRotated(-animUpperArmAngle, 1.0, 0, 0);
	drawUpperLeftHand();
	drawLowerLeftHand();
	drawLeftHand();
	glPopMatrix();

	drawRightLegJoint();
	drawLeftLegJoint();

	drawUpperRightLeg();
	drawLowerRightLeg();
	drawRightFoot();

	drawUpperLeftLeg();
	drawLowerLeftLeg();
	drawLeftFoot();

	if (VAL(NINJATURTLE))
		drawShell();
	else
		drawTail(); // handle the positioning and hierachical modeling of the tail

	if (VAL(METABALLSKIN)) {
		MetaBalls mb;
		mb.setUpGrid();
		mb.setUpMetaballs();
		mb.evalScalarField();
		mb.draw();
	}

	glPopMatrix();

	/***********************************************
	**
	**	NOW WE WILL ACTUALLY BEGIN DRAWING THE MODEL
	**
	**	Draw your model up to the node where you would like
	**	particles to spawn from.
	**
	**  FYI:  As you call glRotate, glScale, or glTranslate,
	**  OpenGL is multiplying new transformations into the
	**  MODELVIEW matrix.
	**
	********************************************/
	// If particle system exists, draw it
	ParticleSystem *ps = ModelerApplication::Instance()->GetParticleSystem();
	if (ps != NULL) {
		ps->computeForcesAndUpdateParticles(t);
		ps->drawParticles(t, m_camera);
	}
	
	/*************************************************
	**
	**	NOW DO ANY CLOSING CODE
	**
	**	Don't forget that animator requires you to call
	**  endDraw().
	**	
	**************************************************/
	endDraw();
}
Ejemplo n.º 25
0
void BlockType::drawBlock(TriangleCollector *collector, const Block &block) const
{
	collector->setCurrentBlock(block);
	int type = block.getType();
	if (blockTypeSpec[type].type == Type_Cube)
	{
		const Tile &tile = blockTypeSpec[type].tile;
		/*        |y
		 *        |
		 *        1----------2
		 *       /|         /|
		 *      / |        / |
		 *     /  |       /  |
		 *    3---+------4   |
		 *    |   5------+---6------x
		 *    |  /       |  /
		 *    | /        | /
		 *    |/         |/
		 *    7----------8
		 *   /
		 *  /z
		 */
		float3 p1(0, 1, 0);
		float3 p2(1, 1, 0);
		float3 p3(0, 1, 1);
		float3 p4(1, 1, 1);

		float3 p5(0, 0, 0);
		float3 p6(1, 0, 0);
		float3 p7(0, 0, 1);
		float3 p8(1, 0, 1);

		Block b[3][3][3];
		for (int x = -1; x <= 1; x++)
			for (int y = -1; y <= 1; y++)
				for (int z = -1; z <= 1; z++)
					b[x + 1][y + 1][z + 1] = block.getNeighbour(x, y, z);

		drawFace(collector, tile, p4, p2, p8, p6,
			b[2][2][2], b[2][2][1], b[2][2][0],
			b[2][1][2], b[2][1][1], b[2][1][0],
			b[2][0][2], b[2][0][1], b[2][0][0],
			float3(1, 0, 0));

		drawFace(collector, tile, p1, p3, p5, p7,
			b[0][2][0], b[0][2][1], b[0][2][2],
			b[0][1][0], b[0][1][1], b[0][1][2],
			b[0][0][0], b[0][0][1], b[0][0][2],
			float3(-1, 0, 0));

		drawFace(collector, tile, p1, p2, p3, p4,
			b[0][2][0], b[1][2][0], b[2][2][0],
			b[0][2][1], b[1][2][1], b[2][2][1],
			b[0][2][2], b[1][2][2], b[2][2][2],
			float3(0, 1, 0));

		drawFace(collector, tile, p7, p8, p5, p6,
			b[0][0][2], b[1][0][2], b[2][0][2],
			b[0][0][1], b[1][0][1], b[2][0][1],
			b[0][0][0], b[1][0][0], b[2][0][0],
			float3(0, -1, 0));

		drawFace(collector, tile, p3, p4, p7, p8,
			b[0][2][2], b[1][2][2], b[2][2][2],
			b[0][1][2], b[1][1][2], b[2][1][2],
			b[0][0][2], b[1][0][2], b[2][0][2],
			float3(0, 0, 1));

		drawFace(collector, tile, p2, p1, p6, p5,
			b[2][2][0], b[1][2][0], b[0][2][0],
			b[2][1][0], b[1][1][0], b[0][1][0],
			b[2][0][0], b[1][0][0], b[0][0][0],
			float3(0, 0, -1));
	}
}
Ejemplo n.º 26
0
//--------------------------------------------------------------
void ofxCubeMap::drawFace( GLuint _face, float _x, float _y )
{
	drawFace( _face, _x, _y, size, size );
}
void MicroViewProgressBarBase::postInit(){
  drawFace();
  draw(); 
}
Ejemplo n.º 28
0
void TrackFace::on_oneClassClassifier_clicked()
{
    TrackFace::capture.open(0);

    string windowName="Family-Stranger Classifier";
    cv::namedWindow(windowName.c_str(), cv::WINDOW_AUTOSIZE);
    cv::moveWindow(windowName.c_str(), window_x, window_y);

    cv::Mat trainingImages;

    for (int i=0;i<images.size();i++)
        //for (int j=1;j<=10;j++)
        trainingImages.push_back(images[i].reshape(1,1));
    //for (int i=images.size()/3*2;i<images.size();i++)
        //for (int j=1;j<=2;j++)
      //      trainingImages.push_back(images[i].reshape(1,1));

    const unsigned int noFeatures=trainingImages.rows;;
    //const unsigned int featureWidth=trainingImages.cols;

    cout << noFeatures << endl;

    float labelImages[noFeatures];
    for (int i=0;i<noFeatures/3;i++) labelImages[i]=1.0;
    for (int i=noFeatures/3;i<noFeatures/3*2;i++) labelImages[i]=1.0;
    for (int i=noFeatures/3*2;i<noFeatures;i++) labelImages[i]=-1.0;

    trainingImages.convertTo(trainingImages, CV_32FC1);
    trainingImages/=128.0;
    trainingImages-=1;

    cv::Mat labelsMat(noFeatures, 1, CV_32FC1, labelImages);

    cv::SVMParams params;
    params.svm_type=cv::SVM::NU_SVC;
    params.kernel_type=cv::SVM::RBF;
    params.nu=0.4;
    params.gamma=100;
    params.term_crit=cv::TermCriteria(CV_TERMCRIT_ITER, (int)1e7, 1e-6);

    cv::SVM svm;

    svm.train(trainingImages, labelsMat, cv::Mat(), cv::Mat(), params);

    while (true)
    {
        cv::Mat frame, buffer;
        if (!capture.isOpened()) break;

        capture >> buffer;
        cv::resize(buffer, frame,Size(buffer.cols/2,buffer.rows/2),0,0,INTER_LINEAR);

        vector<Rect_<int> > faces=haar_faces(frame);

        for (size_t i=0;i<faces.size();i++)
        {
            cv::Mat face_resized=resizeRecognitionFace(frame, faces[i]);
            face_resized=face_resized.reshape(1,1);
            face_resized.convertTo(face_resized, CV_32FC1);
            float response=svm.predict(face_resized);
            string box_text;

            cout << response << endl;

            if (response==1.0)
            {
                box_text=format("Prediction is family");
                drawFace(frame, faces[i], box_text);
            }
            else
            {
                box_text=format("Prediction is stranger");
                drawFace(frame, faces[i], box_text);
            }
        }

        cv::imshow(windowName.c_str(), frame);
        while (cv::waitKey(5)==27)
        {
            capture.release();
            cv::destroyWindow(windowName.c_str());
        }
    }
}
void SkyBackground::clear(DrawEnv *pEnv)
{
#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
    glPushAttrib(GL_POLYGON_BIT | GL_DEPTH_BUFFER_BIT |
                 GL_LIGHTING_BIT);

    glDisable(GL_LIGHTING);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    glDisable(GL_DEPTH_TEST);

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();

    Matrix m,t;

/*
    action->getCamera()->getViewing(m, viewport->getPixelWidth(),
                                        viewport->getPixelHeight());
    action->getCamera()->getProjectionTranslation(t,
                                        viewport->getPixelWidth(),
                                        viewport->getPixelHeight());
 */

    m = pEnv->getCameraViewing();
    t = pEnv->getCameraProjectionTrans();

    m.multLeft(t);

    if(getBeacon() != NULL)
    {
        getBeacon()->getToWorld(t);
        m.mult(t);
    }

    m[3][0] = m[3][1] = m[3][2] = 0;
    glLoadMatrixf(m.getValues());

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();

    glLoadIdentity();
    glTranslatef(0.f, 0.f, 0.5);
    glScalef(1.f, 1.f, 0.f);

/*
    action->getCamera()->getProjection(m, viewport->getPixelWidth(),
                                           viewport->getPixelHeight());
 */
    m = pEnv->getCameraProjection();

    glMultMatrixf(m.getValues());

    UInt32 i, j;
    UInt32 sr = _sfSphereRes.getValue() + 1;      // sphere resolution

    if(_cosval.size() != sr)
    {
        Real32 da = 2 * Pi / (sr - 1);

        _cosval.resize(sr);
        _sinval.resize(sr);

        for(i = 0; i < sr; ++i)
        {
            _cosval[i] = osgCos(i * da);
            _sinval[i] = osgSin(i * da);
        }
    }

    Real32  vcos1,vsin1,vcos2,vsin2;

    // better always clear and set a defined color...
    glColor3f(1, 1, 1);
	
	if(_mfSkyColor.size() > 0)
	{
		glClearColor(_mfSkyColor[0][0], _mfSkyColor[0][1],
					 _mfSkyColor[0][2], _mfSkyColor[0][2]);
	}
	else
	{
		glClearColor(0, 0, 0, 1);
	}

	glClear(GL_COLOR_BUFFER_BIT);

    if(_mfSkyAngle.size() > 0)
    {
        vcos1 = osgCos(_mfSkyAngle[0]);
        vsin1 = osgSin(_mfSkyAngle[0]);

        glBegin(GL_TRIANGLE_FAN);
        glColor4fv(
            static_cast<const GLfloat *>(_mfSkyColor[0].getValuesRGBA()));
        glVertex3f(0, 1, 0);
        glColor4fv(
            static_cast<const GLfloat *>(_mfSkyColor[1].getValuesRGBA()));

        for(i = 0; i < sr; ++i)
        {
            glVertex3f(vsin1 * _sinval[i], vcos1, vsin1 * _cosval[i]);
        }

        glEnd();


        for(j = 0; j < _mfSkyAngle.size() - 1; ++j)
        {
            Color4f c1, c2;

            c1 = _mfSkyColor[j+1];
            c2 = _mfSkyColor[j+2];

            vcos1 = osgCos(_mfSkyAngle[j  ]);
            vsin1 = osgSin(_mfSkyAngle[j  ]);
            vcos2 = osgCos(_mfSkyAngle[j+1]);
            vsin2 = osgSin(_mfSkyAngle[j+1]);

            glBegin(GL_TRIANGLE_STRIP);

            for(i = 0; i < sr; ++i)
            {
                glColor4fv(static_cast<const GLfloat *>(c1.getValuesRGBA()));
                glVertex3f(vsin1 * _sinval[i], vcos1, vsin1 * _cosval[i]);
                glColor4fv(static_cast<const GLfloat *>(c2.getValuesRGBA()));
                glVertex3f(vsin2 * _sinval[i], vcos2, vsin2 * _cosval[i]);
            }
            glEnd();
        }

        //if(osgAbs(_mfSkyAngle[j] - Pi) > TypeTraits<Real32>::getDefaultEps())
        {
            glBegin(GL_TRIANGLE_FAN);
            glColor4fv(
                static_cast<const GLfloat *>(_mfSkyColor[j+1].getValuesRGBA()));
            glVertex3f(0, -1, 0);
            vcos1 = osgCos(_mfSkyAngle[j]);
            vsin1 = osgSin(_mfSkyAngle[j]);

            for(i = 0; i < sr; ++i)
            {
                glVertex3f(vsin1 * _sinval[i], vcos1, vsin1 * _cosval[i]);
            }

            glEnd();
        }
    }

    // Draw the ground.
    // It's possible to be smarter about this, but for now just overdraw.

    if(_mfGroundAngle.size() > 0)
    {
        vcos1 = -osgCos(_mfGroundAngle[0]);
        vsin1 =  osgSin(_mfGroundAngle[0]);

        glBegin(GL_TRIANGLE_FAN);

        if(_mfGroundColor.size())
        {
            glColor4fv(
                static_cast<const GLfloat* >(
                    _mfGroundColor[0].getValuesRGBA()));
        }

        glVertex3f(0, -1, 0);

        if(_mfGroundColor.size() > 1)
        {
            glColor4fv(
                static_cast<const GLfloat *>(
                    _mfGroundColor[1].getValuesRGBA()));
        }

        for(i = 0; i < sr; ++i)
        {
            glVertex3f(vsin1 * _sinval[i], vcos1, vsin1 * _cosval[i]);
        }

        glEnd();


        for(j = 0; j < _mfGroundAngle.size() - 1; ++j)
        {
            Color4f c1, c2;

            if (_mfGroundColor.size() > j+2)
            {
                c1 = _mfGroundColor[j+1];
                c2 = _mfGroundColor[j+2];
            }

            vcos1 = -osgCos(_mfGroundAngle[j  ]);
            vsin1 =  osgSin(_mfGroundAngle[j  ]);
            vcos2 = -osgCos(_mfGroundAngle[j+1]);
            vsin2 =  osgSin(_mfGroundAngle[j+1]);

            glBegin(GL_TRIANGLE_STRIP);

            for(i = 0; i < sr; ++i)
            {
                glColor4fv(static_cast<const GLfloat *>(c1.getValuesRGBA()));
                glVertex3f(vsin1 * _sinval[i], vcos1, vsin1 * _cosval[i]);
                glColor4fv(static_cast<const GLfloat *>(c2.getValuesRGBA()));
                glVertex3f(vsin2 * _sinval[i], vcos2, vsin2 * _cosval[i]);
            }
            glEnd();
        }
    }

    // now draw the textures, if set
          StateChunk *tchunk = NULL;
    const Vec3f      *pTexCoords;

    pTexCoords = selectTexCoords(
        getMFBackTexCoord()->size() ? &getMFBackTexCoord()->front() : NULL,
        getBackTexture(), 1);

    drawFace(pEnv, getBackTexture(),   tchunk,
                                         Pnt3f( 0.5, -0.5,  0.5),
                                         Pnt3f(-0.5, -0.5,  0.5),
                                         Pnt3f(-0.5,  0.5,  0.5),
                                         Pnt3f( 0.5,  0.5,  0.5),
                                         pTexCoords             );

    pTexCoords = selectTexCoords(
        getMFFrontTexCoord()->size() ? &getMFFrontTexCoord()->front() : NULL,
        getFrontTexture(), 2);

    drawFace(pEnv, getFrontTexture(),  tchunk,
                                         Pnt3f(-0.5, -0.5, -0.5),
                                         Pnt3f( 0.5, -0.5, -0.5),
                                         Pnt3f( 0.5,  0.5, -0.5),
                                         Pnt3f(-0.5,  0.5, -0.5),
                                         pTexCoords              );

    pTexCoords = selectTexCoords(
        getMFBottomTexCoord()->size() ? &getMFBottomTexCoord()->front() : NULL,
        getBottomTexture(), 3);

    drawFace(pEnv, getBottomTexture(), tchunk,
                                         Pnt3f(-0.5, -0.5,  0.5),
                                         Pnt3f( 0.5, -0.5,  0.5),
                                         Pnt3f( 0.5, -0.5, -0.5),
                                         Pnt3f(-0.5, -0.5, -0.5),
                                         pTexCoords              );

    pTexCoords = selectTexCoords(
        getMFTopTexCoord()->size() ? &getMFTopTexCoord()->front() : NULL,
        getTopTexture(), 4);

    drawFace(pEnv, getTopTexture(),    tchunk,
                                         Pnt3f(-0.5,  0.5, -0.5),
                                         Pnt3f( 0.5,  0.5, -0.5),
                                         Pnt3f( 0.5,  0.5,  0.5),
                                         Pnt3f(-0.5,  0.5,  0.5),
                                         pTexCoords              );

    pTexCoords = selectTexCoords(
        getMFLeftTexCoord()->size() ? &getMFLeftTexCoord()->front() : NULL,
        getLeftTexture(), 5);

    drawFace(pEnv, getLeftTexture(),   tchunk,
                                         Pnt3f(-0.5, -0.5,  0.5),
                                         Pnt3f(-0.5, -0.5, -0.5),
                                         Pnt3f(-0.5,  0.5, -0.5),
                                         Pnt3f(-0.5,  0.5,  0.5),
                                         pTexCoords              );

    pTexCoords = selectTexCoords(
        getMFRightTexCoord()->size() ? &getMFRightTexCoord()->front() : NULL,
        getRightTexture(), 6);

    drawFace(pEnv, getRightTexture(),  tchunk,
                                         Pnt3f( 0.5, -0.5, -0.5),
                                         Pnt3f( 0.5, -0.5,  0.5),
                                         Pnt3f( 0.5,  0.5,  0.5),
                                         Pnt3f( 0.5,  0.5, -0.5),
                                         pTexCoords              );
    if(tchunk != NULL)
        tchunk->deactivate(pEnv);

    Int32 bit = getClearStencilBit();

	glClearDepth(1.f);

    if(bit >= 0)
    {
        glClearStencil(bit);
        glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    }
    else
    {
        glClear(GL_DEPTH_BUFFER_BIT);
    }

    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    glPopAttrib();

    glColor3f(1.0, 1.0, 1.0);
#endif
}
Ejemplo n.º 30
0
void TrackFace::on_grabPhoto_clicked()
{
    // new window to collect information
    /*

    transmit data between form is tricky.
    grabForm.show();
    string message=grabForm.getMsg();

    cout << message << endl;
    */

    string name=ui->grabName->text().toStdString();
    cout << name << endl;

    string namepath=iofunctions.addName(name, fn_namedb, fn_path);
    int frames=1;

    int label=0;
    if (!labels.empty()) label=labels[labels.size()-1]+1;

    // Face tracking
    TrackFace::capture.open(0);

    string windowName="Grab Face";
    cv::namedWindow(windowName.c_str(), cv::WINDOW_AUTOSIZE);
    moveWindow(windowName.c_str(), window_x, window_y);
    grab_state=GRABBING_OFF;

    while(true)
    {
        cv::Mat frame, buffer;
        if (!capture.isOpened()) break;

        capture >> buffer;
        cv::resize(buffer, frame,Size(buffer.cols/2,buffer.rows/2),0,0,INTER_LINEAR);
        setMouseCallback(windowName.c_str(), grabFaceCallBack, NULL);

        switch(grab_state)
        {
        case GRABBING_OFF:
        {
            string text=format("Grabbing your face No. %d", frames);
            putText(frame, text, Point(frame.cols/2-250, 100), FONT_HERSHEY_PLAIN, 1.2, CV_RGB(255,0,0),2.0);
            cv::imshow(windowName.c_str(), frame);
            break;
        }
        case GRABBING_ON:
        {
            vector<cv::Rect_<int> > faces=haar_faces(frame);

            if (faces.size()>0)
            {
                size_t n=findMaxFace(faces);

                Mat resizedFace=resizeFace(frame(faces[n]), im_width, im_height);

                string imgPath=namepath+name+"_"+(char)(frames+'A'-1)+".jpg";
                cv::imwrite(imgPath,resizedFace);
                iofunctions.addToTrain(fn_images,"resources/"+name+"/"+name+"_"+(char)(frames+'A'-1)+".jpg", label);

                frames++;

                if (frames>20)
                {
                    grab_state=GRABBING_CLOSE;
                }
                else grab_state=GRABBING_OFF;

                drawFace(frame, faces[n], name);
            }

            cv::imshow(windowName.c_str(), frame);
            break;
        }
        case GRABBING_CLOSE :
        {
            capture.release();
            cv::destroyWindow(windowName.c_str());
            break;
        }
        default: break;
        }

        while (cv::waitKey(5)==27)
        {
            capture.release();
            cv::destroyWindow(windowName.c_str());
        }
    }
}