Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 04 Jun 2004
Offline Last Active Today, 09:09 AM

Posts I've Made

In Topic: Storing Player Changes to Procedurally Generated Worlds

28 August 2013 - 08:56 AM

Minecraft stores modified chunks, in full, on the disk and loads them when the chunk is needed again. So in order words, once a part of the procedurally generated world is modified and this modification cannot be deduced from the procedural system itself, that part of the world needs to be saved and is no longer procedural.

In Topic: File Loading Module

22 May 2013 - 08:43 AM

I think the main problem with this design is the genericness of the FileLoadingManager. If you rename this class to MeshLoadingManager, things will be more logical, and also the return types of various loading functions in the class is alot easier to comprehend (i.e. the LoadFile method returns an object of type IMesh).


You will then need different types of LoadingManagers for each type of object you want to load (i.e. Mesh, Sound, Texture, etc). You can then make a generic FileLoadingManager that contains a MeshLoadingManager, SoundLoadingManager, TextureLoadingManager and so on, with a file extension map to the different types of loading managers.


I would also rename the classes to FileLoader, MeshLoader and I wouldn't make them a singleton.


Hopefully you can adjust your design based on the above.

In Topic: Getting X/Y of mouse ONLY inside rendered area

21 February 2013 - 06:19 AM

The .NET Panel class has a method named PointToClient that accepts a Point as input. The Point should be in screen coordinates (in your case; the mouse cursor position relative to the screen itself), the result is a Point that is relative to the Panel.

In Topic: Dynamically create VertexType struct?

13 February 2013 - 03:30 PM

It does have to map 1 to 1 with the layout, indeed. But the pSysMem pointer doesn't have to be an array (or pointer) of type SVertex. You can create a byte array and fill it using the same method I used in the aforementioned example. You can use assimp's aiMesh to check if the layout has the position, normal, and so on and add them to the array of bytes in the same order as you did in the input layout.


I hope that suits your needs. Here is quick&dirty example (don't use it directly, it's just to show how it would work, I didnt try to compile it):



HRESULT SMesh::CreateVB(ID3D11DeviceContext* dc, ID3D11Device* device, aiMesh * mesh)
 int singleVertexSize = 3*3; // in bytes (x,y,z = 3 floats); always has position, so no need to check that
 if (mesh->HasNormals()) singleVertexSize += 3*3; // x,y,z = 3 floats
 if (mesh->HasTexCoords()) singleVertexSize += 2*3; // u,v = 2 floats
 ZeroMemory( &bufferDesc, sizeof(bufferDesc) );
    bufferDesc.Usage            = D3D11_USAGE_DEFAULT;
    bufferDesc.ByteWidth        = singleVertexSize * mesh->mNumVertices;
    bufferDesc.BindFlags        = D3D11_BIND_VERTEX_BUFFER;
    bufferDesc.CPUAccessFlags   = 0;
    bufferDesc.MiscFlags        = 0;
 vertexCount = mesh->mNumVertices;
 char * pmem = new char[singleVertexSize];
 float * fp;
 for (int i = 0; i < mesh->mNumVertices; ++i)
  fp = (float*)pmem;
  *fp = mesh->mVertices[i].x;
  *(fp+1) = mesh->mVertices[i].y;
  *(fp+2) = mesh->mVertices[i].z;
  if (mesh->HasNormals())
   *(fp+3) = mesh->mNormals[i].x;
   *(fp+4) = mesh->mNormals[i].y;
   *(fp+5) = mesh->mNormals[i].z;
  if (mesh->HasTexCoords())
   *(fp+6) = mesh->mTexCoords[i].u;
   *(fp+7) = mesh->mTexCoords[i].v;
  pmem += singleVertexSize;
 //ZeroMemory( &InitData, sizeof(InitData) );   not really needed, you fill all members below explicitly..
 InitData.pSysMem = pmem;
 InitData.SysMemPitch = 0;
 InitData.SysMemSlicePitch = 0;
 hr = device->CreateBuffer( &bufferDesc, &InitData, &vertexBuffer[0] );
 delete [] pmem;
 return hr;

In Topic: Dynamically create VertexType struct?

13 February 2013 - 02:07 PM

Dynamically generating an input layout based on what you need doesn't need to be complex at all. See below for a quick example.


The exciting part is ensuring a specific input layout is only loaded once and used across multiple meshes. I'm not sure if that's what you were asking?



int lastIndex = 0;
aiMesh * mesh; // <- assumed that your assimp mesh is in here
// repeat the sample below for normal, texcoord, tangents, etcetera..
if (mesh->HasPosition())
 dynamicLayout[lastIndex].SemanticName = "POSITION";
 dynamicLayout[lastIndex].SemanticIndex = 0;
 dynamicLayout[lastIndex].Format = DXGI_FORMAT_R32G32B32_FLOAT;
 dynamicLayout[lastIndex].InputSlot = 0;
 dynamicLayout[lastIndex].AlignedByteOffset = 0;
 dynamicLayout[lastIndex].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
 dynamicLayout[lastIndex].InstanceDataStepRate = 0;
ID3D11InputLayout * layout; // output is stored in here, you need this later on when rendering
HRESULT result = d3ddevice->CreateInputLayout(dynamicLayout, lastIndex, vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), &layout);
if (FAILED(result))
 //error handling
// after the input layout is created, you don't need the dynamicLayout array anymore, so it can go out-of-scope or you can delete it if it was dynamically allocated.