我在嘗試旋轉我的粒子系統時遇到問題。首先,我不是試圖旋轉每個粒子來試圖增強效果,我試圖做的是旋轉發射器位置。例如,如果我的發射器位置爲0,0,0,並且我在x和z軸上都發射粒子-5和5,那麼我將以與世界座標軸一致的方形方式發射粒子。我想旋轉這個,使它發射完全相同,但圍繞發射點旋轉。如何旋轉粒子系統以使其不繞世界軸線旋轉
// Each particle point is converted to a quad (two triangles)
[maxvertexcount(4)]
void mainGSDraw
(
point VS_VertIn inParticle[1], // One particle in, as a point
inout TriangleStream<GS_VertOut> outStrip // Triangle stream output, a quad containing two triangles
)
{
// Camera-space offsets for the four corners of the quad from the particle centre
// Will be scaled depending on distance of the particle
const float3 Corners[4] =
{
float3(-1, 1, 0),
float3(1, 1, 0),
float3(-1, -1, 0),
float3(1, -1, 0),
};
// Texture coordinates for the four corners of the generated quad
const float2 UVs[4] =
{
float2(0,1),
float2(1,1),
float2(0,0),
float2(1,0),
};
const float3x3 RotY =
{
cos(rotationAngle),0,sin(rotationAngle),
0,1,0,
-sin(rotationAngle),0,cos(rotationAngle)
};
GS_VertOut outVert; // Used to build output vertices
// Output the four corner vertices of a quad centred on the particle position
[unroll]
for (int i = 0; i < 4; ++i)
{
// Use the corners defined above and the inverse camera matrix to calculate each world
// space corner of the quad
float3 corner = Corners[i] * inParticle[0].Scale; // scale first
float3 worldPosition;
worldPosition = mul(inParticle[0].Position + mul(corner, (float3x3)InvViewMatrix), RotY) ; // face the camera
// Transform to 2D position and output along with an appropriate UV
outVert.ViewportPosition = mul(float4(worldPosition, 1.0f), ViewProjMatrix);
outVert.TexCoord = UVs[i];
outStrip.Append(outVert);
}
outStrip.RestartStrip();
} 以上是我的幾何着色器繪製函數的代碼,粒子爲點進來,擴展到四,縮放,然後世界上的地位進行計算。如果粒子系統處於原點,旋轉計算是錯誤的,它會按照我的需要旋轉系統,但只要我移動它,它就圍繞原點旋轉,所以我的問題是如何圍繞發射器的原點執行此旋轉不是世界零?該代碼已被減少,所以不需要回復此代碼可能無法正常工作。
你必須做那種計算: 1 - 發射點到世界軸的平移。 2 - 圍繞該軸旋轉。 3 - 將其翻回原來的位置。 這是一些常見的方法。當你不知道如何在0位以外的其他地方做某件事時,你只需要翻譯,計算和翻譯回來。你應該在互聯網上搜索,因爲我無法給你可靠或準確的細節。 – Morwenn