Hi, i am using this method for my billboarding.
But it seems that i can only set my billboards at position(0,0,0)
otherwise it displays incorrcect.
I have tried to translate before and after but nothing works.
How can i set any other position than origin?
this is my method:
[source lang="cpp"]void CreateBillboardMatrix(const D3DXVECTOR3& particlePos, const D3DXVECTOR3& cameraPos, D3DXMATRIX& out)
{
// compute billboard basis
D3DXVECTOR3 look = particlePos;
look = look - cameraPos;
D3DXVec3Normalize(&look,&look);
const D3DXVECTOR3 CAMERA_UP_VECTOR(0, 1, 0);
D3DXVECTOR3 camUp = CAMERA_UP_VECTOR;
D3DXVec3Normalize(&camUp,&camUp);
D3DXVECTOR3 right;
D3DXVec3Cross(&right,&camUp,&look);
D3DXVec3Normalize(&right,&right);
D3DXVECTOR3 up;
D3DXVec3Cross(&up,&look,&right);
D3DXVec3Normalize(&up,&up);
// set matrix values
D3DXMatrixIdentity(&out);
out._11 = right.x;
out._12 = right.y;
out._13 = right.z;
out._21 = up.x;
out._22 = up.y;
out._23 = up.z;
out._31 = look.x;
out._32 = look.y;
out._33 = look.z;
out._41 = particlePos.x;
out._42 = particlePos.y;
out._43 = particlePos.z;
}[/source]
Billboard problem
Can you post a screenshot of the incorrectly displayed billboard, or describe what's wrong please? The code you've posted looks OK to me (assuming that your billboard verts are set up in the correct orientation).
i can get it to work if:
as camera position i use a vector that is from my view of camera to position of the camera.
So the position for the camera i send into the function is (View-Pos)
If the Bilboard is in center (0,0,0) it is working, but i cant get the translation to work with this matrix.
If i translate the billboard after my rotation it gets scew and rotation is strange.
The thing is that the function should translate automatically but this function only work if i set my billboard to (0,0,0) position...
as camera position i use a vector that is from my view of camera to position of the camera.
So the position for the camera i send into the function is (View-Pos)
If the Bilboard is in center (0,0,0) it is working, but i cant get the translation to work with this matrix.
If i translate the billboard after my rotation it gets scew and rotation is strange.
The thing is that the function should translate automatically but this function only work if i set my billboard to (0,0,0) position...
Hi, i am using this method for my billboarding.
But it seems that i can only set my billboards at position(0,0,0)
otherwise it displays incorrcect.
I have tried to translate before and after but nothing works.
How can i set any other position than origin?
this is my method:
[source lang="cpp"]void CreateBillboardMatrix(const D3DXVECTOR3& particlePos, const D3DXVECTOR3& cameraPos, D3DXMATRIX& out)
{
// compute billboard basis
D3DXVECTOR3 look = particlePos;
look = look - cameraPos;
D3DXVec3Normalize(&look,&look);
const D3DXVECTOR3 CAMERA_UP_VECTOR(0, 1, 0);
D3DXVECTOR3 camUp = CAMERA_UP_VECTOR;
D3DXVec3Normalize(&camUp,&camUp);
D3DXVECTOR3 right;
D3DXVec3Cross(&right,&camUp,&look);
D3DXVec3Normalize(&right,&right);
D3DXVECTOR3 up;
D3DXVec3Cross(&up,&look,&right);
D3DXVec3Normalize(&up,&up);
// set matrix values
D3DXMatrixIdentity(&out);
out._11 = right.x;
out._12 = right.y;
out._13 = right.z;
out._21 = up.x;
out._22 = up.y;
out._23 = up.z;
out._31 = look.x;
out._32 = look.y;
out._33 = look.z;
out._41 = particlePos.x;
out._42 = particlePos.y;
out._43 = particlePos.z;
}[/source]
I see an error in your code, the look vector is CameraPos-billboardPos (not the other way around). Take into acount that if you have two positions A and B the vector B-A is facing B.
ah, that was the problem. now it works and my look vector looks like this instead.
D3DXVECTOR3 look = cameraPos - particlePos;
Thank you very much! =)
D3DXVECTOR3 look = cameraPos - particlePos;
Thank you very much! =)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement