Esempio n. 1
0
void Scroller::Invalidate(long src, int lines)
{
    if ((src + _scroll >= 320) || (src + _scroll + lines < 0))
        return;

    // Scroll first
    Graphics.Scroll(Mod320(-_scroll));
    
    //  Draw whitespace before image
    if (src < 0)
    {
        int c = min(lines,_scroll);
        FillScrollBG(src,c,-1);
        src += c;
        lines -= c;
    }
        
    short imgLines = lines;
    if (_scrollHeight-src < lines)
        imgLines = _scrollHeight-src;
    if (imgLines > 0)
    {
        DrawBody(src,imgLines);
        src += imgLines;
        lines -= imgLines;
    }
                    
    //  Draw whitespace after image
    if (lines > 0)
        FillScrollBG(src,lines,_scrollHeight);
}
Esempio n. 2
0
void Scroller::DrawBody(long y, int height)
{
    long py = y+_scroll;
    if (py >= 320 || py + height <= 0)
        return;
    int top = Mod320(y);
    int bottom = top + height;
    if (bottom > 320)	 // Wrap across screen bounds from bottom to top
    {
        int h1 = bottom-320;
        int h0 = height-h1;
        DrawBody(y,h0);		// Draw in two slices as this crosses physical bounds of the screen
        DrawBody(y+h0,h1);
        return;
    }
	_drawProc(y,top,height,_ref);
}
Esempio n. 3
0
void DrawActorPics(
	const ActorPics *pics, const Vec2i picPos, const direction_e d)
{
	if (pics->IsDead)
	{
		if (pics->IsDying)
		{
			DrawBody(&gGraphicsDevice, pics, picPos);
		}
	}
	else
	{
		// Draw shadow
		if (!pics->IsTransparent)
		{
			DrawShadow(&gGraphicsDevice, picPos, Vec2iNew(8, 6));
		}
		for (int i = 0; i < 3; i++)
		{
			const Pic *picp = NULL;
			switch (pics->DrawOrder[i])
			{
			case BODY_PART_HEAD:
				picp = pics->Head;
				break;
			case BODY_PART_BODY:
				picp = pics->Body;
				break;
			case BODY_PART_GUN:
				picp = pics->Gun;
				break;
			}
			if (picp == NULL)
			{
				continue;
			}
			const Vec2i drawPos = GetActorDrawOffset(
				picPos, picp, pics->DrawOrder[i], d);
			if (pics->IsTransparent)
			{
				BlitBackground(
					&gGraphicsDevice, picp, drawPos, pics->Tint, true);
			}
			else if (pics->Mask != NULL)
			{
				BlitMasked(&gGraphicsDevice, picp, drawPos, *pics->Mask, true);
			}
			else
			{
				BlitCharMultichannel(
					&gGraphicsDevice, picp, drawPos, pics->Colors);
			}
		}
	}
}
Esempio n. 4
0
//绘图函数,每帧系统要把程序往屏幕上贴之前会发送Paint消息
//参数 pScrBuffer :注册的buf指针
//参数 uWidth	  :buf宽
//参数 uHeight	  :buf高
//int32 TestBox2DLite_Paint(uint16 *pScrBuffer, uint16 uWidth, uint16 uHeight)
iS32 TestBox2DLite_Paint(void)
{
// 	World vWorld;
// 	//MyPair<int, int> MyArbPair;
// 	typedef MyPair<int, int> MyArbPair;
// 	int nTesta=1;
// 	int nTestb=2;
//     vWorld.arbiters.insert(MyArbPair(nTesta, nTestb));
// 	//arbiters.insert(ArbPair(key, newArb));
// 	 return 1;
//	static int32 iLastTime = gettime() - 33;
	static iS32 iLastTime = i51AdeOsGetTick() - 33;
	timeStep = (i51AdeOsGetTick() - iLastTime) / 1000.0f;
	if (timeStep > 0.05f)
		timeStep = 0.05f;
	iLastTime = i51AdeOsGetTick();
//i51AdeOsLog(0,"start TestBox2DLite_Paint");
//    memset( pScrBuffer, 0, uWidth * uHeight * 2 );
i51KitG2CleanScreen(0XAA,iNULL);

////i51AdeOsLog(0,"demoIndex=%d",demoIndex);

 //   if (demoIndex > 0)
//        DrawText(5, 15, demoStrings[demoIndex-1]);
    DrawText(5, 45, "Keys: 1-9 Demos");
    if (demoIndex > 0)
        DrawText(5, 75, "OK to Launch the Bomb");
//iLog("DrawText");
//i51AdeOsLog(0,"Draw Text!");
    world.Step(timeStep);
//iLog("world.Step(timeStep)");
//i51AdeOsLog(0,"numBodies=%d,numJoints=%d",numBodies,numJoints);
//iLog("numJoints=%d",numJoints);
    for (int i = 0; i < numBodies; ++i)
    {
 //   	iLog("i=%d",i);
        DrawBody(bodies + i);
    }

    for (int i = 0; i < numJoints; ++i)
    {
  //  	iLog("i=%d",i);
        DrawJoint(joints + i);
    }
//i51AdeOsLog(0,"Draw End!");

i51KitG2Update();
//i51AdeOsLog(0,"End TestBox2DLite_Paint");
    return 1;
}
Esempio n. 5
0
/// <summary>
/// Draws a 32 bit per pixel image of previously specified width, height, and stride to the associated hwnd
/// </summary>
/// <param name="pImage">image data in RGBX format</param>
/// <param name="cbImage">size of image data in bytes</param>
/// <param name="vBodies">vector of bodies to draw</param>
/// <returns>indicates success or failure</returns>
HRESULT ImageRenderer::Draw(BYTE* pImage, unsigned long cbImage, std::vector<Body> &vBodies)
{
    // incorrectly sized image data passed in
    if (cbImage < ((m_sourceHeight - 1) * m_sourceStride) + (m_sourceWidth * 4))
    {
        return E_INVALIDARG;
    }

    // create the resources for this draw device
    // they will be recreated if previously lost
    HRESULT hr = EnsureResources();

    if (FAILED(hr))
    {
        return hr;
    }
    
    // Copy the image that was passed in into the direct2d bitmap
    hr = m_pBitmap->CopyFromMemory(NULL, pImage, m_sourceStride);

    if (FAILED(hr))
    {
        return hr;
    }
       
    m_pRenderTarget->BeginDraw();

    // Draw the bitmap stretched to the size of the window
    m_pRenderTarget->DrawBitmap(m_pBitmap);
      
	for (unsigned int i = 0; i < vBodies.size(); i++)
	{
		if (vBodies[i].bTracked)
		{
			DrawBody(vBodies[i]);
		}
	}

    hr = m_pRenderTarget->EndDraw();

    // Device lost, need to recreate the render target
    // We'll dispose it now and retry drawing
    if (hr == D2DERR_RECREATE_TARGET)
    {
        hr = S_OK;
        DiscardResources();
    }

    return hr;
}
Esempio n. 6
0
/*
안드로이드 전체 모습을 그리는 함수
*/
void DrawAndroid(){
	DrawBody(0, 0, 0, 0); // 몸통 함수 호출
	Drawneck(); // 목함수 호출
	DrawHead(); // 머리 호출
	DrawR_Arm(R_Arm_x, 1, 0, 0);//우측팔뚝
	if (key == ROCKET) DrawR_HandRocket(); // 로켓모드일때 우측로켓호출
	else DrawR_Hand(R_Arm_y, 1, 0, 0);  //우측팔호출
	DrawL_Arm(L_Arm_x, 1, 0, 0);   //좌측팔뚝
	if (key == ROCKET) DrawL_HandRocket(); // 로켓모드일때 우측로켓호출
	else DrawL_Hand(L_Arm_y, 1, 0, 0);//좌측손호출
	DrawL_Legs(L_Leg_x, 1, 0, 0);  //좌측다리
	DrawL_foot(L_Leg_y, 1, 0, 0);  //좌측발		 
	DrawR_Legs(R_Leg_x, 1, 0, 0);  //우측다리
	DrawR_foot(R_Leg_y, 1, 0, 0);  //우측발	
}
Esempio n. 7
0
void Person::Draw(ModelviewStack* ms)
{
	useLighting(1);

	setColour(1.0, 0.0, 0.0);
	ms->Push();
	{
		ms->Translate(_transform.position);
		
		DrawBody(ms);
		//DrawNeck(ms);
		DrawHead(ms);
		DrawArms(ms);
		DrawLegs(ms);
	}
	ms->Pop();
}
Esempio n. 8
0
void DrawCannon()
{
	//Base
	DrawBase();

	//Wheels
	DrawWheels();

	//WheelDents
	DrawWheelDents();

	//HolderBase
	DrawHolderBase();

	//Holders
	DrawHolders();

	//DrawBody
	DrawBody();
}
Esempio n. 9
0
void SimulationLoop()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	viewNodeBodyCount = 0;
	RenderQuadtree(world._quadtree);

	DrawText(5, 15, demoStrings[demoIndex]);
	DrawText(5, 45, "Keys: 1-9 Demos, Space to Launch the Bomb");
	DrawText(5, 75, (bruteForceHitCalc ? "Brute-force" : "Quadtree"));
	
	std::stringstream s; s << "Collision Checks: " << world._collisionChecks << " Contacts: " << world._contacts << " Updates:  " << world._numUpdates
		<< " MouseNode bodies: " << viewNodeBodyCount;
	DrawText(5, 90, s.str().c_str());

	world._contacts = 0;
	world._numUpdates = 0;
	world._collisionChecks = 0;

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glTranslatef(0.0f, -7.0f, -25.0f);

	timepassed += dt;
	while (timepassed >= mindt)
	{
		world.Step(mindt, bruteForceHitCalc);
		timepassed -= mindt;
	}
	

	for (int i = 0; i < numBodies; ++i)
		DrawBody(bodies + i);

	for (int i = 0; i < numJoints; ++i)
		DrawJoint(joints + i);

	glutSwapBuffers();
}
Esempio n. 10
0
/// <summary>
/// Handle new body data
/// <param name="nTime">timestamp of frame</param>
/// <param name="nBodyCount">body data count</param>
/// <param name="ppBodies">body data in frame</param>
/// </summary>
void CBodyBasics::ProcessBody(INT64 nTime, int nBodyCount, IBody** ppBodies)
{
    if (m_hWnd)
    {
        HRESULT hr = EnsureDirect2DResources();

        DetectionResult nEngaged[6] = { DetectionResult_Unknown };

        int width = 0;
        int height = 0;
        if (SUCCEEDED(hr) && m_pRenderTarget && m_pCoordinateMapper)
        {
            m_pRenderTarget->BeginDraw();
            m_pRenderTarget->Clear();

            RECT rct;
            GetClientRect(GetDlgItem(m_hWnd, IDC_VIDEOVIEW), &rct);
            width = rct.right;
            height = rct.bottom;

            for (int i = 0; i < nBodyCount; ++i)
            {
                nEngaged[i] = DetectionResult_Maybe;

                IBody* pBody = ppBodies[i];
                if (pBody)
                {
                    BOOLEAN bTracked = false;
                    hr = pBody->get_IsTracked(&bTracked);

                    // Engaged()は使えるみたい。これは、視野に入ってきた人を認識するものだろう。
                    hr = pBody->get_Engaged( &nEngaged[i] );
                    // 以下はまだ使えないようだ
                    //hr = pBody->GetAppearanceDetectionResults((UINT)i, &nEngaged[i]);

                    if (SUCCEEDED(hr) && bTracked)
                    {
                        Joint joints[JointType_Count];
                        D2D1_POINT_2F jointPoints[JointType_Count];
                        HandState leftHandState = HandState_Unknown;
                        HandState rightHandState = HandState_Unknown;

                        pBody->get_HandLeftState(&leftHandState);
                        pBody->get_HandRightState(&rightHandState);

                        hr = pBody->GetJoints(_countof(joints), joints);
                        if (SUCCEEDED(hr))
                        {
                            for (int j = 0; j < _countof(joints); ++j)
                            {
                                jointPoints[j] = BodyToScreen(joints[j].Position, width, height);
                            }

                            DrawBody(joints, jointPoints);

                            // ここに頭部に丸を描いて、ボディ番号を表示
                            DrawHead(jointPoints[JointType_Head], i, nEngaged[i]);

                            DrawHand(leftHandState, jointPoints[JointType_HandLeft]);
                            DrawHand(rightHandState, jointPoints[JointType_HandRight]);
                        }
                    }
                }
            }

            hr = m_pRenderTarget->EndDraw();

            // Device lost, need to recreate the render target
            // We'll dispose it now and retry drawing
            if (D2DERR_RECREATE_TARGET == hr)
            {
                hr = S_OK;
                DiscardDirect2DResources();
            }
        }

        if (!m_nStartTime)
        {
            m_nStartTime = nTime;
        }

        double fps = 0.0;

        LARGE_INTEGER qpcNow = {0};
        if (m_fFreq)
        {
            if (QueryPerformanceCounter(&qpcNow))
            {
                if (m_nLastCounter)
                {
                    m_nFramesSinceUpdate++;
                    fps = m_fFreq * m_nFramesSinceUpdate / double(qpcNow.QuadPart - m_nLastCounter);
                }
            }
        }

        WCHAR szStatusMessage[128] ;
        StringCchPrintf( szStatusMessage, _countof(szStatusMessage),
                         L" FPS = %0.2f  Time = %I64d width:%d height:%d",
                         fps, (nTime - m_nStartTime), width, height);

        if (SetStatusMessage(szStatusMessage, 1000, false))
        {
            m_nLastCounter = qpcNow.QuadPart;
            m_nFramesSinceUpdate = 0;
        }
    }
}
Esempio n. 11
0
/// <summary>
/// Handle new body data
/// <param name="nTime">timestamp of frame</param>
/// <param name="nBodyCount">body data count</param>
/// <param name="ppBodies">body data in frame</param>
/// </summary>
void CBodyBasics::ProcessBody(INT64 nTime, int nBodyCount, IBody** ppBodies)
{
   
	//Declare a struct to collect data
	struct FRAME_RESUME actual_frame;
	
	if (m_hWnd)
    {
        HRESULT hr = EnsureDirect2DResources();

        if (SUCCEEDED(hr) && m_pRenderTarget && m_pCoordinateMapper)
        {
            m_pRenderTarget->BeginDraw();
            m_pRenderTarget->Clear();

            RECT rct;
            GetClientRect(GetDlgItem(m_hWnd, IDC_VIDEOVIEW), &rct);
            int width = rct.right;
            int height = rct.bottom;

            for (int i = 0; i < nBodyCount; ++i)
            {
                IBody* pBody = ppBodies[i];
                if (pBody)
                {
                    BOOLEAN bTracked = false;
                    hr = pBody->get_IsTracked(&bTracked);

					//If the person is tracked we assign true '1', else we assign false '0'
					actual_frame.person[i].isTracked = bTracked;

					//If the person is tracked
                    if (SUCCEEDED(hr) && bTracked)
                    {
                        Joint joints[JointType_Count]; 
                        D2D1_POINT_2F jointPoints[JointType_Count];
                        HandState leftHandState = HandState_Unknown;
                        HandState rightHandState = HandState_Unknown;

                        pBody->get_HandLeftState(&leftHandState);
                        pBody->get_HandRightState(&rightHandState);

                        hr = pBody->GetJoints(_countof(joints), joints);
                        if (SUCCEEDED(hr))
                        {
                            
							for (int j = 0; j < _countof(joints); ++j)
                            {
                                jointPoints[j] = BodyToScreen(joints[j].Position, width, height);	

								//If current joint is not tracked
								if (joints[j].TrackingState == TrackingState_NotTracked)
								{
									actual_frame.person[i].body.joint[j].isTracked = 0;
									actual_frame.person[i].body.joint[j].coordinate3D.X = 0;
									actual_frame.person[i].body.joint[j].coordinate3D.Y = 0;
									actual_frame.person[i].body.joint[j].coordinate3D.Z = 0;
									actual_frame.person[i].body.joint[j].coordinate2D.X = 0;
									actual_frame.person[i].body.joint[j].coordinate2D.Y = 0;
								}

								else
								{
									if (joints[j].TrackingState == TrackingState_Tracked)
									{
										actual_frame.person[i].body.joint[j].isTracked = 1;
									}
									else
									{
										if (joints[j].TrackingState == TrackingState_Inferred)
										{
											actual_frame.person[i].body.joint[j].isTracked = 2;
										}
										else
										{
											actual_frame.person[i].body.joint[j].isTracked = 3;
										}
									}

									actual_frame.person[i].body.joint[j].coordinate3D.X = joints[j].Position.X;
									actual_frame.person[i].body.joint[j].coordinate3D.Y = joints[j].Position.Y;
									actual_frame.person[i].body.joint[j].coordinate3D.Z = joints[j].Position.Z;
									actual_frame.person[i].body.joint[j].coordinate2D.X = jointPoints[j].x;
									actual_frame.person[i].body.joint[j].coordinate2D.Y = jointPoints[j].y;
								}

                            }						
											
							
                            DrawBody(joints, jointPoints);

                            DrawHand(leftHandState, jointPoints[JointType_HandLeft]);
                            DrawHand(rightHandState, jointPoints[JointType_HandRight]);
                        }											

						//Gesture values

						//Get body gesture
						//BodyGestureIdentification(actual_frame.person[i], &actual_frame.person[i].bodyGesture.type, &actual_frame.person[i].bodyGesture.parameter1);
						BodyPoseIdentification(actual_frame.person[i], &actual_frame.person[i].bodyPose.type);
						//Get hand gestures
						actual_frame.person[i].leftHandGesture.type = leftHandState;
						actual_frame.person[i].leftHandGesture.parameter1 = 0;
						actual_frame.person[i].rightHandGesture.type = rightHandState;
						actual_frame.person[i].rightHandGesture.parameter1 = 0;


                    }

					//If the person is not tracked put all its values in cero
					else
					{
						//All joints go to zero
						for (int j = 0; j <25; j++)
						{
							actual_frame.person[i].body.joint[j].isTracked = 0;
							actual_frame.person[i].body.joint[j].coordinate3D.X = 0;
							actual_frame.person[i].body.joint[j].coordinate3D.Y = 0;
							actual_frame.person[i].body.joint[j].coordinate3D.Z = 0;
							actual_frame.person[i].body.joint[j].coordinate2D.X = 0;
							actual_frame.person[i].body.joint[j].coordinate2D.Y = 0;
						}

						//All gestures go to zero
						actual_frame.person[i].bodyPose.type = 0;
						actual_frame.person[i].bodyGesture.type = 0;
						actual_frame.person[i].bodyGesture.parameter1 = 0;
						actual_frame.person[i].leftHandGesture.type = 0;
						actual_frame.person[i].leftHandGesture.parameter1 = 0;
						actual_frame.person[i].rightHandGesture.type = 0;
						actual_frame.person[i].rightHandGesture.parameter1 = 0;

					}


                }

           }

		    hr = m_pRenderTarget->EndDraw();

			// Device lost, need to recreate the render target
            // We'll dispose it now and retry drawing
            if (D2DERR_RECREATE_TARGET == hr)
            {
                hr = S_OK;
                DiscardDirect2DResources();
            }
        }

        if (!m_nStartTime)
        {
            m_nStartTime = nTime;
        }

        double fps = 0.0;

        LARGE_INTEGER qpcNow = {0};
        if (m_fFreq)
        {
            if (QueryPerformanceCounter(&qpcNow))
            {
                if (m_nLastCounter)
                {
                    m_nFramesSinceUpdate++;
                    fps = m_fFreq * m_nFramesSinceUpdate / double(qpcNow.QuadPart - m_nLastCounter);
                }
            }
        }

        WCHAR szStatusMessage[64];
        StringCchPrintf(szStatusMessage, _countof(szStatusMessage), L" FPS = %0.2f    Time = %I64d", fps, (nTime - m_nStartTime));

        if (SetStatusMessage(szStatusMessage, 1000, false))
        {
            m_nLastCounter = qpcNow.QuadPart;
            m_nFramesSinceUpdate = 0;
        }
    }

	//Collected results are sent to a file
	write_a_frame_resume_in_file(actual_frame);

}
Esempio n. 12
0
// ************************************************************************** //
// ****************************** Manipulators ****************************** //
// ************************************************************************** //
void Decepticon :: Draw()
{
	glPushMatrix();
		glTranslatef(0, transform_position, 0);
		glRotatef(-bend_angle, -1, 0, 0);

		glPushMatrix();
			glTranslatef(0, -torso_length, 0);
			DrawBody();												// draw body
			glPushMatrix();
				glTranslatef(0, 10, 20);
				glPushMatrix();
					glTranslatef(0, 10, -20);
					if (display_mode == GL_POLYGON)
					{
						GLfloat mat_ambient[] = {1.0, 0.0, 1.0, 1.0};
						GLfloat mat_diffuse[] = {1.0, 0.0, 1.0, 1.0};
						glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
						glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);

						glutSolidTeapot(15);

						mat_ambient[0] = 0.0;
						mat_ambient[1] = 0.0;
						mat_ambient[2] = 1.0;
						mat_diffuse[0] = 0.0;
						mat_diffuse[1] = 0.0;
						mat_diffuse[2] = 0.8;
						glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
						glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
					}  // if statement
				glPopMatrix();
				glRotatef(window_angle, 1, 0, 0);
				DrawWindow();											// draw window
			glPopMatrix();
			glPushMatrix();
				glTranslatef(50, 47.5, 15);
				glRotatef(left_shoulder_forward_angle, -1, 0, 0);
				glRotatef(left_shoulder_outward_angle, 0, 0, 1);
				glTranslatef(0, 0, left_shoulder_back);
				glRotatef(left_shoulder_rotate, 0, 1, 0);
				DrawShoulder();											// draw left shoulder
				glPushMatrix();
					glTranslatef(0, 10, 0);
					glRotatef(left_shoulder_twist_angle, 0, 1, 0);
					DrawUpperArm();										// draw left upper arm
					glPushMatrix();
						glTranslatef(9, -40, 0);
						glRotatef(left_elbow_forward_angle, -1, 0, 0);
						glTranslatef(0, left_lower_arm_retract, 0);
						DrawLowerArm();									// draw left lower arm
					glPopMatrix();
				glPopMatrix();
			glPopMatrix();
			glPushMatrix();
				glTranslatef(-50, 47.5, 15);
				glScalef(-1, 1, 1);
				glRotatef(right_shoulder_forward_angle, 1, 0, 0);
				glRotatef(right_shoulder_outward_angle, 0, 0, 1);
				glTranslatef(0, 0, right_shoulder_back);
				glRotatef(right_shoulder_rotate, 0, 1, 0);
				DrawShoulder();											// draw right shoulder
				glPushMatrix();
					glTranslatef(0, 10, 0);
					glRotatef(right_shoulder_twist_angle, 0, 1, 0);
					DrawUpperArm();										// draw right upper arm
					glPushMatrix();
						glTranslatef(9, -40, 0);
						glRotatef(right_elbow_forward_angle, 1, 0, 0);
						glTranslatef(0, right_lower_arm_retract, 0);
						DrawLowerArm();									// draw right lower arm
					glPopMatrix();
				glPopMatrix();
			glPopMatrix();
			glTranslatef(0, torso_length, 0);
			DrawTorso();												// draw torso
			glPushMatrix();
				glTranslatef(0, -15, 0);
				glRotatef(bend_angle, -1, 0, 0);
				glRotatef(hips_angle, -1, 0, 0);
				DrawHips();												// draw hips
				glPushMatrix();
					glTranslatef(0, -12.5, 15);
					DrawRewind();
					DrawFastForward();
					DrawPlay();
					DrawStop();
					DrawPause();
					glPushMatrix();
						glTranslatef(22.5, -5, -15);
						glTranslatef(0, left_leg_drop, 0);
						glRotatef(left_leg_twist_angle, 0, 1, 0);
						glRotatef(left_leg_forward_angle, -1, 0, 0);
						glRotatef(left_leg_outward_angle, 0, 0, 1);
						glTranslatef(0, left_upper_leg_length, 0);
						DrawUpperLeg();									// draw left upper leg
						glPushMatrix();
							glTranslatef(0, -65, 0);
							glTranslatef(0, left_lower_leg_length, 0);
							glRotatef(left_knee_angle, 1, 0, 0);
							DrawLowerLeg();								// draw left lower leg
							glTranslatef(0, -70, 5);
							glRotatef(left_foot_angle, 1, 0, 0);
							glTranslatef(0, 0, left_foot_retract);
							DrawFoot();									// draw left foot
						glPopMatrix();
					glPopMatrix();
					glPushMatrix();
						glTranslatef(-22.5, -5, -15);
						glTranslatef(0, right_leg_drop, 0);
						glRotatef(right_leg_twist_angle, 0, -1, 0);
						glRotatef(right_leg_forward_angle, -1, 0, 0);
						glRotatef(right_leg_outward_angle, 0, 0, -1);
						glTranslatef(0, right_upper_leg_length, 0);
						DrawUpperLeg();									// draw right upper leg
						glPushMatrix();
							glTranslatef(0, -65, 0);
							glScalef(-1, 1, 1);
							glTranslatef(0, right_lower_leg_length, 0);
							glRotatef(right_knee_angle, 1, 0, 0);
							DrawLowerLeg();								// draw right lower leg
							glTranslatef(0, -70, 5);
							glRotatef(right_foot_angle, 1, 0, 0);
							glTranslatef(0, 0, right_foot_retract);
							DrawFoot();									// draw right foot
						glPopMatrix();
					glPopMatrix();
				glPopMatrix();
			glPopMatrix();
		glPopMatrix();

	glPopMatrix();
}  // DrawSoundwave
Esempio n. 13
0
// This function does any needed initialization on the rendering
// context. 
void SetupRC()
    {
    GLint iWidth, iHeight,iComponents;
    GLenum eFormat;
    GLbyte *pBytes;
    
    GLfloat fAmbLight[] =   { 0.1f, 0.1f, 0.1f, 0.0f };
    GLfloat fDiffLight[] =  { 1.0f, 1.0f, 1.0f, 0.0f };
    GLfloat fSpecLight[] = { 0.5f, 0.5f, 0.5f, 0.0f };
    GLfloat lightPos[] = { -100.0f, 100.0f, 100.0f, 1.0f };
    GLfloat fScale = 0.01f;

    // Bluish background
    glClearColor(0.0f, 0.0f, .50f, 1.0f );
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
        
    // Lit texture environment
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    
    glGenTextures(2, textureObjects);
    
    // Load the body texture
    glBindTexture(GL_TEXTURE_2D, textureObjects[BODY_TEXTURE]);
    pBytes = gltLoadTGA("BODY.tga", &iWidth, &iHeight, &iComponents, &eFormat);    
    glTexImage2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, eFormat, GL_UNSIGNED_BYTE, (void *)pBytes);
    free(pBytes);
    
    GLfloat fLargest;
    glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &fLargest);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, fLargest);
    
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    
    glBindTexture(GL_TEXTURE_2D, textureObjects[GLASS_TEXTURE]);
    pBytes = gltLoadTGA("glass.tga", &iWidth, &iHeight, &iComponents, &eFormat);    
    glTexImage2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, eFormat, GL_UNSIGNED_BYTE, (void *)pBytes);
    free(pBytes);
    
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    
    glEnable(GL_TEXTURE_2D);

    // Set up lighting
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_COLOR_MATERIAL);
    glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
    glMaterialfv(GL_FRONT, GL_SPECULAR, fDiffLight);
    glMateriali(GL_FRONT, GL_SHININESS, 128);
    
    glLightfv(GL_LIGHT0, GL_AMBIENT, fAmbLight);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, fDiffLight);
    glLightfv(GL_LIGHT0, GL_SPECULAR, fSpecLight);
    glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);

    // Light never changes, put it here
    glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
    
    glEnable(GL_RESCALE_NORMAL);
    
    bodyList = glGenLists(2);
    glassList = bodyList + 1;
    
    glNewList(bodyList, GL_COMPILE);
        DrawBody();
    glEndList();
    
    glNewList(glassList, GL_COMPILE);
        DrawGlass();
    glEndList();
    }
Esempio n. 14
0
/// <summary>
/// Handle new body data
/// <param name="nTime">timestamp of frame</param>
/// <param name="nBodyCount">body data count</param>
/// <param name="ppBodies">body data in frame</param>
/// </summary>
void CBodyBasics::ProcessBody(INT64 nTime, int nBodyCount, IBody** ppBodies)
{
    if (m_hWnd)
    {
        HRESULT hr = EnsureDirect2DResources();

        if (SUCCEEDED(hr) && m_pRenderTarget && m_pCoordinateMapper)
        {
            m_pRenderTarget->BeginDraw();
            m_pRenderTarget->Clear();

            RECT rct;
            GetClientRect(GetDlgItem(m_hWnd, IDC_VIDEOVIEW), &rct);
            int width = rct.right;
            int height = rct.bottom;

            for (int i = 0; i < nBodyCount; ++i)
            {
                IBody* pBody = ppBodies[i];
                if (pBody)
                {
                    BOOLEAN bTracked = false;
                    hr = pBody->get_IsTracked(&bTracked);

                    if (SUCCEEDED(hr) && bTracked)
                    {
                        Joint joints[JointType_Count]; 
                        D2D1_POINT_2F jointPoints[JointType_Count];
                        HandState leftHandState = HandState_Unknown;
                        HandState rightHandState = HandState_Unknown;

                        pBody->get_HandLeftState(&leftHandState);
                        pBody->get_HandRightState(&rightHandState);

                        hr = pBody->GetJoints(_countof(joints), joints);
                        if (SUCCEEDED(hr))
                        {
                            for (int j = 0; j < _countof(joints); ++j)
                            {
                                jointPoints[j] = BodyToScreen(joints[j].Position, width, height);
                            }

                            DrawBody(joints, jointPoints);

                            DrawHand(leftHandState, jointPoints[JointType_HandLeft]);
                            DrawHand(rightHandState, jointPoints[JointType_HandRight]);
                        }
						
                    }
                }
            }

            hr = m_pRenderTarget->EndDraw();

            // Device lost, need to recreate the render target
            // We'll dispose it now and retry drawing
            if (D2DERR_RECREATE_TARGET == hr)
            {
                hr = S_OK;
                DiscardDirect2DResources();
            }
        }
		FILE *fp;
		if ((fp = fopen("C:\\Users\\tuchiyama\\Desktop\\SpeechBasics-D2D\\speech.txt", "r")) != NULL) {
			if ((fp = fopen("body.txt", "r")) != NULL) {
				std::ifstream ifsa("C:\\Users\\tuchiyama\\Desktop\\SpeechBasics-D2D\\speech.txt");
				std::string linea;
				int si = 0;
				while (std::getline(ifsa, linea)) {
					si++;
				}
				std::ifstream ifsb("body.txt");
				std::string lineb;
				int bi = 0;
				while (std::getline(ifsb, lineb)) {
					bi++;
				}
				if (si > bi) {
					isWrite = true;
					std::ofstream ofs("body.txt", std::ios::app);
					for (int j = 0; j < si - bi; j++) {
						ofs << "start" << std::endl;
					}
				}
			}
		}
		if ((fp = fopen("C:\\Users\\tuchiyama\\Desktop\\SpeechBasics-D2D\\delete.txt", "r")) != NULL) {
			if ((fp = fopen("delete.txt", "r")) != NULL) {
				std::ifstream ifsa("C:\\Users\\tuchiyama\\Desktop\\SpeechBasics-D2D\\delete.txt");
				std::string linea;
				int si = 0;
				while (std::getline(ifsa, linea)) {
					si++;
				}
				std::ifstream ifsb("delete.txt");
				std::string lineb;
				int bi = 0;
				while (std::getline(ifsb, lineb)) {
					bi++;
				}
				if (si > bi) {
					system("ruby C:\\Users\\tuchiyama\\Documents\\odorimming\\make_html.rb undo");
					std::ofstream ofs("delete.txt", std::ios::app);
					for (int j = 0; j < si - bi; j++) {
						ofs << "delete" << std::endl;
					}
				}
			}
		}

        if (!m_nStartTime)
        {
            m_nStartTime = nTime;
        }

        double fps = 0.0;

        LARGE_INTEGER qpcNow = {0};
        if (m_fFreq)
        {
            if (QueryPerformanceCounter(&qpcNow))
            {
                if (m_nLastCounter)
                {
                    m_nFramesSinceUpdate+=1;
                    fps = m_fFreq * m_nFramesSinceUpdate / double(qpcNow.QuadPart - m_nLastCounter);
                }
            }
        }

        WCHAR szStatusMessage[64];
        StringCchPrintf(szStatusMessage, _countof(szStatusMessage), L" FPS = %0.2f    Time = %I64d", fps, (nTime - m_nStartTime));

        if (SetStatusMessage(szStatusMessage, 1000, false))
        {
            m_nLastCounter = qpcNow.QuadPart ;
            m_nFramesSinceUpdate = 0;
        }
    }
}
Esempio n. 15
0
/*
김연아 선수의 모션을 취하는 함수
*/
void Show()
{
	sndPlaySound(TEXT("C:\\sample4.wav"), SND_ASYNC | SND_NOSTOP);
	glLoadIdentity(); //CTM 초기화

	/*
	로봇의 기본적인 관절의 움직임 범위를 제한하는 곳
	*/
	L_Arm_x = (-40) + sin(time2) * 60;//왼쪽 어깨의 각도시작은 -40상태에서 sin()함수를 사용하여 주기적인 움직임 설정
	R_Arm_x = (-80) - L_Arm_x;       //우측 어깨의 각도시작은 -80상태에서 왼쪽어깨 움직임의 반대로 설정
	R_Arm_y = -abs(cos(time2) * 10);  //우측팔뚝 각도조절(팔을 뻗는 움직임표현을위하여 어깨의 sin()함수와 반대인 cos()함수 사용)
	L_Arm_y = -abs(-cos(time2) * 10); //좌측팔뚝 각도조절(팔을 뻗는 움직임표현을위하여 어깨의 sin()함수와 반대인 cos()함수 사용)

	R_Leg_y = abs(-sin(time) * 30 - 30); //우측종아리 각도조절(abs절대값을 줌으로써 종아리가 앞으로 꺾이지 않는 한계점을 설정)
	L_Leg_y = abs(sin(time) * 30 - 30);  //좌측종아리 각도조절(abs절대값을 줌으로써 종아리가 앞으로 꺾이지 않는 한계점을 설정)
	R_Leg_x = sin(time) * 60;          //우측다리는 60도 각도까지 움직이되 sin()함수를 사용하여 주기적인 움직임 설정
	L_Leg_x = -R_Leg_x;             //좌측다리는 우측다리반대로 60도 각도까지 움직이되 sin()함수를 사용하여 주기적인 움직임 설정

	////////////////display////////////////

	cyl = gluNewQuadric(); //실린더 객체 생성
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //초기화
	glMatrixMode(GL_MODELVIEW); //모드 설정

	DrawGround(); //지면 호출
	glLoadIdentity(); //CTM 초기화
	glRotatef(-230.0, 0, 1, 0); //y축기준으로 회전

	/*
	로봇이 피겨동작시 몸이 틀어지는 것을 표현
	*/
	glRotatef(sin(time) * 7, 0, 0, 1); //z축기준으로 7도 까지 각도틀어짐 (sin()함수를 사용하여 주기적인 움직임 설정)
	glRotatef(sin(time) * 7, 0, 1, 0); //y축으로 7도 까지 각도틀어짐 (sin()함수를 사용하여 주기적인 움직임 설정)

	//로봇 몸체 각도 조절
	glTranslatef(0.0, 0.18, 0.0); //y축으로 이동
	glRotatef(80, 1, 0, 0);        //x축 기준으로 회전

	glTranslatef(0.0, 0.5, 0.0);//최초 위치 

	glPushMatrix(); // 처음 저장 위치

	DrawBody(0, 0, 0, 0); // 몸통 함수 호출

	glPopMatrix(); // 처음 저장 좌표로 돌아 간다.
	glPushMatrix();// 처음 저장 좌표 다시 저장

	Drawneck(); // 목함수 호출

	glPopMatrix(); // 처음 저장 좌표로 돌아 간다.
	glPushMatrix();// 처음 저장 좌표 다시 저장

	//머리 위치 설정
	glRotatef(-75, 1, 0, 0); //x축기준으로 회전(머리를 위쪽으로 돌리기)
	glTranslatef(0.0, -0.02, 0.0); //y축으로 이동 (머리 시작점)

	DrawHead(); // 머리 호출

	glPopMatrix(); // 처음 저장 좌표로 돌아 간다.
	glPushMatrix();// 처음 저장 좌표 다시 저장

	//우측전체팔 위치 설정


	DrawR_Arm((R_Arm_y + 30), 1, 0, 0);  //우측팔호출
	DrawR_Hand(-(R_Arm_y - 15), 1, 0, 0); //우측팔뚝

	glPopMatrix(); // 처음 저장 좌표로 돌아 간다.
	glPushMatrix();// 처음 저장 좌표 다시 저장

	//좌측전체팔 위치 설정
	glTranslatef(0.0, -0.16, -0.04);//y축,z축으로 이동(좌측팔 시작점)
	glRotatef(40, 0, 0, 1);     //z축 기준으로 회전

	DrawL_Arm((L_Arm_y + 30), 1, 0, 0);   //좌측팔호출	
	DrawL_Hand(-(L_Arm_y - 15), 1, 0, 0);  //좌측팔뚝

	glPopMatrix(); // 처음 저장 좌표로 돌아 간다.
	glPushMatrix();// 처음 저장 좌표 다시 저장

	//좌측전체 다리 위치 설정
	glTranslatef(0.0, -0.45, -0.25);//y축,z축으로 이동(좌측다리 시작점)
	glRotatef(-90, 1, 0, 0);  //x축 기준으로 회전

	DrawL_Legs(-30, 1, 0, 0);  //좌측다리
	DrawL_foot(10, 1, 0, 0);  //좌측종아리		 

	glPopMatrix(); // 처음 저장 좌표로 돌아 간다.
	glPushMatrix();// 처음 저장 좌표 다시 저장

	//우측전체 다리 위치 설정
	glTranslatef(0.0, -0.5, -0.5);//y축,z축으로 이동(우측다리 시작점)
	glRotatef(-90, 1, 0, 0); //x축 기준으로 회전

	DrawR_Legs(160, 1, 0, 0);  //우측다리
	DrawR_foot(R_Leg_y, 1, 0, 0);  //우측종아리		

	glPopMatrix(); // 처음 저장 좌표로 돌아 간다.

	glutSwapBuffers();
}