Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Anddos

Member Since 01 Nov 2002
Offline Last Active Yesterday, 02:07 PM

Topics I've Started

Basic Terrain editor help

29 June 2015 - 04:48 AM

This is the rendering code to render and do a pick test on the terrain

What i want todo next is increase the picked triangles vertices for mouse 1 and decrease for mouse 2 , so that i can sculpt it to how i like

I know i have to lock the vertex buffer but i am unsure how to get the positions and adjust them and when todo it

// Clear the backbuffer and depth buffer.
    HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffeeeeee, 1.0f, 0));

    HR(gd3dDevice->BeginScene());

    // Setup the rendering FX
    HR(mFX->SetMatrix(mhViewProj, &(mView*mProj)));
    HR(mFX->SetTechnique(mhTech));
    UINT numPasses = 0;
    HR(mFX->Begin(&numPasses, 0));
    HR(mFX->BeginPass(0));
    HR(gd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME));
    HR(mTerrainMesh->DrawSubset(0));


    // Switch back to solid mode.
    HR(gd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID));

    // Did we pick anything?
    D3DXVECTOR3 originW(0.0f, 0.0f, 0.0f);
    D3DXVECTOR3 dirW(0.0f, 0.0f, 0.0f);
    if( gDInput->mouseButtonDown(0) )
    {
        getWorldPickingRay(originW, dirW);

        BOOL hit = 0;
        DWORD faceIndex = -1;
        float u = 0.0f;
        float v = 0.0f;
        float dist = 0.0f;
        ID3DXBuffer* allhits = 0;
        DWORD numHits = 0;
        HR(D3DXIntersect(mTerrainMesh, &originW, &dirW, &hit,
            &faceIndex, &u, &v, &dist, &allhits, &numHits));
        ReleaseCOM(allhits);

        // We hit anything?
        if( hit )
        {
            // Yes, draw the picked triangle in solid mode.
            IDirect3DVertexBuffer9* vb = 0;
            IDirect3DIndexBuffer9* ib = 0;
            HR(mTerrainMesh->GetVertexBuffer(&vb));
            HR(mTerrainMesh->GetIndexBuffer(&ib));

            HR(gd3dDevice->SetIndices(ib));
            HR(gd3dDevice->SetVertexDeclaration(VertexPNT::Decl));
            HR(gd3dDevice->SetStreamSource(0, vb, 0, sizeof(VertexPNT)));

            // faceIndex identifies the picked triangle to draw.
            HR(gd3dDevice->DrawIndexedPrimitive(
                D3DPT_TRIANGLELIST, 0, 0, mTerrainMesh->GetNumVertices(), faceIndex*3, 1))
            
            ReleaseCOM(vb);
            ReleaseCOM(ib);
        }
    }
    HR(mFX->EndPass());
    HR(mFX->End());
    
    mGfxStats->display();

    HR(gd3dDevice->EndScene());

    // Present the backbuffer.
    HR(gd3dDevice->Present(0, 0, 0, 0));

livecoding.tv

13 May 2015 - 12:34 PM

Just letting fellow programmers know about a site to for just coding

https://www.livecoding.tv


Creating Traffic lights (.x)

11 May 2015 - 01:13 AM

I am loading a traffic lights model with the.x functions the problem is i want 3 texture states for the lights etc, red, amba , green , how would i load 3 different textures if the model loading function loads 1 texture?

 

for(DWORD i = 0; i < numMaterials; i++)    // for each material...
    {
        material[i] = tempMaterials[i].MatD3D;    // get the material info
        material[i].Ambient = material[i].Diffuse;    // make ambient the same as diffuse
        // if there is a texture to load, load it
        if(FAILED(D3DXCreateTextureFromFileA(d3ddev,
                                             tempMaterials[i].pTextureFilename,
                                             &texture[i])))
        texture[i] = NULL;    // if there is no texture, set the texture to NULL
      }

 

could i not use D3DXCreateTextureFromFileA 3 times on the different texture states and apply the texture this way?

because in code i need to set device->SetTexture(&red); , device->SetTexture(&amba); device->SetTexture(&green);

http://i.imgur.com/hGL4nHH.png?1

thanks if you can help


Loading own md5 format causes scewed model

24 April 2015 - 11:35 AM

I am trying to load md5 data from my own format, i write it like this

its working fine for .obj , so i am not sure what the issue is

std::ofstream outfileBinary ("objdataBin.data",std::ofstream::out | std::ofstream::binary);
                
//write indices
outfileBinary.write((char*)&subset.indices[0], subset.indices.size() * sizeof(subset.indices[0]));
 
//write vertices
outfileBinary.write((char*)&subset.vertices[0], subset.vertices.size() * sizeof(subset.vertices[0]));
outfileBinary.close();
 
//reading the data
std::vector <Vertex> VecVerts;
std::vector <DWORD> VecIndices;
VecVerts.resize(subset.vertices.size());
VecIndices.resize(subset.indices.size());
 
std::ifstream infileBinary ("objdataBin.data",std::ifstream::in | std::ifstream::binary);
    if(infileBinary.is_open())
    {
        infileBinary.read((char*)&VecIndices[0], subset.indices.size() * sizeof(subset.indices[0]));
        infileBinary.read((char*)&VecVerts[0], subset.vertices.size() * sizeof(Vertex));
        
    }
 
// Create index buffer
                D3D11_BUFFER_DESC indexBufferDesc;
                ZeroMemory( &indexBufferDesc, sizeof(indexBufferDesc) );

                indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
                indexBufferDesc.ByteWidth = sizeof(DWORD) * subset.numTriangles * 3;
                indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
                indexBufferDesc.CPUAccessFlags = 0;
                indexBufferDesc.MiscFlags = 0;

                D3D11_SUBRESOURCE_DATA iinitData;
                iinitData.pSysMem = &VecIndices[0]; //&subset.indices[0];
                d3d11Device->CreateBuffer(&indexBufferDesc, &iinitData, &subset.indexBuff);
 
//Create Vertex Buffer
                D3D11_BUFFER_DESC vertexBufferDesc;
                ZeroMemory( &vertexBufferDesc, sizeof(vertexBufferDesc) );

                vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC;                            // We will be updating this buffer, so we must set as dynamic
                vertexBufferDesc.ByteWidth = sizeof( Vertex ) * subset.vertices.size();
                vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
                vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;                // Give CPU power to write to buffer
                vertexBufferDesc.MiscFlags = 0;

                D3D11_SUBRESOURCE_DATA vertexBufferData;
                ZeroMemory( &vertexBufferData, sizeof(vertexBufferData) );
                vertexBufferData.pSysMem = &VecVerts[0]; //&subset.vertices[0];
                hr = d3d11Device->CreateBuffer( &vertexBufferDesc, &vertexBufferData, &subset.vertBuff);
 

how do you work out the direction to move a third person camera?

26 February 2015 - 05:46 PM

if i wanted to make a third person camera, how do you work how the yaw direction and to move in that direction, prefilbly, i want to be using directx input for mouse data, thanks if you can help


PARTNERS