1
votes

I am having a problem when trying to rotate my particle system. First off, I am not trying to rotate each particle to try and enhance an effect what I am trying to do is rotate the emitter position. so for example if i have an emitter position at 0,0,0 and I emit particles -5 and 5 on both the x and z axes I will end up with particles emitting in a square fashion that is in line with the world axes. What i want to is rotate this so that it emits exactly the same but rotated around the emitter point.

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

} Above is the code for my geometry shader draw function, a particle as a point comes in and is expanded to a quad, scaled and then the world position is calculated. The rotation calculation is wrong if the particle system is at the origin it rotates the system exactly as i want it but as soon as I move it, it rotates around the origin so my question is how to do this rotation around the origin of the emitter not the world zero? The code has been cut down so no need for replies that this code might not work.

1
You have to do that kind of calculs: 1 - Translation of the emitting point to the world axis. 2 - Have it rotate around that axis. 3 - Translate it back to its original position. It's some common method. When you don't know how to do something at some other place than the 0 position, you just translate, compute and translate back. You should search the internet for that because I won't be able to give you reliable or exact details about it.Morwenn

1 Answers

1
votes

You would multiple the translation of your particle from the emitter origin by the rotation, then add the translation of the emitter from the world origin.