예제 #1
0
    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();
    }
예제 #2
0
 void
 Vert (
     LXtFVector               pos,
     int                      flags = LXiSTROKE_ABSOLUTE)
 {
     Vertex3 (pos[0], pos[1], pos[2], flags);
 }
예제 #3
0
//物体剔除
bool hgl_CullPrimitive( const HGL_Primitive& primitive, const matrix44& transMatrix, const frustum& space )
{
	vertex3 obj = Vertex3( transMatrix._v4._x, transMatrix._v4._y, transMatrix._v4._z );

	//物体是否超出远近剪裁面
	//注意比较近剪裁面时只要物体包围球有一点超出就全部剔除,这是在不做剪裁的情况下防止那种可怕的错误透视发生
	if( obj._z - primitive.radius <= space._nearZ || 
		obj._z - primitive.radius >= space._farZ )
	{
		return true;
	}

	//视椎体左右剪裁面剔除
	if( IsFront( obj, primitive.radius, space._left ) || 
		IsFront( obj, primitive.radius, space._right ) )
	{
		return true;
	}

	//视椎体上下剪裁面剔除
	if( IsFront( obj, primitive.radius, space._top ) || 
		IsFront( obj, primitive.radius, space._bottom ) )
	{
		return true;
	}

	return false;
}
예제 #4
0
 void
 Vert (
     float                    x,
     float                    y,
     int                      flags = LXiSTROKE_SCREEN)
 {
     Vertex3 (x, y, 0.0, flags);
 }
예제 #5
0
 void
 Vert (
     double                   x,
     double                   y,
     int                      flags = LXiSTROKE_SCREEN)
 {
     Vertex3 (x, y, 0.0, flags);
 }
예제 #6
0
 void
 Vert (
     float                    x,
     float                    y,
     float                    z,
     int                      flags = LXiSTROKE_ABSOLUTE)
 {
     Vertex3 (x, y, z, flags);
 }
예제 #7
0
 void
 Vert (
     double                   x,
     double                   y,
     double                   z,
     int                      flags = LXiSTROKE_ABSOLUTE)
 {
     Vertex3 (x, y, z, flags);
 }
예제 #8
0
//----------------------------------------------------------------------------
void VETable::RemoveTriangles (V3Array& rkVA, T3Array& rkTA)
{
    // ear-clip the wireframe to get the triangles
    Triangle3 kTri;
    while ( Remove(kTri) )
    {
        int iV0 = (int)rkVA.size(), iV1 = iV0+1, iV2 = iV1+1;
        rkTA.push_back(Triangle3(iV0,iV1,iV2));

        const Vertex& rkV0 = m_akVertex[kTri.i0];
        const Vertex& rkV1 = m_akVertex[kTri.i1];
        const Vertex& rkV2 = m_akVertex[kTri.i2];

        rkVA.push_back(Vertex3(rkV0.m_fX,rkV0.m_fY,rkV0.m_fZ));
        rkVA.push_back(Vertex3(rkV1.m_fX,rkV1.m_fY,rkV1.m_fZ));
        rkVA.push_back(Vertex3(rkV2.m_fX,rkV2.m_fY,rkV2.m_fZ));
    }
}
예제 #9
0
    void Node::SetGlobalPosition(const Vertex3& position)
    {
        PNode parent = parent_.lock();

        if (parent == nullptr)
        {
            SetPosition(position);
        }
        else
        {
            SetPosition(Vertex3(parent->GetGlobalModelInvMatrix() * Vertex4(position, 1)));
        }
    }
예제 #10
0
Void RPGGame::_CreateLightsMaterials()
{
    // Lights
    Light * pSun = GraphicsFn->CreateLight( TEXT("Light_Sun"), LIGHT_OMNI );
    pSun->Diffuse = Color4::White;
    pSun->Position = Vertex3( 256.00f, 256.0f, 100.0f );

    // Materials
    Material * pMat = GraphicsFn->CreateMaterial( TEXT("Material_Player") );
    pMat->Diffuse = Color4::Blue;
    pMat = GraphicsFn->CreateMaterial( TEXT("Material_SelectionMarker") );
    pMat->Diffuse = Color4::Yellow;
    pMat = GraphicsFn->CreateMaterial( TEXT("Material_CastAura") );
    pMat->Diffuse = Color4::Green;
    pMat = GraphicsFn->CreateMaterial( TEXT("Material_FireBolt") );
    pMat->Diffuse = Color4::Red;
    pMat = GraphicsFn->CreateMaterial( TEXT("Material_IceNova") );
    pMat->Diffuse = Color4::Cyan;
}
예제 #11
0
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;
}
예제 #12
0
Void EngineTests::_CreateEffects()
{
    m_hSunLight.SetType( LIGHT_OMNI );
    m_hSunLight.Diffuse = Color4::White;
    m_hSunLight.Position = Vertex3( 0.0f, 0.0f, 50.0f );

    m_hMaterialFloor.Diffuse = Color4::Cyan;
    m_hMaterialCharacter.Diffuse = Color4::Cyan;
    m_hMaterialA.Diffuse = Color4::Blue;
    m_hMaterialB.Diffuse = Color4::Green;
    m_hMaterialC.Diffuse = Color4::Yellow;
    m_hMaterialD.Diffuse = Color4::Red;

    m_pDefaultEffect = New EffectLightMaterial();

    m_pEffectInstanceFloor = m_pDefaultEffect->CreateInstance( EFFECTLIGHT_TECHNIQUE_POINT_PHONG, &m_hSunLight, &m_hMaterialFloor );
    m_pEffectInstanceCharacter = m_pDefaultEffect->CreateInstance( EFFECTLIGHT_TECHNIQUE_POINT_PHONG, &m_hSunLight, &m_hMaterialCharacter );
    m_pEffectInstanceA = m_pDefaultEffect->CreateInstance( EFFECTLIGHT_TECHNIQUE_POINT_PHONG, &m_hSunLight, &m_hMaterialA );
    m_pEffectInstanceB = m_pDefaultEffect->CreateInstance( EFFECTLIGHT_TECHNIQUE_POINT_PHONG, &m_hSunLight, &m_hMaterialB );
    m_pEffectInstanceC = m_pDefaultEffect->CreateInstance( EFFECTLIGHT_TECHNIQUE_POINT_PHONG, &m_hSunLight, &m_hMaterialC );
    m_pEffectInstanceD = m_pDefaultEffect->CreateInstance( EFFECTLIGHT_TECHNIQUE_POINT_PHONG, &m_hSunLight, &m_hMaterialD );
}
예제 #13
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();

    }
예제 #14
0
  //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
  }
예제 #15
0
    void BoxMesh::AllocateResources()
    {
        // halves
        float halfW = width_ * .5f;
        float halfH = height_ * .5f;
        float halfD = depth_ * .5f;

        Vertex3 vert;
        Vertex2 texcoord;
        Vertex3 normal;
        size_t vertOffset = 0;

        vertexsData_.clear();
        indexes_.clear();
        indexesWireframe_.clear();

        VertexsData& data = vertexsData_;

        // TRIANGLES
        // Front Face
        normal = Vertex3(0, 0, 1);

        for (int iy = 0; iy < resY_; iy++)
        {
            for (int ix = 0; ix < resX_; ix++)
            {

                // normalized tex coords
                texcoord.x = ((float)ix / ((float)resX_ - 1.f));
                texcoord.y = ((float)iy / ((float)resY_ - 1.f));

                vert.x = texcoord.x * width_ - halfW;
                vert.y = texcoord.y * height_ - halfH;
                vert.z = halfD;

                VertexData vertexData;
                vertexData.normal_ = normal;
                vertexData.position_ = vert;
				vertexData.uv_[0] = texcoord;

                data.push_back(vertexData);
            }
        }

        // Front face CCW
        for (int y = 0; y < resY_ - 1; y++)
        {
            for (int x = 0; x < resX_ - 1; x++)
            {
				IndexType i0 = (IndexType)(y * resX_ + x + vertOffset);
				IndexType i1 = (IndexType)(y * resX_ + x + 1 + vertOffset);
				IndexType i2 = (IndexType)((y + 1)*resX_ + x + vertOffset);
				IndexType i3 = (IndexType)((y + 1)*resX_ + x + 1 + vertOffset);
                // first triangle
                indexes_.push_back(i0);
                indexes_.push_back(i1);
                indexes_.push_back(i2);

                // second triangle
                indexes_.push_back(i1);
                indexes_.push_back(i3);
                indexes_.push_back(i2);

                indexesWireframe_.push_back(i0);
                indexesWireframe_.push_back(i1);
				indexesWireframe_.push_back(i1);
                indexesWireframe_.push_back(i3);
				indexesWireframe_.push_back(i3);
                indexesWireframe_.push_back(i2);
				indexesWireframe_.push_back(i2);
				indexesWireframe_.push_back(i0);
            }
        }

        vertOffset = data.size();


        // Right Side Face
        normal = Vertex3(1, 0, 0);
        for (int iy = 0; iy < resY_; iy++)
        {
            for (int ix = 0; ix < resZ_; ix++)
            {
                // normalized tex coords
                texcoord.x = ((float)ix / ((float)resZ_ - 1.f));
                texcoord.y = ((float)iy / ((float)resY_ - 1.f));

                vert.x = halfW;
                vert.y = texcoord.y * height_ - halfH;
                vert.z = texcoord.x * -depth_ + halfD;

                VertexData vertexData;
                vertexData.normal_ = normal;
                vertexData.position_ = vert;
				vertexData.uv_[0] = texcoord;

                data.push_back(vertexData);
            }
        }

        for (int y = 0; y < resY_ - 1; y++)
        {
            for (int x = 0; x < resZ_ - 1; x++)
            {
				IndexType i0 = (IndexType)(y * resZ_ + x + vertOffset);
				IndexType i1 = (IndexType)(y * resZ_ + x + 1 + vertOffset);
				IndexType i2 = (IndexType)((y + 1)*resZ_ + x + vertOffset);
				IndexType i3 = (IndexType)((y + 1)*resZ_ + x + 1 + vertOffset);

                // first triangle
                indexes_.push_back(i0);
                indexes_.push_back(i1);
                indexes_.push_back(i2);

                // second triangle
                indexes_.push_back(i1);
                indexes_.push_back(i3);
                indexes_.push_back(i2);

				indexesWireframe_.push_back(i0);
				indexesWireframe_.push_back(i1);
				indexesWireframe_.push_back(i1);
				indexesWireframe_.push_back(i3);
				indexesWireframe_.push_back(i3);
				indexesWireframe_.push_back(i2);
				indexesWireframe_.push_back(i2);
				indexesWireframe_.push_back(i0);
			}
        }

        vertOffset = data.size();

        // Left Side Face
        normal = Vertex3(-1, 0, 0);

        for (int iy = 0; iy < resY_; iy++)
        {
            for (int ix = 0; ix < resZ_; ix++)
            {
                // normalized tex coords
                texcoord.x = ((float)ix / ((float)resZ_ - 1.f));
                texcoord.y = ((float)iy / ((float)resY_ - 1.f));

                vert.x = -halfW;
                vert.y = texcoord.y * height_ - halfH;
                vert.z = texcoord.x * depth_ - halfD;

                VertexData vertexData;
                vertexData.normal_ = normal;
                vertexData.position_ = vert;
				vertexData.uv_[0] = texcoord;

                data.push_back(vertexData);
            }
        }

        for (int y = 0; y < resY_ - 1; y++)
        {
            for (int x = 0; x < resZ_ - 1; x++)
            {
				IndexType i0 = (IndexType)(y * resZ_ + x + vertOffset);
				IndexType i1 = (IndexType)(y * resZ_ + x + 1 + vertOffset);
				IndexType i2 = (IndexType)((y + 1)*resZ_ + x + vertOffset);
				IndexType i3 = (IndexType)((y + 1)*resZ_ + x + 1 + vertOffset);

				// first triangle
				indexes_.push_back(i0);
				indexes_.push_back(i1);
				indexes_.push_back(i2);

				// second triangle
				indexes_.push_back(i1);
				indexes_.push_back(i3);
				indexes_.push_back(i2);

				indexesWireframe_.push_back(i0);
				indexesWireframe_.push_back(i1);
				indexesWireframe_.push_back(i1);
				indexesWireframe_.push_back(i3);
				indexesWireframe_.push_back(i3);
				indexesWireframe_.push_back(i2);
				indexesWireframe_.push_back(i2);
				indexesWireframe_.push_back(i0);
			}
        }

        vertOffset = data.size();


        // Back Face
        normal = Vertex3(0, 0, -1);
        for (int iy = 0; iy < resY_; iy++)
        {
            for (int ix = 0; ix < resX_; ix++)
            {

                // normalized tex coords
                texcoord.x = ((float)ix / ((float)resX_ - 1.f));
                texcoord.y = ((float)iy / ((float)resY_ - 1.f));

                vert.x = texcoord.x * -width_ + halfW;
                vert.y = texcoord.y * height_ - halfH;
                vert.z = -halfD;

                VertexData vertexData;
                vertexData.normal_ = normal;
                vertexData.position_ = vert;
				vertexData.uv_[0] = texcoord;

                data.push_back(vertexData);
            }
        }

        for (int y = 0; y < resY_ - 1; y++)
        {
            for (int x = 0; x < resX_ - 1; x++)
            {
				IndexType i0 = (IndexType)(y * resX_ + x + vertOffset);
				IndexType i1 = (IndexType)(y * resX_ + x + 1 + vertOffset);
				IndexType i2 = (IndexType)((y + 1)*resX_ + x + vertOffset);
				IndexType i3 = (IndexType)((y + 1)*resX_ + x + 1 + vertOffset);
				// first triangle
				indexes_.push_back(i0);
				indexes_.push_back(i1);
				indexes_.push_back(i2);

				// second triangle
				indexes_.push_back(i1);
				indexes_.push_back(i3);
				indexes_.push_back(i2);

				indexesWireframe_.push_back(i0);
				indexesWireframe_.push_back(i1);
				indexesWireframe_.push_back(i1);
				indexesWireframe_.push_back(i3);
				indexesWireframe_.push_back(i3);
				indexesWireframe_.push_back(i2);
				indexesWireframe_.push_back(i2);
				indexesWireframe_.push_back(i0);
            }
        }

        vertOffset = data.size();

        // Bottom Face
        normal = Vertex3(0, -1, 0);
        for (int iy = 0; iy < resZ_; iy++)
        {
            for (int ix = 0; ix < resX_; ix++)
            {

                // normalized tex coords
                texcoord.x = ((float)ix / ((float)resX_ - 1.f));
                texcoord.y = ((float)iy / ((float)resZ_ - 1.f));

                vert.x = texcoord.x * width_ - halfW;
                vert.y = -halfH;
                vert.z = texcoord.y * depth_ - halfD;

                VertexData vertexData;
                vertexData.normal_ = normal;
                vertexData.position_ = vert;
				vertexData.uv_[0] = texcoord;

                data.push_back(vertexData);
            }
        }

        for (int y = 0; y < resZ_ - 1; y++)
        {
            for (int x = 0; x < resX_ - 1; x++)
            {
				IndexType i0 = (IndexType)(y * resX_ + x + vertOffset);
				IndexType i1 = (IndexType)(y * resX_ + x + 1 + vertOffset);
				IndexType i2 = (IndexType)((y + 1)*resX_ + x + vertOffset);
				IndexType i3 = (IndexType)((y + 1)*resX_ + x + 1 + vertOffset);

				// first triangle
				indexes_.push_back(i0);
				indexes_.push_back(i1);
				indexes_.push_back(i2);

				// second triangle
				indexes_.push_back(i1);
				indexes_.push_back(i3);
				indexes_.push_back(i2);

				indexesWireframe_.push_back(i0);
				indexesWireframe_.push_back(i1);
				indexesWireframe_.push_back(i1);
				indexesWireframe_.push_back(i3);
				indexesWireframe_.push_back(i3);
				indexesWireframe_.push_back(i2);
				indexesWireframe_.push_back(i2);
				indexesWireframe_.push_back(i0);
            }
        }

        vertOffset = data.size();

        // Top Face
        normal = Vertex3(0, 1, 0);
        for (int iy = 0; iy < resZ_; iy++)
        {
            for (int ix = 0; ix < resX_; ix++)
            {
                // normalized tex coords
                texcoord.x = ((float)ix / ((float)resX_ - 1.f));
                texcoord.y = ((float)iy / ((float)resZ_ - 1.f));

                vert.x = texcoord.x * width_ - halfW;
                vert.y = halfH;
                vert.z = texcoord.y * -depth_ + halfD;

                VertexData vertexData;
                vertexData.normal_ = normal;
                vertexData.position_ = vert;
				vertexData.uv_[0] = texcoord;

                data.push_back(vertexData);
            }
        }

        for (int y = 0; y < resZ_ - 1; y++)
        {
            for (int x = 0; x < resX_ - 1; x++)
            {
				IndexType i0 = (IndexType)(y * resX_ + x + vertOffset);
				IndexType i1 = (IndexType)(y * resX_ + x + 1 + vertOffset);
				IndexType i2 = (IndexType)((y + 1)*resX_ + x + vertOffset);
				IndexType i3 = (IndexType)((y + 1)*resX_ + x + 1 + vertOffset);

				// first triangle
				indexes_.push_back(i0);
				indexes_.push_back(i1);
				indexes_.push_back(i2);

				// second triangle
				indexes_.push_back(i1);
				indexes_.push_back(i3);
				indexes_.push_back(i2);

				indexesWireframe_.push_back(i0);
				indexesWireframe_.push_back(i1);
				indexesWireframe_.push_back(i1);
				indexesWireframe_.push_back(i3);
				indexesWireframe_.push_back(i3);
				indexesWireframe_.push_back(i2);
				indexesWireframe_.push_back(i2);
				indexesWireframe_.push_back(i0);
            }
        }

        Mesh::AllocateResources();
    }
예제 #16
0
Void ShapeConvexMesh::ComputeMassProperties( Scalar fDensity, Scalar * outMass, Vertex3 * outCenterOfMass, Matrix3 * outInertiaTensor ) const
{
    static const Scalar Inv6 = (1.0f / 6.0f);
    static const Scalar Inv24 = (1.0f / 24.0f);
    static const Scalar Inv60 = (1.0f / 60.0f);
    static const Scalar Inv120 = (1.0f / 120.0f);

    // 1, x, y, z, x2, y2, z2, xy, yz, zx
    Scalar arrIntegrals[10] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
                                0.0f, 0.0f, 0.0f, 0.0f, 0.0f };

    // Walk through all facets
    m_pGraph->EnumFacets();
    const MeshFacet * pFacet = m_pGraph->EnumNextFacet();
    while( pFacet != NULL ) {
        switch( pFacet->GetFacetType() ) {
            case MESH_FACET_TRIANGLE: {
                    const Triangle * pTriangle = (const Triangle *)pFacet;
                    const Vertex3 & vA = m_pGraph->GetVertexPosition( pTriangle->Vertices[0] );
                    const Vertex3 & vB = m_pGraph->GetVertexPosition( pTriangle->Vertices[1] );
                    const Vertex3 & vC = m_pGraph->GetVertexPosition( pTriangle->Vertices[2] );
                    _UpdateMassIntegral( arrIntegrals, vA, vB, vC );
                } break;
            case MESH_FACET_QUAD: {
                    const Quad * pQuad = (const Quad *)pFacet;
                    const Vertex3 & vA = m_pGraph->GetVertexPosition( pQuad->Vertices[0] );
                    const Vertex3 & vB = m_pGraph->GetVertexPosition( pQuad->Vertices[1] );
                    const Vertex3 & vC = m_pGraph->GetVertexPosition( pQuad->Vertices[2] );
                    const Vertex3 & vD = m_pGraph->GetVertexPosition( pQuad->Vertices[3] );
                    _UpdateMassIntegral( arrIntegrals, vA, vB, vC );
                    _UpdateMassIntegral( arrIntegrals, vA, vC, vD );
                } break;
            case MESH_FACET_POLYGON: {
                    // Quick on-the-fly fan triangulation
                    const Polygon * pPolygon = (const Polygon *)pFacet;
                    UInt iTriangleCount = ( pPolygon->GetVertexCount() - 2 );
                    const Vertex3 & vA = m_pGraph->GetVertexPosition( pPolygon->Vertices[0] );
                    for( UInt i = 0; i < iTriangleCount; ++i ) {
                        const Vertex3 & vB = m_pGraph->GetVertexPosition( pPolygon->Vertices[i+1] );
                        const Vertex3 & vC = m_pGraph->GetVertexPosition( pPolygon->Vertices[i+2] );
                        _UpdateMassIntegral( arrIntegrals, vA, vB, vC );
                    }
                } break;
            default: Assert(false); break;
        }
        pFacet = m_pGraph->EnumNextFacet();
    }

    // Finalize
    Scalar fTmp0 = ( Inv24 * fDensity );
    Scalar fTmp1 = ( Inv60 * fDensity );
    Scalar fTmp2 = ( Inv120 * fDensity );
    arrIntegrals[0] *= ( Inv6 * fDensity );
    arrIntegrals[1] *= fTmp0;
    arrIntegrals[2] *= fTmp0;
    arrIntegrals[3] *= fTmp0;
    arrIntegrals[4] *= fTmp1;
    arrIntegrals[5] *= fTmp1;
    arrIntegrals[6] *= fTmp1;
    arrIntegrals[7] *= fTmp2;
    arrIntegrals[8] *= fTmp2;
    arrIntegrals[9] *= fTmp2;

    // Mass / CenterOfMass
    *outMass = arrIntegrals[0];
    *outCenterOfMass = ( Vertex3(arrIntegrals[1], arrIntegrals[2], arrIntegrals[3]) / (*outMass) );

    // Inertia Tensor
    outInertiaTensor->m00 = arrIntegrals[5] + arrIntegrals[6];
    outInertiaTensor->m01 = -arrIntegrals[7];
    outInertiaTensor->m02 = -arrIntegrals[9];
    outInertiaTensor->m10 = outInertiaTensor->m01;
    outInertiaTensor->m11 = arrIntegrals[4] + arrIntegrals[6];
    outInertiaTensor->m12 = -arrIntegrals[8];
    outInertiaTensor->m20 = outInertiaTensor->m02;
    outInertiaTensor->m21 = outInertiaTensor->m12;
    outInertiaTensor->m22 = arrIntegrals[4] + arrIntegrals[5];
}
예제 #17
0
 Vertex3 Camera::ScreenToWorld(const Vertex3& screenXYZ) const
 {
     Update();
     Vertex4 worldCoord = GetViewProjectionInverse() * Vertex4(screenXYZ, 1);
     return Vertex3(worldCoord.x / worldCoord.w, worldCoord.y / worldCoord.w, worldCoord.z / worldCoord.w);
 }
예제 #18
0
Void EngineTests::_CreateWorld()
{
    // Floor
    RigidBody * pFloorBody = PhysicsFn->CreateRigidBody( true, m_pFloorShape, 1.0f, Vertex3(0.0f,0.0f,-10.0f) );
    pFloorBody->SetRestitution( 0.0f );
    pFloorBody->SetFriction( 0.0f );
    pFloorBody->SetRollingFriction( 0.0f );
    pFloorBody->SetCollisionGroup( 0x01 );
    pFloorBody->SetCollisionMask( 0x7f );

    m_pFloor = WorldFn->CreateLeaf( TEXT("Floor") );
    m_pFloor->SetMesh( m_pFloorGeometry );
    m_pFloor->SetEffectInstance( m_pEffectInstanceFloor );
    m_pFloor->SetBody( pFloorBody );
    WorldFn->AddChild( m_pFloor );

    // Character
    Vertex3 vInitialPosition( 0.0f, 0.0f, 2.0f );

    KinematicBody * pCharacterBody = PhysicsFn->CreateKinematicBody( false, m_pCharacterShape, 1.0f );
    pCharacterBody->SetRestitution( 0.0f );
    pCharacterBody->SetFriction( 0.0f );
    pCharacterBody->SetRollingFriction( 0.0f );
    pCharacterBody->SetCollisionGroup( 0x01 );
    pCharacterBody->SetCollisionMask( 0x07 );

    m_pCharacterController = PhysicsFn->CreateCharacterController( TEXT("CharacterController"), vInitialPosition, Quaternion::Identity, Vector3::Null, Vector3::Null );
    m_pCharacterController->Enabled = true;
    m_pCharacterController->EnableForces( false );
    m_pCharacterController->SetMovementSpeed( 5.0f );
    pCharacterBody->AttachController( m_pCharacterController );

    m_pCharacter = WorldFn->CreateLeaf( TEXT("Character") );
    m_pCharacter->SetMesh( m_pCharacterGeometry );
    m_pCharacter->SetEffectInstance( m_pEffectInstanceCharacter );
    m_pCharacter->SetBody( pCharacterBody );
    WorldFn->AddChild( m_pCharacter );

    // Sphere/Box stack
    Vertex3 vBallStackPosition( -10.0f, 10.0f, 0.0f );
    Vertex3 vBoxStackPosition( -10.0f, -10.0f, 0.0f );
    GChar strName[64];

    for( UInt i = 0; i < ENGINE_TEST_STACK_SIZE; ++i ) {
        vBallStackPosition.Z = 5.0f * (Scalar)(i+1);
        vBoxStackPosition.Z = 5.0f * (Scalar)(i+1);

        //StringFn->Format( strName, TEXT("Ball_%d"), i );

        //RigidBody * pBallBody = PhysicsFn->CreateRigidBody( false, m_pSphereShape, 1.0f, vBallStackPosition );
        //pBallBody->SetRestitution( 0.0f );
        //pBallBody->SetFriction( 0.0f );
        //pBallBody->SetRollingFriction( 0.0f );

        //m_arrBallStack[i] = WorldFn->CreateLeaf( strName );
        //m_arrBallStack[i]->SetMesh( m_pSphereGeometry );
        //m_arrBallStack[i]->SetEffectInstance( m_pEffectInstanceA );
        //m_arrBallStack[i]->SetBody( pBallBody );
        //WorldFn->AddChild( m_arrBallStack[i] );

        StringFn->Format( strName, TEXT("Box_%d"), i );

        RigidBody * pBoxBody = PhysicsFn->CreateRigidBody( false, m_pBoxShape, 1.0f, vBoxStackPosition );
        pBoxBody->SetRestitution( 0.0f );
        pBoxBody->SetFriction( 0.0f );
        pBoxBody->SetRollingFriction( 0.0f );

        m_arrBoxStack[i] = WorldFn->CreateLeaf( strName );
        m_arrBoxStack[i]->SetMesh( m_pBoxGeometry );
        m_arrBoxStack[i]->SetEffectInstance( m_pEffectInstanceA );
        m_arrBoxStack[i]->SetBody( pBoxBody );
        WorldFn->AddChild( m_arrBoxStack[i] );
    }

    // Joint systems
    //Matrix3 matRotation;
    //matRotation.MakeRotate( 0.0f, SCALAR_PI_4, SCALAR_PI_4, EULER_ANGLES_XYZ );

    //Vertex3 vFixedObjectPosition( 10.0f, 10.0f, 10.0f );
    //Vertex3 vObjectAPosition( 12.0f, 10.0f, 10.0f );
    //Quaternion qObjectAOrientation( matRotation );
    //Vertex3 vObjectBPosition( 7.0f, 10.0f, 10.0f );

    //RigidBody * pFixedBody = PhysicsFn->CreateRigidBody( true, m_pSphereShape, 1.0f, vFixedObjectPosition );
    //pFixedBody->SetRestitution( 0.0f );
    //pFixedBody->SetFriction( 0.0f );
    //pFixedBody->SetRollingFriction( 0.0f );
    //pFixedBody->SetCollisionGroup( 0x80 );
    //pFixedBody->SetCollisionMask( 0 );

    //m_pFixedObject = WorldFn->CreateLeaf( TEXT("FixedObject") );
    //m_pFixedObject->SetMesh( m_pSphereGeometry );
    //m_pFixedObject->SetEffectInstance( m_pEffectInstanceC );
    //m_pFixedObject->SetBody( pFixedBody );
    //WorldFn->AddChild( m_pFixedObject );

    //RigidBody * pObjectABody = PhysicsFn->CreateRigidBody( false, m_pBoxShape, 1.0f, vObjectAPosition ); //, qObjectAOrientation );
    //pObjectABody->SetRestitution( 0.0f );
    //pObjectABody->SetFriction( 0.0f );
    //pObjectABody->SetRollingFriction( 0.0f );
    //pObjectABody->SetCollisionGroup( 0x02 );
    //pObjectABody->SetCollisionMask( 0x03 );

    //m_pObjectA = WorldFn->CreateLeaf( TEXT("ObjectA") );
    //m_pObjectA->SetMesh( m_pBoxGeometry );
    //m_pObjectA->SetEffectInstance( m_pEffectInstanceA );
    //m_pObjectA->SetBody( pObjectABody );
    //WorldFn->AddChild( m_pObjectA );

    //RigidBody * pObjectBBody = PhysicsFn->CreateRigidBody( false, m_pBoxShape, 1.0f, vObjectBPosition );
    //pObjectBBody->SetRestitution( 0.0f );
    //pObjectBBody->SetFriction( 0.0f );
    //pObjectBBody->SetRollingFriction( 0.0f );
    //pObjectBBody->SetCollisionGroup( 0x04 );
    //pObjectBBody->SetCollisionMask( 0x05 );

    //m_pObjectB = WorldFn->CreateLeaf( TEXT("ObjectB") );
    //m_pObjectB->SetMesh( m_pBoxGeometry );
    //m_pObjectB->SetEffectInstance( m_pEffectInstanceB );
    //m_pObjectB->SetBody( pObjectBBody );
    //WorldFn->AddChild( m_pObjectB );

    //Transform3 vJointFrame;

    //Matrix3 matJointFrame;
    //matJointFrame.SetColumn( 0, Vector3::eJ );
    //matJointFrame.SetColumn( 1, Vector3::eK );
    //matJointFrame.SetColumn( 2, Vector3::eI );
    //vJointFrame.SetRotate( matJointFrame );
    //vJointFrame.SetTranslate( Vector3(11.0f, 10.0f, 10.0f) );

    //m_pJointAF = PhysicsFn->CreateJoint( JOINT_CONETWIST, pObjectABody, pFixedBody, vJointFrame );
    //( (JointConeTwist*)(m_pJointAF->GetJoint()) )->EnableTwistLimits( -SCALAR_PI_4, SCALAR_PI_4 );
    //( (JointHinge*)(m_pJointAF->GetJoint()) )->EnableSpring( 0.5f, SCALAR_PI_4 );

    //vJointFrame.SetTranslate( Vector3(9.0f, 10.0f, 10.0f) );

    //m_pJointBF = PhysicsFn->CreateJoint( JOINT_SLIDER, pObjectBBody, pFixedBody, vJointFrame );
    //( (JointSlider*)(m_pJointBF->GetJoint()) )->EnableLimits( -2.0f, +2.0f );
    //( (JointSlider*)(m_pJointBF->GetJoint()) )->EnableSpring( 0.5f, -1.0f );

    // World camera
    m_pRenderCamera = New Camera( true );
    m_pWorldCamera = New WorldCamera3rdPerson( m_pRenderCamera, m_pCharacter, NULL, 3.0f );
    WorldFn->SetWorldCamera( m_pWorldCamera );
}
예제 #19
0
 Vertex3 Camera::WorldToScreen(const Vertex3& worldXYZ) const
 {
     Update();
     Vertex4 screenCoord = GetViewProjection() * Vertex4(worldXYZ, 1);
     return Vertex3(screenCoord.x / screenCoord.w, screenCoord.y / screenCoord.w, screenCoord.z / screenCoord.w);
 }
예제 #20
0
 void Node::SetScale(float scale)
 {
     SetScale(Vertex3(scale));
 }
예제 #21
0
    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();
    }
예제 #22
0
    void PointOnSphere::CalculatePoint()
    {
        // Apply spherical coordinates
		point_ = center_ + radius_ * Vertex3(cos(theta_) * sin(phi_), cos(phi_), sin(theta_) * sin(phi_));
    }