Jump to content

  • Log In with Google      Sign In   
  • Create Account


All Sphere with same radius !


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 zonozz   Members   -  Reputation: 158

Like
0Likes
Like

Posted 26 February 2013 - 10:00 PM

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;
}

 

 



Sponsor:

#2 Yourself   Crossbones+   -  Reputation: 962

Like
0Likes
Like

Posted 27 February 2013 - 02:54 AM

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...



#3 zonozz   Members   -  Reputation: 158

Like
0Likes
Like

Posted 27 February 2013 - 08:34 AM

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();






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS