Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (9 posts)

Particle3DSample and Camera

Last post 6/25/2009 10:19 AM by Janellesnow. 8 replies.
  • 5/22/2009 2:53 PM

    Particle3DSample and Camera


    I am working on the particle in my project from the tutorial sample of Particle3DSample. I am new with XNA.

    I notice that the AddParticle(position, velocity) is causing the particle to be following the camera when ever I move the camera. And particle need camera.viewMatrix and camera.projectionMatrix in order to render in the game world. I found a forum discussion http://forums.xna.com/forums/p/27329/150327.aspx#150327, but i do not quite understand.

    Can anyone please help me? How can I get the particle to render in the world, not following the camera position?

     

    /// </summary> 
    public void SetCamera(Matrix view, Matrix projection)
     
    {
    effectViewParameter.SetValue(view);
    effectProjectionParameter.SetValue(projection);
    }

     


    Thanks in advance.
  • 5/22/2009 6:27 PM In reply to

    Re: Particle3DSample and Camera

    The particles are moving along with the camera because the position you give them is in the local coordinate space of camera instead of the world's coordinate system. When you move the camera, the particles positions have to be updated relative to the camera.  

    For example, if the camera moves up, what do you expect to happen?  All the particles should move down, right?   If your camera has a position then you need to store that position and subtract that from the particles position when you add it to the sceen.


    One important thing to remember with graphics is there really is no mathematical difference between moving an object in one direction or moving the camera in the opposite direction.   The end position that the graphics card uses will be the same.   
  • 5/22/2009 6:57 PM In reply to

    Re: Particle3DSample and Camera

    caedicus: The particle sample creates particles in world space, not view space, so you don't need to move each particle every time the camera changes.

    Janellesnow: I don't understand why you quoted the SetCamera method at the end of your question? Are you calling that method? If not, there's your problem: you need to call this every frame to tell the particle system where your camera is at.

  • 5/23/2009 5:03 AM In reply to

    Re: Particle3DSample and Camera

    Shawn Hargreaves:
    The particle sample creates particles in world space, not view space,


    Yes, i added the "setCamera" and I am wondering where is the world matrix that pass through the ParticleEffect.fx. I notice I have to setCamera in order to make the particle visible in the game.

    // Camera parameters. In ParticlEffect.fx

    float4x4 View;
    float4x4 Projection;
    float ViewportHeight;


    Thanks for your explanation. It is really helpful informations.

  • 5/29/2009 9:40 AM In reply to

    Re: Particle3DSample and Camera

    Hi,

    I discovered another issue on Particle3DSample and Camera in my project. I hope anyone can please give me some advices.

    I notice that when the Camera zooms in, to look at the particle nearer, the particle seems to be scattered and the sprite becomes smaller. When the Camera is moved further away from the particles, the particles starts to become bigger, and brighter. I re-tested on the original xml particle source code. XML particle sample does not have my problem.

    Initially, I am suspecting it is some screen space distance that particleEffect.fx is calculating, but cannot really understand where and why is the problem? But now, I am really confused where and what is causing the texture sprite to render smaller when Camera is near to the particles.

    I continue to test the problem, in my project, particleSystem.as is not inherited from DrawableGameComponent, but I have tested in the original xml sample to confirm it is not the DrawableGameComponent.

    Hope anyone can give me some advices where am I wrong.

    Thanks in advance

  • 5/29/2009 5:34 PM In reply to

    Re: Particle3DSample and Camera

    Janellesnow:
    I am wondering where is the world matrix that pass through the ParticleEffect.fx


    I'm not sure what you mean by this. There is no world matrix in the ParticleEffect.fx from our sample. Particles are created already in world space, not in object space, so they only need a View and Projection matrix (which are specified by the ParticleSystem.SetCamera method) to render them.
  • 5/29/2009 5:35 PM In reply to

    Re: Particle3DSample and Camera

    Janellesnow:
    notice that when the Camera zooms in, to look at the particle nearer, the particle seems to be scattered and the sprite becomes smaller.


    There is a maximum size that point sprites can have (the exact limit varying depending on your GPU). If the camera gets too close to the particles, the hardware will clamp them to this maximum size.
  • 6/20/2009 4:52 AM In reply to

    Re: Particle3DSample and Camera

    Thanks for telling me the maximum sprite size. I have increased the sprite size to 1024, instead of 256.

    I bump into another issue, that when I force a large amount of particles to play on multiple loops at the same point, there is no particle emitting out for a while. It seems be running out of particles. I am wondering if it is due to GPU again.

    It seems to be there is a limit to the maximum of particles can create. How do I solve this problem that the particles failed to appear? Or can I increase the limit?


    Thanks in advance

    [Continue with my trial and error]

    I added the MaxParticles to 10000 inside my particle_explosion.xml. I can see there are more fequency of explosion created, but at the same time, the explosion becomes bigger by itself. I wish to generate more explosions but not bigger explosion. Hope there is anyone who can give me your advice if you are also doing the 3D XNA particles.

  • 6/25/2009 10:19 AM In reply to

    Re: Particle3DSample and Camera

    [Continue with my trial and error]

    I added the MaxParticles to 10000 inside my particle_explosion.xml. I can see there are more fequency of explosion created, but at the same time, the explosion becomes bigger by itself. I wish to generate more explosions but not bigger explosion. Hope there is anyone who can give me your advice if you are also doing the 3D XNA particles.
Page 1 of 1 (9 posts) Previous Discussion Next Discussion