• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Medo Mex

Sparks Animation

12 posts in this topic

I have bunches of lines that I want to animate for sparks effect.

 

In my particle engine, I have gravity which I set to 0.0f, 10.0f, 0.0f. (sparks will move up)

 

The sparks will be generated in random initial position.

 

In the particles Update() code:

currentParticle.position += gravity / elapsedTime;

 

I use the following to draw each spark line:

void RenderSingleLine(D3DXVECTOR3& lineFrom, D3DXVECTOR3& lineTo)
{
     // Code to draw spark line according to lineFrom and lineTo here...
}

 

How do I set lineFrom and lineTo according to the current spark position and gravity?

 

I want the lines to always point at the direction it's moving toward.

0

Share this post


Link to post
Share on other sites

The question is what are you trying to accomplish.  Something like the sparks from http://www.youtube.com/watch?v=c_isjeljO_s?  I was experimenting and adding features to the Irlicht renderer and added the particle rotation/stretch etc code to make the little sparks there.  While those are actually stretched quads the same basic method of calculation works for lines.  What you need is the particle velocity in order to figure out the length and the direction.  While you can derive velocity from the information you post above, it will likely be unstable due to float rounding, so it is suggested to use real velocity stored with the particle.  Anyway, here is the basic way to do it:

 

struct Particle
{
  Vector3f    position;
  Vector3f    velocity;
};
 
void Update()
{
   velocity += gravity * elapsedTime;
   position += velocity * elapsedTime;
}
 
RenderSingleLine(
  particle.position,  // Start of the particle is current location.
  particle.position - particle.velocity * length  // Trail end is at "length" based on velocity.
);

 

Now that gives you a fair approximation of a spark.  Though, the tail sometimes ends up a bit odd.  What you may be really desiring is a trail and not a tail, in which case you basically just record a list of past positions, drop intermediates which are within a given tolerance and draw a line list instead of a simple velocity tail.

 

If you expand on your desires, I'm sure folks can help out more..

1

Share this post


Link to post
Share on other sites

When I set the gravity to 0.0f, 10.0f, 0.0f, the sparks will go up in a straight direction, how do I make the sparks spread when they go up?

 

Here is how I want the sparks to move:

 

 End point
\         /
 \       /
  \     /
   \   /
    \ /
Start point
0

Share this post


Link to post
Share on other sites

Oh...  You sound like you need to get your concepts worked out a bit better.  There are three parts to this:

 

Emission point:  Needs to be a point and a full coordinate system, i.e, three normalized vectors at right angles to each other.  We'll say the +Z axis is the direction you want to emit the particles.

Emission velocity: This is a scalar value of how fast the particle moves.  We'll say it is 20.0.

Emission randomness: Another scalar value, we'll just use this to narrow the emission cone.  We'll say .5 which is basically saying 45 degree emission angle max.

Gravity: Given the above, we'll say gravity is {0, -10, 0}.

 

Put this all together using crappy C rand:

 

particle.position = emission.point;

Vector3f offset = Normalize( emission.x * (rand()/float( RAND_MAX )*2.0f-1.0f) + emission.y * (rand()/float( RAND_MAX )*2.0f-1.0f) );

particle.velocity = Normalize( emission.z+offset*emission.randomness )*emission.velocity;

 

Now, using velocity as I did in the prior reply during you update and the mentioned negative gravity, most of your particles should emit in random directions up to 45 degree's around the emission vector and then curve down with gravity over time.

0

Share this post


Link to post
Share on other sites

I'm trying to convert your code to D3DX*

 

But having some problems

 

The following is a float value? How could I put it in D3DXVECTOR3?

 

emission.x * (rand()/float( RAND_MAX )*2.0f-1.0f) + emission.y * (rand()/float( RAND_MAX )*2.0f-1.0f)

 

Same apply here:

 

particle.velocity = Normalize( emission.z+offset*emission.randomness )*emission.velocity;

 

"emission.z+offset*emission.randomness" is a float value as well, how do you normalize it and make it D3DXVECTOR3?

0

Share this post


Link to post
Share on other sites

Been a while since I've done D3DX stuff, sorry.  Let me see if I can explain it well enough so you can convert it:

 

emission.x would be the "X" value of the coordinate system around your emission point.  It is a Vector3.

 

You scale, or set the length/magnitude, of the x vector to the random value between -1 and +1.

 

So, the result should be a vector3 again.

 

Do the same to the y coordinate axis and add that to the result of the x scaling.

 

You end up with a randomized vector3 in the x/y plane.

 

 

The final item is normalize the emission direction (+z) plus the offset vector which is scaled by the randomness value.  Finally you scale the result by the desired velocity.

 

NOTE: Perhaps this will help, nothing other than scale, add or normalize are in use within this.

Edited by AllEightUp
0

Share this post


Link to post
Share on other sites

I'm confused.

 

emission is a Vector3, emission.z is a float.

 

If I do the following, the program will not compile:

D3DXVec3Normalize(emission.z+offset*emission.randomness);

 

However, I tried doing it using the way I have in my engine, it could be the same way as your way:

void generateNewParticle()
{
    // Code to generate a new particle here...
    D3DXVECTOR3 randVec = GetRandomVec();
    particle.velocity += randVec * 4.0f;
}

 

D3DXVECTOR3 GetRandomVec()
{
    D3DXVECTOR3 vVector;
    vVector.z = getRandMinMax( -1.0f, 1.0f );
    float radius = (float)sqrt(1 - vVector.z * vVector.z);
    float t = getRandMinMax( -D3DX_PI, D3DX_PI );
    vVector.x = (float)cosf(t) * radius;
    vVector.y = (float)sinf(t) * radius;
    return vVector;
}

 

Althought it works, I have slight problems at the particles generation point, the particles are not looking at the moving direction when generated:

[attachment=15766:problem.png]

Edited by Medo3337
1

Share this post


Link to post
Share on other sites

Up. Any idea how can I make the sparks look at the moving direction when generated so I get rid of the parts around the circles?

0

Share this post


Link to post
Share on other sites

Sorry but i don't know the answer to your question. Although you could cover that up with smoke maybe? It doesn't look that bad.

 

I just wanted to say that i really like how 3rd image looks like. Congrats. biggrin.png

Could you possibly make a video so i can see it in action and moving?

1

Share this post


Link to post
Share on other sites

@belfegor: Well, your help is one of the main reasons that made me able to accomplish that smile.png I'm still doing some improvement so I could upload a video when I finish.

 

Everyone,

 

In this screenshot, the sparks looks messed up, because it's getting generated pointing at random direction, then when it move it point at the UP direction (correct direction), this problem is much more noticeable when the particles are moving:

(I think the problem is be more clear in this screenshot)

[attachment=15782:5644.png]

 

I'm looking for a way to modify the code to make it look at the moving direction when generated.

 

So my question is: How do I make the particles generate while looking at the gravity direction?

 

Here is how I generate the particles (I need to update the following code to fix this problem):

D3DXVECTOR3 randVec = getRandVector();
particle.velocity += randVec * 4.0f; // 4.0f = How much spread

Here is how I render the sparks lines:

               // D3DXVECTOR3 lineFrom      D3DXVECTOR3 lineTo
RenderSingleLine( currentParticle.position, currentParticle.position - currentParticle.velocity * lineLength );

 

0

Share this post


Link to post
Share on other sites

Okay, I figured one step towards solving this problem:

 

How do I modify the following code to make it generate a random vector looking at or close the direction of gravity?

 

Basically, I want the particle random vector to be limited to the half circle of the direction of the gravity

 

I think the line following line should be modified:

float t = getRandMinMax( -D3DX_PI, D3DX_PI ); // I want to limit this circle

 

 

D3DXVECTOR3 getRandVector(D3DXVECTOR3 gravity)
{
     D3DXVECTOR3 vVector;
 
    // Pick a random Z between -1.0f and 1.0f.
    vVector.z = GetRandomMinMax( -1.0f, 1.0f );
 
    // Get radius of this circle
    float radius = (float)sqrt(1 - vVector.z * vVector.z);
 
    // Pick a random point on a circle.
    float t = getRandMinMax( -D3DX_PI, D3DX_PI );
 
    // Compute matching X and Y for our Z.
    vVector.x = (float)cosf(t) * radius;
    vVector.y = (float)sinf(t) * radius;
 
    return vVector;
}
 
[attachment=15792:gr.png]

 

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0