Sign in to follow this  

All Sphere with same radius !

This topic is 1749 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone !

 

I make a class Model, and ModelsManager, I use Model  to initialize 3 spheres with 1 Model obj ( m_pModel ). After each initialize I save model to ModelsManager by AddModel(int modelID, CGEModel** ppSource); I do copy the vertex buffer / index buffer / texture information to ModelsManager's model nodes. But when I try to render all spheres , I see all spheres have same radius ? ( I use different radius to initialize each sphere !).

 

Please help me !

 

Here is my code to initialize 3 spheres and save to ModelsManager.

result = this->m_modelsManager.Initialize(this->m_pGraphics->GetD3DDevice(), 
		this->m_pGraphics->GetD3DObj()->GetDeviceContextPointer());
	if( !result )
		return false;

	this->m_pModel = new CGEModel;
	if( !this->m_pModel )
		return false;

	result = this->m_pModel->InitializeSphere(this->m_pGraphics->GetD3DDevice(), 2.0f, 50, 50);
	if( !result )
		return false;

	result = this->m_pModel->SetTexture(this->m_pGraphics->GetD3DDevice(), L"../Res/Tex/Earth2.jpg");
	if( !result )
		return false;

	this->m_modelsManager.AddModel(TESTSPHERE_EARTH, &this->m_pModel);

	// Desc -
	// m_pModel ??????????????????????
	// ???????????????????????m_pModel
	// ?Shutdown?????????????????
	this->m_pModel->Shutdown();

	result = this->m_pModel->InitializeSphere(this->m_pGraphics->GetD3DDevice(), 1.0f, 50, 50);
	if( !result )
		return false;

	result = this->m_pModel->SetTexture(this->m_pGraphics->GetD3DDevice(), L"../Res/Tex/Earth5.jpg");
	if( !result )
		return false;

	this->m_modelsManager.AddModel(TESTSPHERE_P1, &this->m_pModel);
	this->m_pModel->Shutdown();

	result = this->m_pModel->InitializeSphere(this->m_pGraphics->GetD3DDevice(), 0.5f, 50, 50);
	if( !result )
		return false;

	result = this->m_pModel->SetTexture(this->m_pGraphics->GetD3DDevice(), L"../Res/Tex/Earth.jpg");
	if( !result )
		return false;

	this->m_modelsManager.AddModel(TESTSPHERE_P2, &this->m_pModel);
	this->m_pModel->Shutdown();

 

 

The code to copy data from source.

bool CGEModel::_copy(ID3D11Device* pDevice, ID3D11DeviceContext* pDeviceContext, const CGEModel* pSource)
{
	ReleaseWithoutDel<ID3D11Buffer*>(this->m_pVertex_buffer);
	ReleaseWithoutDel<ID3D11Buffer*>(this->m_pIndex_buffer);

	HRESULT result;

	this->m_vertexCount = pSource->m_vertexCount;
	this->m_indexCount = pSource->m_indexCount;
	this->m_triangleCount = pSource->m_triangleCount;

	D3D11_BUFFER_DESC vbDesc;
	D3D11_BUFFER_DESC ibDesc;

	// If source's vertex data & index data are empty, this function will not woking.
	if( NULL == pSource->m_pVertex_buffer ||
		NULL == pSource->m_pIndex_buffer )
		return false;

	// Copy vertex data & index data
	vbDesc.Usage = D3D11_USAGE_DEFAULT;
	vbDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vbDesc.ByteWidth = this->m_vertexCount * sizeof(GEVertex3D_Normal_Tex);
	vbDesc.CPUAccessFlags = 0;
	vbDesc.MiscFlags = 0;
	vbDesc.StructureByteStride = 0;

	result = pDevice->CreateBuffer(&vbDesc, NULL, &this->m_pVertex_buffer);
	if(FAILED(result) )
		return false;

	pDeviceContext->CopyResource(this->m_pVertex_buffer, pSource->m_pVertex_buffer);
	if( NULL == this->m_pVertex_buffer )
		return false;

	ibDesc.Usage = D3D11_USAGE_DEFAULT;
	ibDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
	ibDesc.ByteWidth = this->m_indexCount * sizeof(unsigned long);
	ibDesc.CPUAccessFlags = 0;
	ibDesc.MiscFlags = 0;
	ibDesc.StructureByteStride = 0;

	result = pDevice->CreateBuffer(&ibDesc, NULL, &this->m_pIndex_buffer);
	if( FAILED(result) )
		return false;

	pDeviceContext->CopyResource(this->m_pIndex_buffer, pSource->m_pIndex_buffer);
	if( NULL == this->m_pIndex_buffer )
		return false;

	
	// Copy texture data
	if( NULL == this->m_pTexturePath )
		return false;

	result = this->_load_texture(pDevice, pSource->m_pTexturePath);
	if( FAILED(result) )
		return false;

	return true;
}

 

 

Share this post


Link to post
Share on other sites

I think the problem is that the model manager takes a CGEModel** but the adress of m_pModel is always the same.

you assign a different adress to the pointer (using new CGEModel) but the adress of that pointer doesn't change...

Share this post


Link to post
Share on other sites

I think the problem is that the model manager takes a CGEModel** but the adress of m_pModel is always the same.

you assign a different adress to the pointer (using new CGEModel) but the adress of that pointer doesn't change...

 

Thank you for help. I've done this problem.

 

I make a interface called RenderAllModels() to do Render() for each model obj first, and then use shader to render it. So the shader will render the last model's buffer data, this is the problem I made.

 

 

The right way to do I change :

 

For 0 to numOfModels

do

     m_modelsManager[i]->Render();

     shader->Render();

 

NOT like this :

 

m_modelsManager.RenderAllModels();

 

For 0 to numOfModels

do

     shader->Render();

Share this post


Link to post
Share on other sites

This topic is 1749 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this