예제 #1
0
void PolygonShapeBuilder::DrawRectangle(
    const Vector2& position,
    float width,
    float height,
    const Vector2& originPivot,
    const Color& color)
{
    if (width <= 0 || height <= 0) {
        return;
    }

    Vector2 anchorOffset = Vector2{width, height} * originPivot;
    const auto minX = position.X - anchorOffset.X;
    const auto minY = position.Y - anchorOffset.Y;
    const auto maxX = position.X + width - anchorOffset.X;
    const auto maxY = position.Y + height - anchorOffset.Y;

    std::array<Vector3, 4> rectVertices = {{
        Vector3{minX, minY, 0.0f},
        Vector3{minX, maxY, 0.0f},
        Vector3{maxX, maxY, 0.0f},
        Vector3{maxX, minY, 0.0f},
    }};

    auto colorVector = color.ToVector4();

    DrawTriangle(
        rectVertices[0], rectVertices[1], rectVertices[2],
        colorVector, colorVector, colorVector);
    DrawTriangle(
        rectVertices[2], rectVertices[3], rectVertices[0],
        colorVector, colorVector, colorVector);
}
예제 #2
0
// DrawQuads (GL_QUADS)
void nuiSoftwarePainter::DrawQuadStrip(const nuiRenderArray* pArray)
{
  int32 i;
  int32 count = (pArray->GetSize() - 2) / 2;
  for (i = 0; i < count; i++)
  {
    int32 ii = i << 1;

    // Is the quad a special case?
    const std::vector<nuiRenderArray::Vertex>& rCoords = pArray->GetVertices();

    float x0 = rCoords[ii].mX, y0 = rCoords[ii+1].mY;
    float x1 = rCoords[(ii+1)].mX, y1 = rCoords[(ii+1)].mY;
    float x2 = rCoords[(ii+2)].mX, y2 = rCoords[(ii+2)].mY;
    float x3 = rCoords[(ii+3)].mX, y3 = rCoords[(ii+3)].mY;
    if (x0 == x3 && x1 == x2 && y0 == y1 && y2 == y3)
    {
      // This is an axis aligned rectangle
      DrawRectangle(pArray, ii, ii+1, ii+3, ii+2);
    }
    else
    {
      // This is not a special quad, draw two triangles:
      DrawTriangle(pArray, ii, ii+1, ii+2);
      DrawTriangle(pArray, ii+1, ii+3, ii+2);
    }
  }
}
예제 #3
0
void PolygonShapeBuilder::DrawRectangle(
    const Rectangle& sourceRect,
    const Color& color1,
    const Color& color2,
    const Color& color3,
    const Color& color4)
{
    if (sourceRect.Width <= 0 || sourceRect.Height <= 0) {
        return;
    }

    std::array<Vector3, 4> rectVertices = {{
        Vector3{static_cast<float>(sourceRect.GetLeft()), static_cast<float>(sourceRect.Y), 0.0f},
        Vector3{static_cast<float>(sourceRect.GetLeft()), static_cast<float>(sourceRect.Y + sourceRect.Height), 0.0f},
        Vector3{static_cast<float>(sourceRect.GetRight()), static_cast<float>(sourceRect.Y + sourceRect.Height), 0.0f},
        Vector3{static_cast<float>(sourceRect.GetRight()), static_cast<float>(sourceRect.Y), 0.0f},
    }};

    auto colorVector1 = color1.ToVector4();
    auto colorVector2 = color2.ToVector4();
    auto colorVector3 = color3.ToVector4();
    auto colorVector4 = color4.ToVector4();

    DrawTriangle(
        rectVertices[0], rectVertices[1], rectVertices[2],
        colorVector1, colorVector4, colorVector3);
    DrawTriangle(
        rectVertices[2], rectVertices[3], rectVertices[0],
        colorVector3, colorVector2, colorVector1);
}
예제 #4
0
    void KGEDevice::SoftRasterization(HDC hdc)
    {
        submitMesh();
        transformVertexes();
        /// TODO
        /// for test hard code
        DrawPoint(hdc, 100, 100, Vector4(1, 0, 0, 1));
        DrawLine(hdc, 200, 247, 300, 405, Vector4(1, 0, 0, 1));
        DrawTriangle(hdc, 500, 200, 400, 300, 700, 400, Vector4(0, 1, 0, 1));

        int nIDtri = (int)_transformMesh->triList.size();
        for (int i = 0; i<nIDtri; i++){
            const KGETriangle & IDtri = _transformMesh->triList[i];
            const int vID0 = IDtri.vID(0);
            const int vID1 = IDtri.vID(1);
            const int vID2 = IDtri.vID(2);
            if (vID0 == -1)continue;
            KGEVertex v0, v1, v2;
            v0 = _transformMesh->GetVertex(vID0);
            v1 = _transformMesh->GetVertex(vID1);
            v2 = _transformMesh->GetVertex(vID2);

            DrawTriangle(hdc, v0.pos.x, v0.pos.y, v1.pos.x, v1.pos.y, v2.pos.x, v2.pos.y, v0.color);
        }
        /// end test hard code
    }
예제 #5
0
static void DrawTriangleFan(State * state, GLuint index) {
	SelectArrayElement(state, index, state->vertexQueue + state->nextIndex);

	if (state->primitiveState == 3) {
		// even triangle
		GLuint prevIndex = (state->nextIndex - 1) > state->nextIndex ? state->nextIndex + 2 : state->nextIndex - 1;
		GLuint prevIndex2 = (state->nextIndex - 2) > state->nextIndex ? state->nextIndex + 1 : state->nextIndex - 2;
		DrawTriangle(state, state->vertexQueue + prevIndex, state->vertexQueue + prevIndex2, 
				     state->vertexQueue + state->nextIndex);
		state->primitiveState = 2;
	} else if (state->primitiveState == 2) {
		// odd triangle
		GLuint prevIndex = (state->nextIndex - 1) > state->nextIndex ? state->nextIndex + 2 : state->nextIndex - 1;
		GLuint prevIndex2 = (state->nextIndex - 2) > state->nextIndex ? state->nextIndex + 1 : state->nextIndex - 2;
		DrawTriangle(state, state->vertexQueue + prevIndex2, state->vertexQueue + prevIndex, 
					 state->vertexQueue + state->nextIndex);
		state->primitiveState = 3;
	} else if (state->primitiveState == 1) {
		// remember seen second vertex
		state->primitiveState = 2;
	} else if (state->primitiveState == 0) {
		// remember seen first vertex
		state->primitiveState = 1;
	}

	if (++state->nextIndex == 3) {
		state->nextIndex = 1;
	}
}
예제 #6
0
void PolygonShapeBuilder::DrawLine(
    const Vector2& start,
    const Vector2& end,
    const Color& startColor,
    const Color& endColor,
    float weight)
{
    auto halfWeight = weight / 2;

    if (halfWeight <= 0) {
        return;
    }

    auto vec = end - start;
    std::swap(vec.X, vec.Y);

    auto a = Vector2::Normalize(vec * Vector2{1, -1}) * halfWeight;
    auto b = Vector2::Normalize(vec * Vector2{-1, 1}) * halfWeight;

    Vector3 p1 = Vector3{start + a, 0.0f};
    Vector3 p2 = Vector3{start + b, 0.0f};
    Vector3 p3 = Vector3{end + b, 0.0f};
    Vector3 p4 = Vector3{end + a, 0.0f};

    DrawTriangle(p1, p2, p3, startColor, startColor, endColor);
    DrawTriangle(p3, p4, p1, endColor, endColor, startColor);
}
예제 #7
0
파일: Paint2.cpp 프로젝트: kyushu-pc/kpc
void p9(void) {
	SetDrawScreen(DX_SCREEN_BACK);

	char keybuf[256];

	while (ProcessMessage() == 0 && GetHitKeyStateAll(keybuf) == 0 && keybuf[KEY_INPUT_ESCAPE] == 0) {
		ClearDrawScreen();
		DrawLine(10, 10, 200, 10, GetColor(255, 0, 0));
		DrawLine(10, 20, 200, 20, GetColor(0, 255, 0));
		DrawLine(10, 30, 200, 30, GetColor(0, 0, 255));
		SetDrawBlendMode(DX_BLENDMODE_ALPHA, 100);	//	αブレンド
		DrawBox(5, 5, 205, 35, GetColor(255, 255, 255), TRUE);
		SetDrawBlendMode(DX_BLENDMODE_NOBLEND, TRUE);	//	ブレンドなし
		DrawBox(100, 100, 201, 201, GetColor(255, 0, 0), TRUE);
		SetDrawBlendMode(DX_BLENDMODE_ADD, 255);	//	加算ブレンド
		DrawCircle(150, 150, 50, GetColor(0, 255, 255), TRUE);
		SetDrawBlendMode(DX_BLENDMODE_SUB, 255);	//	減算ブレンド
		DrawCircle(150, 150, 30, GetColor(0, 100, 100), TRUE);
		SetDrawBlendMode(DX_BLENDMODE_INVSRC, 255);	//	反転ブレンド
		DrawOval(300, 200, 30, 25, GetColor(0, 0, 0), TRUE);
		SetDrawBlendMode(DX_BLENDMODE_MULA, 255);	//	乗算ブレンド
		DrawOval(300, 200, 25, 30, GetColor(0, 100, 100), TRUE);
		SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 255);
		DrawPixel(320, 240, GetColor(255, 255, 255));
		DrawTriangle(5, 5, 205, 5, 5, 35, GetColor(0, 0, 0), TRUE);
		DrawTriangle(5, 5, 205, 5, 5, 35, GetColor(255, 255, 255), FALSE);

		ScreenFlip();
	}
}
예제 #8
0
void Rat::draw(Maze &maze)
{
    if(maze.current_view == maze.rat_view)
    {
        return; // drawing yourself in rat view looks bad.
    }
    glPushMatrix();
    
    glTranslated(mX, mY, 0.0);//3rd
    glRotated(mDegrees, 0.0, 0.0, 1.0);//2nd
    glScaled(.5, .5, 1);//1st
    glTranslated(-mX, -mY, 0);
    
    glColor3d(.75, .75, .75);
    
    DrawTriangle(mX-.5, mY-.5, mX+.5, mY-.5, mX, mY); //outerearright
    DrawTriangle(mX-.5, mY+.5, mX+.5, mY+.5, mX, mY); //outerearleft
    DrawCircle(mX, mY, .3); //head
    glColor3d(1, .8, .89);
    DrawTriangle(mX-.3, mY-.4, mX+.3, mY-.4, mX, mY-.2); //innerearright
    DrawTriangle(mX-.3, mY+.4, mX+.3, mY+.4, mX, mY+.2); //innerearleft
    glColor3d(1, 1, 1);
    DrawCircle(mX, mY-.1, .1);//eyeright
    DrawCircle(mX, mY+.1, .1);//eyeleft
    glColor3d(0, 0, 0);
    DrawCircle(mX+.05, mY-.1, .05);//pupilright
    DrawCircle(mX+.05, mY+.1, .05);//pupilleft
    DrawCircle(mX+.35, mY, .1);//nose
    glPopMatrix();
}
예제 #9
0
// DrawTrianglesStrip (GL_TRIANGLE_STRIP)
void nuiSoftwarePainter::DrawTrianglesStrip(const nuiRenderArray* pArray)
{
  int32 i;
  int32 count = pArray->GetSize() - 2;
  for (i = 0; i < count; i++)
  {
    if (i & 1)
      DrawTriangle(pArray, i, i + 1, i + 2);
    else
      DrawTriangle(pArray, i + 1, i, i + 2);
  }
}
예제 #10
0
//function to draw
void render()
{
	//set the clear colour
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

	//clear the colour and depth-buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	DrawTriangle(TR1);
	DrawTriangle(TR2);

	//requirte to swap the back and front buffer
	SDL_GL_SwapWindow(window);

}
예제 #11
0
void PolygonShapeBuilder::DrawCircle(
    const Vector3& position,
    float radius,
    int segments,
    const Color& color)
{
    POMDOG_ASSERT(segments >= 3);
    POMDOG_ASSERT(radius >= 0);

    if (radius <= 0) {
        return;
    }

    if (segments < 3) {
        return;
    }

    POMDOG_ASSERT(radius > 0);
    POMDOG_ASSERT(segments >= 3);

    Radian<float> centralAngle = Math::TwoPi<float> / segments;
    auto prevPoint = position + Vector3{radius, 0, 0};

    auto colorVector = color.ToVector4();

    for (int i = 0; i < segments; ++i) {
        auto rad = centralAngle * static_cast<float>(i + 1);
        auto cos = std::cos(rad.value);
        auto sin = std::sin(rad.value);
        auto nextPoint = position + Vector3{radius * Vector2{cos, sin}, 0};
        DrawTriangle(nextPoint, prevPoint, position,
            colorVector, colorVector, colorVector);
        prevPoint = nextPoint;
    }
}
예제 #12
0
void NCLDebug::DrawPolygon(int n_verts, const Vector3* verts, const Vector4& colour)
{
	for (int i = 2; i < n_verts; ++i)
	{
		DrawTriangle(verts[0], verts[i - 1], verts[i], colour);
	}
}
예제 #13
0
//敵弾の表示
void DrawEnemyBullet(){
	for(int i=0; i<EnemyBulletNum; i++)
		if(EnemyBullet[i].flag == true){
			DrawLine((int)EnemyBullet[i].x, (int)EnemyBullet[i].y, (int)EnemyBullet[i].x, (int)(EnemyBullet[i].y-10), GetColor(255,0,0));
			DrawTriangle((int)EnemyBullet[i].x, (int)(EnemyBullet[i].y+5), (int)(EnemyBullet[i].x-3), (int)EnemyBullet[i].y, (int)(EnemyBullet[i].x+3), (int)EnemyBullet[i].y, GetColor(255, 0, 0), TRUE);
		}
}
예제 #14
0
/**
 * Create the region for an OSD slider.
 * Types are: OSD_PLAY_ICON, OSD_PAUSE_ICON, OSD_SPEAKER_ICON, OSD_MUTE_ICON
 */
static subpicture_region_t *OSDIcon(int type, const video_format_t *fmt)
{
    const float size_ratio   = 0.05;
    const float margin_ratio = 0.07;

    const int size   = __MAX(fmt->i_visible_width, fmt->i_visible_height);
    const int width  = size * size_ratio;
    const int height = size * size_ratio;
    const int x      = fmt->i_x_offset + fmt->i_visible_width - margin_ratio * size - width;
    const int y      = fmt->i_y_offset                        + margin_ratio * size;

    subpicture_region_t *r = OSDRegion(__MAX(x, 0),
                                       __MIN(y, (int)fmt->i_visible_height - height),
                                       width, height);
    if (!r)
        return NULL;

    if (type == OSD_PAUSE_ICON) {
        int bar_width = width / 3;
        DrawRect(r, STYLE_FILLED, 0, 0, bar_width - 1, height -1);
        DrawRect(r, STYLE_FILLED, width - bar_width, 0, width - 1, height - 1);
    } else if (type == OSD_PLAY_ICON) {
        int mid   = height >> 1;
        int delta = (width - mid) >> 1;
        int y2    = ((height - 1) >> 1) * 2;
        DrawTriangle(r, STYLE_FILLED, delta, 0, width - delta, y2);
    } else {
예제 #15
0
파일: bullet.c 프로젝트: rolk/ug
void NS_DIM_PREFIX BulletPolygon(DOUBLE *points, INT nb, DOUBLE intensity, long color)
{
  DOUBLE z0, z1, z2;
  POINT p0, p1, p2;
  INT k;

  p0.x = (INT)((*points++) - XShift + 0.5);
  p0.y = (INT)((*points++) - YShift + 0.5);
  if (BulletDim == 3)
    z0   = *points++;
  else
    z0 = 0.0;
  for (k = 1; k < nb-1; k++) {
    p1.x = (INT)((*points++) - XShift + 0.5);
    p1.y = (INT)((*points++) - YShift + 0.5);
    if (BulletDim == 3)
      z1 = *points++;
    else
      z1 = 0.0;
    p2.x = (INT)((*points++) - XShift + 0.5);
    p2.y = (INT)((*points++) - YShift + 0.5);
    if (BulletDim == 3)
      z2 = *points;
    else
      z2 = 0.0;
    points -= 2;
    DrawTriangle(p0, z0, p1, z1, p2, z2, intensity, color);
  }
}
예제 #16
0
void CSplitterControlEx::OnPaint()
{
	CPaintDC dc(this); // device context for painting

	CRect rtClient;
	GetClientRect(rtClient);

	CRect rtButton;

	if (m_nType == SPS_VERTICAL)
	{
		rtButton = rtClient;
		rtButton.top = rtClient.Height()/2 - 25;
		rtButton.bottom = rtClient.Height()/2 + 25;
	}

	if(m_nType == SPS_HORIZONTAL)
	{
		rtButton = rtClient;
		rtButton.left = rtClient.Width()/2 - 25;
		rtButton.right = rtClient.Width()/2 + 25;
	}

	m_rtBtn = rtButton;

	Draw(&dc, rtClient);

	if(m_bHover)
	{
		if(m_bPress)
		{
			dc.FillSolidRect(rtButton, RGB(123, 30, 30));
			DrawTriangle(&dc, rtButton, RGB(155, 85, 85), !m_nflag);
		}
		else
		{
			dc.FillSolidRect(rtButton, RGB(249, 177, 25));	//RGB(90, 13, 13)
			DrawTriangle(&dc, rtButton, RGB(153, 0, 0), !m_nflag);	//RGB(242, 233, 233)
		}
	}
	else
	{
		dc.FillSolidRect(rtButton, RGB(162, 40, 40));
		DrawTriangle(&dc, rtButton, RGB(242, 233, 233), !m_nflag);
	}
}
예제 #17
0
void dSceneRender::DrawCylinder(int segments, dFloat radius, dFloat heigh)
{
	dVector q0 ( heigh / 2.0f, radius, 0.0f, 0.0f);
	dVector q1 (-heigh / 2.0f, radius, 0.0f, 0.0f);
	dMatrix rotation (dPitchMatrix(2.0f * 3.1614f/segments));
	dVector cap0[1024];
	dVector cap1[1024];
	dAssert (segments < sizeof (cap0)/sizeof (cap0[0]));
	cap0[segments] = q0;
	cap1[segments] = q1;
	for (int i = 0; i < segments; i ++) {
		cap0[i] = q0;
		cap1[i] = q1;
		q0 = rotation.RotateVector(q0);
		q1 = rotation.RotateVector(q1);
	}
	dVector normal0 ( 1.0f, 0.0f, 0.0f, 0.0f);
	dVector normal1 (-1.0f, 0.0f, 0.0f, 0.0f);

	BeginTriangle();	
	for (int i = 2; i < segments; i ++) {
		SubmitNormal(normal0);
		DrawTriangle(cap0[0], cap0[i-1], cap0[i]);

		SubmitNormal(normal1);
		DrawTriangle(cap1[0], cap1[i], cap1[i - 1]);
	}

	for (int i = 0; i < segments; i ++) {
		dVector p0 (cap0[i]);
		dVector p1 (cap0[i + 1]);
		dVector p2 (cap1[i + 1]);
		dVector p3 (cap1[i]);

		dVector normal ((p1 - p0) * (p2 - p0));
		normal = normal.Scale (1.0f / dSqrt(normal % normal));

		SubmitNormal(normal);
		DrawTriangle(p0, p2, p1);

		SubmitNormal(normal);
		DrawTriangle(p0, p3, p2);
	}
	End();	
}
예제 #18
0
// DrawTrianglesFan (GL_TRIANGLE_FAN)
void nuiSoftwarePainter::DrawTrianglesFan(const nuiRenderArray* pArray)
{
  int32 i;
  int32 count = pArray->GetSize() - 1;
  for (i = 1; i < count; i++)
  {
    DrawTriangle(pArray, 0, i, i + 1);
  }
}
예제 #19
0
int main()
{
    // Initialization
    //--------------------------------------------------------------------------------------
    int screenWidth = 800;
    int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing");
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        // TODO: Update your variables here
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();

            ClearBackground(RAYWHITE);

            DrawText("some basic shapes available on raylib", 20, 20, 20, DARKGRAY);

            DrawLine(18, 42, screenWidth - 18, 42, BLACK);

            DrawCircle(screenWidth/4, 120, 35, DARKBLUE);
            DrawCircleGradient(screenWidth/4, 220, 60, GREEN, SKYBLUE);
            DrawCircleLines(screenWidth/4, 340, 80, DARKBLUE);

            DrawRectangle(screenWidth/4*2 - 60, 100, 120, 60, RED);
            DrawRectangleGradient(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD);
            DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE);

            DrawTriangle((Vector2){screenWidth/4*3, 80},
                         (Vector2){screenWidth/4*3 - 60, 150},
                         (Vector2){screenWidth/4*3 + 60, 150}, VIOLET);

            DrawTriangleLines((Vector2){screenWidth/4*3, 160},
                              (Vector2){screenWidth/4*3 - 20, 230},
                              (Vector2){screenWidth/4*3 + 20, 230}, DARKBLUE);

            DrawPoly((Vector2){screenWidth/4*3, 320}, 6, 80, 0, BROWN);

        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    CloseWindow();        // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}
예제 #20
0
void CSearchBarCtrl::OnPaint()
{
	CPaintDC dc(this);

	CRect rtTriangle;
	CRect rtBack;
	

	CClientRect	rtClient(this);
	CBufferDC	bufDC(dc.GetSafeHdc(), rtClient);
	rtTriangle.CopyRect(rtClient);

	SendMessage(WM_ERASEBKGND, (WPARAM) bufDC.GetSafeHdc(), 1);

	CSize	sizeIcon;
	CRect	rtIcon;
	CFaceManager::GetInstance()->GetImageSize(m_nCurrentIcon, sizeIcon);
	CenterRect(&rtIcon, rtClient, sizeIcon);

	rtIcon.left = rtClient.left + MARGIN_WIDTH;
	rtIcon.top = rtClient.top + MARGIN_WIDTH;
	rtIcon.right = rtIcon.left + sizeIcon.cx;

	rtBack.left = rtClient.left + 2;
	rtBack.top = rtClient.top + 2;
	rtBack.bottom = rtClient.bottom;
	rtBack.right = sizeIcon.cx - 8;


	if (m_bHover)
	{
		bufDC.FillSolidRect(rtBack, RGB(226,226,226));//RGB(238,236,221)
	}
	else
	{
		bufDC.FillSolidRect(rtBack, RGB(240,240,240));//RGB(238,236,221)
	}

	{
		CPenDC pen(bufDC.GetSafeHdc(), RGB(200,200,200));


		bufDC.MoveTo(rtBack.bottom + 6, rtBack.top - 1);
		bufDC.LineTo(rtBack.bottom + 6, rtBack.right - 5);

	}

	m_ImageList.Draw(&bufDC, m_nCurrentIcon, CPoint(rtIcon.left, rtIcon.top), ILD_NORMAL);

	rtTriangle.left = rtClient.left + MARGIN_WIDTH + 1;
	rtTriangle.bottom = rtClient.bottom - rtClient.Height()/2 + MARGIN_WIDTH;
	rtTriangle.right = rtTriangle.left + sizeIcon.cx;


	DrawTriangle(&bufDC, rtTriangle);

}
예제 #21
0
static void DrawTriangles(State * state, GLuint index) {
	SelectArrayElement(state, index, state->vertexQueue + state->nextIndex++);

	if (state->nextIndex == 3) {
		DrawTriangle(state, state->vertexQueue + 0, state->vertexQueue + 1,
		state->vertexQueue + 2);
		state->nextIndex = 0;
	}
}
예제 #22
0
// DrawTriangles (GL_TRIANGLES)
void nuiSoftwarePainter::DrawTriangles(const nuiRenderArray* pArray)
{
  int32 i;
  int32 count = pArray->GetSize() / 3;
  for (i = 0; i < count; i++)
  {
    uint32 ii = i *3;
    DrawTriangle(pArray, ii, ii+1, ii+2);
  }
}
예제 #23
0
void PolygonShapeBuilder::DrawRectangle(
    const Matrix3x2& matrix,
    const Vector2& position,
    float width,
    float height,
    const Color& color1,
    const Color& color2,
    const Color& color3,
    const Color& color4)
{
    if (width <= 0 || height <= 0) {
        return;
    }

    const auto left = position.X;
    const auto right = position.X + width;

    std::array<Vector3, 4> rectVertices = {{
        Vector3{left, position.Y, 0.0f},
        Vector3{left, position.Y + height, 0.0f},
        Vector3{right, position.Y + height, 0.0f},
        Vector3{right, position.Y, 0.0f},
    }};

    for (auto& vertex : rectVertices) {
        auto vec2 = Vector2::Transform(Vector2{vertex.X, vertex.Y}, matrix);
        vertex.X = vec2.X;
        vertex.Y = vec2.Y;
    }

    auto colorVector1 = color1.ToVector4();
    auto colorVector2 = color2.ToVector4();
    auto colorVector3 = color3.ToVector4();
    auto colorVector4 = color4.ToVector4();

    DrawTriangle(
        rectVertices[0], rectVertices[1], rectVertices[2],
        colorVector1, colorVector4, colorVector3);
    DrawTriangle(
        rectVertices[2], rectVertices[3], rectVertices[0],
        colorVector3, colorVector2, colorVector1);
}
예제 #24
0
void PolygonShapeBuilder::DrawTriangle(
    const Vector3& point1,
    const Vector3& point2,
    const Vector3& point3,
    const Color& color1,
    const Color& color2,
    const Color& color3)
{
    DrawTriangle(point1, point2, point3,
        color1.ToVector4(), color2.ToVector4(), color3.ToVector4());
}
예제 #25
0
void MyConvex::Render(bool only_wireframe, const btVector3& wire_color) const
{
	const float Scale = 1.0f;
	glPushMatrix();

	btScalar glmat[16];	//4x4 column major matrix for OpenGL.
	mTransform.getOpenGLMatrix(glmat);
#ifndef BT_USE_DOUBLE_PRECISION
	glMultMatrixf(&(glmat[0]));
#else
	glMultMatrixd(&(glmat[0]));
#endif
	if(!only_wireframe)
	{
		btVector3 color(0.0f, 0.5f, 1.0f);
		for(int i=0;i<mNbPolys;i++)
		{
			glNormal3f(mPolys[i].mPlane[0], mPolys[i].mPlane[1], mPolys[i].mPlane[2]);

			int NbTris = mPolys[i].mNbVerts-2;
			const btVector3& p0 = mVerts[mPolys[i].mIndices[0]]*Scale;
			for(int j=1;j<=NbTris;j++)
			{
				int k = (j+1)%mPolys[i].mNbVerts;

				const btVector3& p1 = mVerts[mPolys[i].mIndices[j]]*Scale;
				const btVector3& p2 = mVerts[mPolys[i].mIndices[k]]*Scale;

				DrawTriangle(p0, p1, p2, color);
			}
		}
	}

	{
		btVector3 color;
		if(only_wireframe)
			color = wire_color;
		else
			color = btVector3(0.0f, 0.0f, 0.0f);

		for(int i=0;i<mNbPolys;i++)
		{
			for(int j=0;j<mPolys[i].mNbVerts;j++)
			{
				int k = (j+1)%mPolys[i].mNbVerts;
				DrawLine(mVerts[mPolys[i].mIndices[j]]*Scale, mVerts[mPolys[i].mIndices[k]]*Scale, color, 1.0f);
			}
		}
	}

	glPopMatrix();
}
예제 #26
0
void
Compositor::DrawGeometry(const gfx::Rect& aRect,
                         const gfx::IntRect& aClipRect,
                         const EffectChain& aEffectChain,
                         gfx::Float aOpacity,
                         const gfx::Matrix4x4& aTransform,
                         const gfx::Rect& aVisibleRect,
                         const Maybe<gfx::Polygon3D>& aGeometry)
{
  if (!aGeometry) {
    DrawQuad(aRect, aClipRect, aEffectChain,
             aOpacity, aTransform, aVisibleRect);
    return;
  }

  // Cull invisible polygons.
  if (aRect.Intersect(aGeometry->BoundingBox()).IsEmpty()) {
    return;
  }

  gfx::Polygon3D clipped = aGeometry->ClipPolygon(aRect);
  nsTArray<gfx::Triangle> triangles = clipped.ToTriangles();

  for (gfx::Triangle& geometry : triangles) {
    const gfx::Rect intersection = aRect.Intersect(geometry.BoundingBox());

    // Cull invisible triangles.
    if (intersection.IsEmpty()) {
      continue;
    }

    MOZ_ASSERT(aRect.width > 0.0f && aRect.height > 0.0f);
    MOZ_ASSERT(intersection.width > 0.0f && intersection.height > 0.0f);

    gfx::TexturedTriangle triangle(Move(geometry));
    triangle.width = aRect.width;
    triangle.height = aRect.height;

    // Since the texture was created for non-split geometry, we need to
    // update the texture coordinates to account for the split.
    if (aEffectChain.mPrimaryEffect->mType == EffectTypes::RGB) {
      TexturedEffect* texturedEffect =
        static_cast<TexturedEffect*>(aEffectChain.mPrimaryEffect.get());

      UpdateTextureCoordinates(triangle, aRect, intersection,
                               texturedEffect->mTextureCoords);
    }

    DrawTriangle(triangle, aClipRect, aEffectChain,
                 aOpacity, aTransform, aVisibleRect);
  }
}
예제 #27
0
void CPolyCtl::CalcPoints(HDC hdc, const RECT& rc)
{
	const double pi = 3.14159265358979;
	POINT   ptCenter;
	// The radius is the hypotenuse 
	double  dblRadiusx = (rc.right - rc.left) / 2;
	double  dblRadiusy = (rc.bottom - rc.top) / 2;
	// angle is in radians, or radius lengths. 
	double  dblAngle = 4 * pi / 2;          // Start at the top
	double  dblDiff = 2 * pi / m_nSides;   // Angle each side will make

	ptCenter.x = (rc.left + rc.right) / 2;
	ptCenter.y = (rc.top + rc.bottom) / 2;

	POINT radianStart[2];
	radianStart[0].x = ptCenter.x;
	radianStart[0].y = ptCenter.y;
	radianStart[1].x = (long)(dblRadiusx * cos(0) + ptCenter.x + 0.5);
	radianStart[1].y = (long)(dblRadiusy * sin(0) + ptCenter.y + 0.5);

	Polyline(hdc, &radianStart[0], 2);

	// Calculate the points for each side
	int i = 0;
	for (; i < m_nSides; i++)
	{
		// When executing in the Visual C++ Debugger the output isn't directed to DebugView.
		ATLTRACE(_T("Angle in radians: %f\n"), dblAngle);

		m_arrPoint[i].x = (long)(dblRadiusx * cos(dblAngle) + ptCenter.x + 0.5);
		m_arrPoint[i].y = (long)(dblRadiusy * sin(dblAngle) + ptCenter.y + 0.5);

		if ( i > 0)
			DrawTriangle(hdc, ptCenter, m_arrPoint[i-1], m_arrPoint[i]);

		dblAngle += dblDiff;
	}
	DrawTriangle(hdc, ptCenter, m_arrPoint[i-1], m_arrPoint[0]);
}
예제 #28
0
void PolygonShapeBuilder::DrawTriangle(
    const Vector2& point1,
    const Vector2& point2,
    const Vector2& point3,
    const Color& color)
{
    auto colorVector = color.ToVector4();
    DrawTriangle(
        Vector3{point1, 0.0f},
        Vector3{point2, 0.0f},
        Vector3{point3, 0.0f},
        colorVector, colorVector, colorVector);
}
예제 #29
0
void display(void) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    
    glLoadIdentity();
    gluLookAt(0,0,2, 0,0,0, 0,1,0);
    
    glLineWidth(4);
    DrawAxes();
    DrawTriangle();
    glutSolidSphere(0.5,20,20);
    
    glutSwapBuffers();
}
예제 #30
0
void RenderVector(int frameNumber) {
  CanvasT *canvas = R_("Canvas");
  PointT *toDraw = R_("TriangleToDraw");
  MatrixStack2D *ms = R_("ms2d");

  float s = sin(frameNumber * 3.14159265f / 22.5f);
  float c = cos(frameNumber * 3.14159265f / 45.0f);

  StackReset(ms);
  PushTranslation2D(ms, -1.5f, -1.5f);
  PushScaling2D(ms, 20.0f + 10.0f * s, 20.0f + 10.0f * s);
  PushRotation2D(ms, (float)(frameNumber * -3));
  PushTranslation2D(ms, (float)(WIDTH/2) + c * (WIDTH/4), (float)(HEIGHT/2));

  Transform2D(R_("CrossToDraw"), R_("Cross"), 12, GetMatrix2D(ms, 0));

  if (effect == 0) {
    CanvasFill(canvas, 0);
    DrawPolyLine(canvas, R_("CrossToDraw"), 12, TRUE);
  }

  StackReset(ms);
  PushTranslation2D(ms, 5.0f, 10.0f);
  PushScaling2D(ms, 2.5f, 2.5f);
  PushRotation2D(ms, (float)(frameNumber*5*c));
  PushTranslation2D(ms, WIDTH/2 + c * 50, HEIGHT/2 + s * 20);

  Transform2D(R_("TriangleToDraw"), R_("Triangle"), 3, GetMatrix2D(ms, 0));

  frameNumber &= 255;

  if (frameNumber < 128)
    canvas->fg_col = frameNumber * 2;
  else 
    canvas->fg_col = (255 - frameNumber) * 2;

  if (effect == 1) {
    DrawTriangle(canvas,
                 toDraw[0].x, toDraw[0].y,
                 toDraw[1].x, toDraw[1].y,
                 toDraw[2].x, toDraw[2].y);
  }

  if (effect == 2) {
    DrawEllipse(canvas,
                toDraw[1].x, toDraw[1].y,
                30 + c * 15, 30 + s * 15);
  }
}