void RectangleMesh::AllocateResources()
    {
        vertexsData_.clear();
        indexes_.clear();

        VertexsData& data = vertexsData_;

        float halfX = width_ * 0.5f;
        float halfY = height_ * 0.5f;

        VertexData vertexData;
        vertexData.normal_ = Vertex3(0, 0, 1); // always facing forward

        vertexData.position_ = Vertex3(-halfX, -halfY, 0);
		vertexData.uv_[0] = Vertex2(0, 1);
        data.push_back(vertexData);

        vertexData.position_ = Vertex3(halfX, -halfY, 0);
		vertexData.uv_[0] = Vertex2(1, 1);
        data.push_back(vertexData);

        vertexData.position_ = Vertex3(halfX, halfY, 0);
		vertexData.uv_[0] = Vertex2(1, 0);
        data.push_back(vertexData);

        vertexData.position_ = Vertex3(-halfX, halfY, 0);
		vertexData.uv_[0] = Vertex2(0, 0);
        data.push_back(vertexData);

        Mesh::AllocateResources();
    }
  void Console::Draw(IRenderer * GDI)
  {
    if (this->m_btoggle){
      GDI->DrawRectangle(Vertex2(0,0,Color(0.5f,0.5f,0.5f,0.5f)),
        Vertex2(GDI->getWidth(),0,Color(0.5f,0.5f,0.5f,0.5f)),
        Vertex2(GDI->getWidth(),200,Color(0.5f,0.5f,0.5f,0.5f)),
        Vertex2(0,200,Color(0.5f,0.5f,0.5f,0.5f)));

      if (m_lConsole.size() > 0){
        std::list<sMessageLine>::reverse_iterator iter = m_lConsole.rbegin();

        for (int i = 8; i>0; i--){
          if (iter->m_type == C_WARNING){
            GDI->DrawTextW(Vertex2(10, 2 + i*22,Color(1.0f,1.0f,0.0f)),
              iter->m_text);
          }else if (iter->m_type == C_ERROR){
            GDI->DrawTextW(Vertex2(10, 2 + i*22,Color(1.0f,0.0f,0.0f)),
              iter->m_text);
          }else
            GDI->DrawTextW(Vertex2(10, 2 + i*22,Color(1.0f,1.0f,1.0f)),
            iter->m_text);
          ++iter;
          if (iter == m_lConsole.rend())
            break;
        }
      }
    }
  }
Beispiel #3
0
	void CurvePreview::Redraw()
	{
		if (!mCurve)
			return;

		TextureRef texture = mSprite->GetTexture();
		if (!texture || texture->GetSize() != layout->GetSize())
		{
			texture = TextureRef(layout->GetSize(), PixelFormat::R8G8B8A8, Texture::Usage::RenderTarget);
			mSprite->SetTexture(texture);
			mSprite->SetTextureSrcRect(RectI(Vec2I(), texture->GetSize()));
		}

		const Color4 backColor(120, 120, 120, 255);
		const Color4 curveColor(0, 255, 0, 255);

		Camera prevCamera = o2Render.GetCamera();
		Camera currCamera; currCamera.SetRect(mCurve->GetRect());
		currCamera.SetScale(currCamera.GetScale().InvertedY());

		o2Render.SetRenderTexture(texture);
		o2Render.SetCamera(currCamera);
		o2Render.Clear(backColor);

		static Vector<Vertex2> buffer;
		buffer.Clear();

		auto curveColorHex = curveColor.ARGB();

		auto& keys = mCurve->GetKeys();
		for (auto& key : keys)
		{
			buffer.Add(Vertex2(key.position, key.value, curveColorHex, 0, 0));

			auto points = key.GetApproximatedPoints();
			for (int i = 0; i < key.GetApproximatedPointsCount(); i++)
				buffer.Add(Vertex2(points[i], curveColorHex, 0, 0));

			o2Render.DrawAAPolyLine(buffer.Data(), buffer.Count(), 2);
		}

		o2Render.UnbindRenderTexture();
		o2Render.SetCamera(prevCamera);
	}
Beispiel #4
0
// read face correspondences as direct three point mapping --------------------
//
void BspInput::ReadDirectCorrespondences( int& mappingsread )
{
	FaceChunk& facelist = m_baseobject->getFaceList();

	int texmapcount = 0;
	int corrfaceno  = 0;
	for ( corrfaceno = 0; corrfaceno < facelist.getNumElements(); corrfaceno++ ) {
		if ( facelist[ corrfaceno ].FaceTexMapped() )
			++texmapcount;
		if ( texmapcount > mappingsread )
			break;
	}

	if ( corrfaceno == facelist.getNumElements() ) {
		sprintf( line, "%s[Too many mappings specified]: line %d\n",
				 parser_err_str, m_parser_lineno );
		ErrorMessage( line );
		HandleCriticalError();
	}

	double x, y, z;
	ReadThreeDoubles( x, y, z );
	facelist[ corrfaceno ].MapXY( 0 ) = Vertex2( x, y, z );

	for ( int k = 1; k < 6; k++ ) {
		if ( m_input.ReadLine( line, TEXTLINE_MAX ) == NULL )
			ParseError( m_section );
		m_parser_lineno++;
		if ( ( m_scanptr = strtok( line, ",/ \t\n\r" ) ) == NULL )
			continue;
		ReadThreeDoubles( x, y, z );
		if ( k < 3 ) {
			facelist[ corrfaceno ].MapXY( k ) = Vertex2( x, y, z );
		} else {
			facelist[ corrfaceno ].MapUV( k - 3 ) = Vertex2( x, y, z );
		}
	}

	mappingsread++;
}
Beispiel #5
0
bool SimpleUniformGL::InitScene()
{
	glClearColor(bgColor.r, bgColor.g, bgColor.b, bgColor.a);

	std::vector<GLuint> shaders;
	shaders.push_back(GLUtil::CreateShader(GL_VERTEX_SHADER, "SimpleUniformVert.glsl"));
	shaders.push_back(GLUtil::CreateShader(GL_FRAGMENT_SHADER, "SimpleUniformFrag.glsl"));
	shaderProgram = GLUtil::CreateProgram(shaders);
	for_each(shaders.begin(), shaders.end(), glDeleteShader);
	glUseProgram(shaderProgram);

	GLint overrideColor = glGetUniformLocation(shaderProgram, "overrideColor");
	glProgramUniform4f(shaderProgram, overrideColor, 1.0f, 0.0f, 0.0f, 1.0f);

	GLuint bindingPoint = 1;

	float colorsBlock[8] = { 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0, 1.0f };
	GLuint buffer;
	glGenBuffers(1, &buffer);
	glBindBuffer(GL_ARRAY_BUFFER, buffer);
	glBufferData(GL_ARRAY_BUFFER, sizeof(colorsBlock), colorsBlock, GL_DYNAMIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	glBindBufferBase(GL_UNIFORM_BUFFER, bindingPoint, buffer);

	GLuint blockIndex = glGetUniformBlockIndex(shaderProgram, "ColorBlock");
	glUniformBlockBinding(shaderProgram, blockIndex, bindingPoint);

	glCreateVertexArrays(1, &vao);
	glBindVertexArray(vao);

	glCreateBuffers(1, &vbo);
	glNamedBufferData(vbo, sizeof(Data::vertices), Data::vertices, GL_STATIC_DRAW);

	glVertexArrayAttribBinding(vao, 0, 0);
	glVertexArrayAttribBinding(vao, 1, 0);
	glVertexArrayVertexBuffer(vao, 0, vbo, 0, sizeof(Vertex2));

	glEnableVertexArrayAttrib(vao, 0);
	glEnableVertexArrayAttrib(vao, 1);
	glVertexArrayAttribFormat(vao, 0, 4, GL_FLOAT, GL_FALSE, 0);
	glVertexArrayAttribFormat(vao, 1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex2().position));

	return true;
}
void KDTree::Build()
{
	// Compute bounds for kd-tree construction
    vector<BBox> primBounds;
	primBounds.reserve(m_uiNumPrimitives);
	primitives.reserve(m_uiNumPrimitives);

	for (unsigned int i = 0; i < m_uiNumPrimitives; ++i) 
	{ 
		Point Vertex1(m_pPrimitives[i]->GetVertex(0)->Pos);
		Point Vertex2(m_pPrimitives[i]->GetVertex(1)->Pos);
		Point Vertex3(m_pPrimitives[i]->GetVertex(2)->Pos);
		BBox bbox = Union(BBox(Vertex1, Vertex2),Vertex3);

		bounds = Union(bounds, bbox);
        primBounds.push_back(bbox);
		primitives.push_back(KDTreePrimitiveInfo(i, bbox));
    }

    // Allocate working memory for kd-tree construction
    BoundEdge *edges[3];
    for (int i = 0; i < 3; ++i)
        edges[i] = new BoundEdge[2*primitives.size()];
    uint32_t *prims0 = new uint32_t[primitives.size()];
    uint32_t *prims1 = new uint32_t[(maxDepth+1) * primitives.size()];

    // Initialize _primNums_ for kd-tree construction
    uint32_t *primNums = new uint32_t[primitives.size()];
    for (uint32_t i = 0; i < primitives.size(); ++i)
        primNums[i] = i;

    // Start recursive construction of kd-tree
    BuildTree(0, bounds, primBounds, primNums, primitives.size(),
              maxDepth, edges, prims0, prims1);

	// Free working memory for kd-tree construction
    delete[] primNums;
    for (int i = 0; i < 3; ++i)
        delete[] edges[i];
    delete[] prims0;
    delete[] prims1;
}
Beispiel #7
0
    void EllipseMesh::AllocateResources()
    {
        vertexsData_.clear();
        indexes_.clear();

        VertexsData& data = vertexsData_;

        float halfX = width_ * 0.5f;
        float halfY = height_ * 0.5f;

        float angle = 0.0f;

        const float angleAdder = TWO_PI / (float)res_;

        for (int i = 0; i < res_; i++)
        {
            VertexData vertexData;
            vertexData.normal_ = Vertex3(0, 0, 1); // always facing forward
            vertexData.position_.x = cos(angle);
            vertexData.position_.y = sin(angle);
            vertexData.position_.z = 0;
            vertexData.uv_[0] = Vertex2(vertexData.position_.x, vertexData.position_.y);
			vertexData.uv_[0].x = (vertexData.uv_[0].x + 1) / 2.0f;
			vertexData.uv_[0].y = 1 - (vertexData.uv_[0].y + 1) / 2.0f;

            vertexData.position_.x *= halfX;
            vertexData.position_.y *= halfY;

            data.push_back(vertexData);

            angle += angleAdder;
        }

        Mesh::AllocateResources();

    }
  //go throught the list of objects that need to be rendered and render them
  void Engine::Render()
  { //int probug = 0; //pConsole->Log(_T("DRAW %d"),C_NORMAL,probug++); //3

    pRenderer->ClearBuffer(); //clear the screen

    pRenderer->EnableBlendMode();
    pRenderer->BlendMode(BM_ALPHA);

    //pRenderer->CamTranslate(0,0,1);

    //pRenderer->Begin3D();
    //pRenderer->DrawCube(Vertex3(0,0,-8),r,10);
    //r+=0.15f;

    //  pRenderer->Begin2D();

    //DRAW FRAME TIME
    //  pRenderer->DrawText(Vertex2(10,20,Color(0,1,0)),"RenderTime: %4.2f: Frame Number: %d",fps,nFrameCount);

    //Mouse look
    //pRenderer->CamRotate(camrotx,1.0,0.0,0.0);
    //pRenderer->CamRotate(camroty,0.0,1.0,0.0);
    //WASD Movement
    pRenderer->CamTranslate(-camx,-camy,-camz);

    //TEST

    //3D
    /*
    for(int i = 0;i<1000;i++){
      for (int j = 0; j < 60; j+=4){
        pRenderer->DrawCube(Vertex3(i * 2,0,j,Color(1.0f,1.0f,0.0f)),0,0,Color(1, (i - 1) % 2, (i - 1) % 2));
        pRenderer->DrawCube(Vertex3(i * 2,0,j + 2,Color(1.0f,1.0f,0.0f)),0,0,Color(1, i % 2, i % 2));
      }
    }
    */
    pRenderer->DrawCube(Vertex3(16,10,13,Color(1.0f,1.0f,0.0f)),0,0,Color(1,1,0));
    pRenderer->DrawCube(Vertex3(13,10,16,Color(1.0f,1.0f,0.0f)),0,0,Color(1,0,1));
    pRenderer->DrawCube(Vertex3(16,10,16,Color(1.0f,1.0f,0.0f)),0,0,Color(0,0,1));

    float fvViewMatrix[ 16 ]; 
   // glGetFloatv( GL_MODELVIEW_MATRIX, fvViewMatrix );



    /*
    auto vbo = pResourceMan->Aquire<VBO>("razuleVBO",L"C:\\untitled.obj");
    if (! vbo->HasBeenCreated()){
      pRenderer->BuildVBO(vbo, VBO::STATIC_DRAW);
    }
    pRenderer->DrawVBO(vbo, Vertex3());
    */


    pRenderer->Push2D();

    pEntityMan->Draw(pRenderer);

    auto id = pResourceMan->Aquire<Texture>("testkey",L"C:\\test.png");
    if (!id->isBound()) pRenderer->BuildTexture(id);

   // pRenderer->DrawTexture2D(id,Vertex2(x,y));


    pRenderer->DrawText(Vertex2(10,20,Color(0,1,0)),_T("FPS: %3.0f"),fps);

    //for (int i = 0; i < 16; i+=4)
    //  pRenderer->DrawText(Vertex2(10,40 + i * 8,Color(0,1,0)),_T("%.3f,%.3f,%.3f,%.3f"),fvViewMatrix[i],fvViewMatrix[i + 1],fvViewMatrix[i + 2],fvViewMatrix[i + 3]);


    //DRAW SPRITES

    //2D (no Z buffer)
    //	for (int i=0; i < 200000; i++)
    //	pRenderer->DrawTriangle(Vertex2(i,100,Color(.0f,1.0f,0.0f)),
    //							Vertex2(200+i,200+fps,Color(1.0f,0.0f,0.0f)),
    //							Vertex2(100+i,0,Color(0.0f,0.0f,1.0f)));

    if (id != 0)
      pRenderer->BeginTexture(id);

    if (input[32]){
      pRenderer->DrawRectangle(
        Vertex2(100,100,Color(1)),
        Vertex2(410,100,Color(0)),
        Vertex2(410,410,Color(1)),
        Vertex2(100,410,Color(0)));
    }

    pRenderer->EndTexture();
    pRenderer->DrawLine(Vertex2(0,600,Color(0.0f,1.0f,0.0f)),
      Vertex2(1280,600,Color(1.0f,1.0f,0.0f))
      );

    //  pRenderer->DrawTexture2D(sp->GetNextSprite(),Vertex2(640,360));
    // pRenderer->DrawTexture2D(pTextureMan->Texture(_T("data\\textures\\Kumori.tga")),Vertex2(200 + nFrameCount % 60,200));

    // pRenderer->DrawTexture2D(pTextureMan->Texture("icephoenix.tga"),Vertex2(150,100));


    //END TEST


    //DRAW CONSOLE
    pConsole->Draw(pRenderer);

    pRenderer->Pop2D();

    pRenderer->DisableBlendMode();
    pRenderer->SwapBuffer(); //update buffers
  }
Beispiel #9
0
void GeometryGenerator::CreateMultiTexBox(float width, float height, float depth, MeshData& meshData)
{
	//
	// Create the vertices.
	//

	Vertex2 v[24];

	float w2 = 0.5f*width;
	float h2 = 0.5f*height;
	float d2 = 0.5f*depth;

	// Fill in the front face vertex data.
	v[0] = Vertex2(XMFLOAT3(-w2, -h2, -d2), XMFLOAT3(0.0f, 0.0f, -1.0f), XMFLOAT2(0.1f, 0.1f), XMFLOAT2(0.9f, 0.9f), XMFLOAT2(0.9f, 0.1f), XMFLOAT2(0.1f, 0.9f), XMFLOAT2(0.1f, 0.5f), XMFLOAT2(0.9f, 0.5f));
	//v[0] = Vertex2(-w2, -h2, -d2, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
	v[1] = Vertex2(XMFLOAT3(-w2, +h2, -d2), XMFLOAT3(0.0f, 0.0f, -1.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[1] = Vertex(-w2, +h2, -d2, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f);
	v[2] = Vertex2(XMFLOAT3(+w2, +h2, -d2), XMFLOAT3(0.0f, 0.0f, -1.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[2] = Vertex(+w2, +h2, -d2, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f);
	v[3] = Vertex2(XMFLOAT3(+w2, -h2, -d2), XMFLOAT3(0.0f, 0.0f, -1.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[3] = Vertex(+w2, -h2, -d2, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f);

	// Fill in the back face vertex data.
	v[4] = Vertex2(XMFLOAT3(-w2, -h2, +d2), XMFLOAT3(0.0f, 0.0f, 1.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[4] = Vertex(-w2, -h2, +d2, 0.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f);
	v[5] = Vertex2(XMFLOAT3(+w2, -h2, +d2), XMFLOAT3(0.0f, 0.0f, 1.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[5] = Vertex(+w2, -h2, +d2, 0.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
	v[6] = Vertex2(XMFLOAT3(+w2, +h2, +d2), XMFLOAT3(0.0f, 0.0f, 1.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[6] = Vertex(+w2, +h2, +d2, 0.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f);
	v[7] = Vertex2(XMFLOAT3(-w2, +h2, +d2), XMFLOAT3(0.0f, 0.0f, 1.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[7] = Vertex(-w2, +h2, +d2, 0.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f);

	// Fill in the top face vertex data.
	v[8] = Vertex2(XMFLOAT3(-w2, +h2, -d2), XMFLOAT3(0.0f, 1.0f, 0.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[8]  = Vertex(-w2, +h2, -d2, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
	v[9] = Vertex2(XMFLOAT3(-w2, +h2, +d2), XMFLOAT3(0.0f, 1.0f, 0.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[9]  = Vertex(-w2, +h2, +d2, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f);
	v[10] = Vertex2(XMFLOAT3(+w2, +h2, +d2), XMFLOAT3(0.0f, 1.0f, 0.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[10] = Vertex(+w2, +h2, +d2, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f);
	v[11] = Vertex2(XMFLOAT3(+w2, +h2, -d2), XMFLOAT3(0.0f, 1.0f, 0.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[11] = Vertex(+w2, +h2, -d2, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f);

	// Fill in the bottom face vertex data.
	v[12] = Vertex2(XMFLOAT3(-w2, -h2, -d2), XMFLOAT3(0.0f, -1.0f, 0.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[12] = Vertex(-w2, -h2, -d2, 0.0f, -1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f);
	v[13] = Vertex2(XMFLOAT3(+w2, -h2, -d2), XMFLOAT3(0.0f, -1.0f, 0.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[13] = Vertex(+w2, -h2, -d2, 0.0f, -1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
	v[14] = Vertex2(XMFLOAT3(+w2, -h2, +d2), XMFLOAT3(0.0f, -1.0f, 0.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[14] = Vertex(+w2, -h2, +d2, 0.0f, -1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f);
	v[15] = Vertex2(XMFLOAT3(-w2, -h2, +d2), XMFLOAT3(0.0f, -1.0f, 0.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[15] = Vertex(-w2, -h2, +d2, 0.0f, -1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f);

	// Fill in the left face vertex data.
	v[16] = Vertex2(XMFLOAT3(-w2, -h2, +d2), XMFLOAT3(-1.0f, 0.0f, 0.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[16] = Vertex(-w2, -h2, +d2, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f);
	v[17] = Vertex2(XMFLOAT3(-w2, +h2, +d2), XMFLOAT3(-1.0f, 0.0f, 0.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[17] = Vertex(-w2, +h2, +d2, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f);
	v[18] = Vertex2(XMFLOAT3(-w2, +h2, -d2), XMFLOAT3(-1.0f, 0.0f, 0.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[18] = Vertex(-w2, +h2, -d2, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f);
	v[19] = Vertex2(XMFLOAT3(-w2, -h2, -d2), XMFLOAT3(-1.0f, 0.0f, 0.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[19] = Vertex(-w2, -h2, -d2, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f);

	// Fill in the right face vertex data.
	v[20] = Vertex2(XMFLOAT3(+w2, -h2, -d2), XMFLOAT3(1.0f, 0.0f, 0.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[20] = Vertex(+w2, -h2, -d2, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f);
	v[21] = Vertex2(XMFLOAT3(+w2, +h2, -d2), XMFLOAT3(1.0f, 0.0f, 0.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[21] = Vertex(+w2, +h2, -d2, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);
	v[22] = Vertex2(XMFLOAT3(+w2, +h2, +d2), XMFLOAT3(1.0f, 0.0f, 0.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[22] = Vertex(+w2, +h2, +d2, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f);
	v[23] = Vertex2(XMFLOAT3(+w2, -h2, +d2), XMFLOAT3(1.0f, 0.0f, 0.0f), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0), XMFLOAT2(0, 0));
	//v[23] = Vertex(+w2, -h2, +d2, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f);

	//meshData.Vertices.assign(&v[0], &v[24]);

	//
	// Create the indices.
	//

	UINT i[36];

	// Fill in the front face index data
	i[0] = 0; i[1] = 1; i[2] = 2;
	i[3] = 0; i[4] = 2; i[5] = 3;

	// Fill in the back face index data
	i[6] = 4; i[7] = 5; i[8] = 6;
	i[9] = 4; i[10] = 6; i[11] = 7;

	// Fill in the top face index data
	i[12] = 8; i[13] = 9; i[14] = 10;
	i[15] = 8; i[16] = 10; i[17] = 11;

	// Fill in the bottom face index data
	i[18] = 12; i[19] = 13; i[20] = 14;
	i[21] = 12; i[22] = 14; i[23] = 15;

	// Fill in the left face index data
	i[24] = 16; i[25] = 17; i[26] = 18;
	i[27] = 16; i[28] = 18; i[29] = 19;

	// Fill in the right face index data
	i[30] = 20; i[31] = 21; i[32] = 22;
	i[33] = 20; i[34] = 22; i[35] = 23;

	meshData.Indices.assign(&i[0], &i[36]);
}
    void RoundedRectangleMesh::AllocateResources()
    {
        vertexsData_.clear();
        indexes_.clear();

        VertexsData& data = vertexsData_;

        float halfX = width_ * 0.5f;
        float halfY = height_ * 0.5f;

        float angle = 0.0f;

        float radius1 = std::min(radius_, std::min(halfX, halfY));

        float totalSizeX = width_ + 2 * radius1;
        float totalSizeY = height_ + 2 * radius1;

        halfX -= (totalSizeX - width_) / 2;
        halfY -= (totalSizeY - height_) / 2;
        float coordXFactor = (2 * halfX) / totalSizeX;
        float coordYFactor = (2 * halfY) / totalSizeY;

        const float angleAdder = TWO_PI / (float)res_;

        for (int i = 0; i < res_; i++)
        {
            VertexData vertexData;
            vertexData.normal_ = Vertex3(0, 0, 1); // always facing forward
            vertexData.position_.x = cos(angle);
            vertexData.position_.y = sin(angle);
            vertexData.position_.z = 0;
			vertexData.uv_[0] = Vertex2(vertexData.position_.x, vertexData.position_.y);

            vertexData.position_ *= radius1;

            if (angle < PI / 2 || angle > 3 * PI / 2)
            {
                vertexData.position_.x += halfX;
				vertexData.uv_[0].x = coordXFactor + 0.5f * (1 - coordXFactor) * vertexData.uv_[0].x;
            }
            else if (angle > PI / 2)
            {
                vertexData.position_.x -= halfX;
				vertexData.uv_[0].x = -coordXFactor + 0.5f * (1 - coordXFactor) * vertexData.uv_[0].x;
            }

            if (angle >= 0 && angle < PI)
            {
                vertexData.position_.y += halfY;
				vertexData.uv_[0].y = coordYFactor + 0.5f * (1 - coordYFactor) * vertexData.uv_[0].y;
            }
            else if (angle >= PI)
            {
                vertexData.position_.y -= halfY;
				vertexData.uv_[0].y = -coordYFactor + 0.5f * (1 - coordYFactor) * vertexData.uv_[0].y;
            }

			vertexData.uv_[0].x = (vertexData.uv_[0].x + 1) / 2.0f;
			vertexData.uv_[0].y = 1 - (vertexData.uv_[0].y + 1) / 2.0f;

            data.push_back(vertexData);

            angle += angleAdder;
        }

        Mesh::AllocateResources();
    }