gpt4 book ai didi

c++ - 如何旋转粒子系统使其不绕世界轴旋转

转载 作者:太空宇宙 更新时间:2023-11-04 12:09:31 24 4
gpt4 key购买 nike

我在尝试旋转我的粒子系统时遇到问题。首先,我并不是要旋转每个粒子来尝试增强效果,我想做的是旋转发射器位置。因此,例如,如果我有一个位于 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();

}上面是我的几何着色器绘制函数的代码,一个粒子作为一个点进入并扩展为四边形,缩放然后计算世界位置。如果粒子系统在原点,旋转计算是错误的,它会完全按照我想要的方式旋转系统,但是一旦我移动它,它就会围绕原点旋转,所以我的问题是如何围绕发射器的原点进行旋转不是零世界?代码已被删减,因此无需回复此代码可能无效的问题。

最佳答案

您可以将粒子从发射器原点的平移乘以旋转,然后添加发射器从世界原点的平移。

关于c++ - 如何旋转粒子系统使其不绕世界轴旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10434635/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com