Sign in to follow this  
xero7

Raining Visualisation

Recommended Posts

Hi there. i'm new here. i have a problem according to my study. i'm doing final project for my study titled "Raining Visualisation". basically i need to visualyse the rain using particle system. here are some question i wanna us you guys: is there any technical paper similar to my project? what is the method i need to use to create the rain? that's all for now. sorry for my broken english :P.

Share this post


Link to post
Share on other sites
Rain (and similar things) is done through "particles." I can't give you any technical papers because I don't know which platform (if any) you are using. Post some specifics like that and we'll be able to help you more.

Share this post


Link to post
Share on other sites
Depending on how real you want it to look, you can use this simple trick:
Create a system of particles (a few K particles works well). Each particle should have the following properties: x_pos, y_pos, plane, size, and mass (optional). The display part should be obvious. The update part is simple too; just update the x_pos and y_pos according to the wind and gravity (for example the wind moves the particles on x, while the gravity moves them on y). The gravity and wind should move the particles from plane 1 pretty fast, those from plane 2 a little slower, those from plane 3 even slower, etc. 5-10 planes should do the trick. Then when a particle dies (y<bottom of the screen) mark it as free, and in the next update cycle put it somewhere near the top of the screen.
I used this algorithm a few time, with good results. Optionally, if you want to simplify it, remove the wind (and x_pos and the mass).

Share this post


Link to post
Share on other sites
i'm doing my project in windows xp environment...using visual studio c++ n opengl...can anyone give me a simple coding for rain so that i can understand how it's work...for ur information, i'm not really familiar with opengl..tq :) anyway

Share this post


Link to post
Share on other sites
Quote:
can anyone give me a simple coding for rain so that i can understand how it's work.

here is a sample from the book Focus on Terrain Programming by Trent Polack. i've shortened/edited it for discussionial purposes (alright, the book does have a rain simulation, but i can't find the cd with the full source). oh well, no pain no gain.

struct SParticle {
float life; // the lifespan of a particle (in time)
float[3] pos; // the position
float[3] velocity; // the velocity
float mass; // the mass of a particle - for physics
float size; // the size of the particle on the screen
float[3] color; // the color of the particle
float translucency; // the translucency of the particle (how clear it is). is useful for making it disappear bit by bit over time
float friction; // the friction the particle creates
};




a basic outline for a particle engine

class CParticle_Engine
{
private:
SParticle* m_particles; // the list of active particles
int m_numparticles; // how many particles we have
float[3] m_gravity; // the gravity (or force) applied to the particles (as a whole)
float life; // the default lifespan
float[3] color; // the default color
float friction; // the default force applied
/*
* creates a particle and adds it to the list, based upon the
* default criteria set above
*/

void CreateParticle(float velX, float velY, float velZ);

public:
CParticle_Engine() {}
~CParticle_Engine() {}
/*
* updates all the particles. those whose lifespans
*/

void Update()
{
float[3] momentum;
for(int i = 0; i < m_numparticles; i++)
{
// age the particles
m_particles[i].life -= 1;
// only update the particle if it is alive
if(m_particle[i].life > 0.0f /* || particlepos > somevalue ect.. */)
{
// update the particle
// mostly physics calculation
// update velocity, momentum, transluceny, ect.
// left for you to do
}
else
{
// remove the particle from the list
}
}
}
void DrawParticles()
{
for(int i = 0; i < m_numparticles; i++)
{
// use opengl here
glBegin(GL_QUADS)
// set color
// set texture
// set alpha blending (if any)
// set the texture coords (if a texture is
// loaded)
// do some billboard calculations to ensure
// we don't just see air
glVertex3f(// top left of particle);
glVertex3f(// top right of particle);
glVertex3f(// bottom right of particle);
glVertex3f(// bottom left of particle);
glEnd();
}
}
};





as you can see, the opengl part isn't hard - you just use it to draw the particles, while raw C++ is used for everything else. you need to be careful, however, that you only load one texture to use for each particle that uses it, and store it in the engine instead of in each particle. also, if you're using the system in 3d, you need to use billboarding to ensure the particles all face the camera, otherwise when you rotate you won't see anything (from a side-on view). also look into data interpolation for more realistic output.

for further reference, here is a particle engine with full source using C++ and Opengl, although it models a comet and not rain. it also uses triangle strips, instead of quads.

cheers.

Share this post


Link to post
Share on other sites
em, tq for ur reply...actually i'm not really familiar with opengl...so can anyone give the code for rain...basic coding also accepted because all i need now is to understand the method to generate rain...

Share this post


Link to post
Share on other sites
stormrunner actually did provide you a good bit of the code, the rest you'll have to figure out yourself (tip: look it up in the OGL manual online).

The basic algorithm is fairly simple once you can render some particles (even if static). All you need to do after that is randomly position them a few at a time within the bounds of a rect above the player, and animate them down. When they hit the ground, start them back up at the top.

Share this post


Link to post
Share on other sites
i've tried the example in lesson19 but there are some errors when i tried to run the program...what should i do to solve this problem..help me ASAP...the errors are:

--------------------Configuration: Lesson19 - Win32 Debug--------------------
Linking...
Lesson19.obj : error LNK2001: unresolved external symbol _auxDIBImageLoadA@4
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glTexImage2D@36
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glTexParameteri@12
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glBindTexture@8
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glGenTextures@8
Lesson19.obj : error LNK2001: unresolved external symbol _gluPerspective@32
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glLoadIdentity@0
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glMatrixMode@4
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glViewport@16
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glHint@8
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glBlendFunc@8
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glEnable@4
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glDisable@4
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glClearDepth@8
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glClearColor@16
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glShadeModel@4
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glEnd@0
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glVertex3f@12
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glTexCoord2d@16
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glBegin@4
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glColor4f@16
Lesson19.obj : error LNK2001: unresolved external symbol __imp__glClear@4
Lesson19.obj : error LNK2001: unresolved external symbol __imp__wglDeleteContext@4
Lesson19.obj : error LNK2001: unresolved external symbol __imp__wglMakeCurrent@8
Lesson19.obj : error LNK2001: unresolved external symbol __imp__wglCreateContext@4
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Lesson19.exe : fatal error LNK1120: 26 unresolved externals
Error executing link.exe.

Lesson19.exe - 27 error(s), 0 warning(s)

Share this post


Link to post
Share on other sites
Did you download the project from nehe? It looks like you're not linking against opengl32.lib. Check your linker settings. Er, although it also apparently couldn't find main. I just loaded it in Visual Studio and it worked for me..

sam.

Share this post


Link to post
Share on other sites
i've link to the glut32.lib, and opengl32.lib (project>settings>link...right?)...but there's still 1 error..help me :)..the error is like this :-

--------------------Configuration: Lesson19 - Win32 Debug--------------------
Linking...
LINK : fatal error LNK1104: cannot open file ",.obj"
Error executing link.exe.

Lesson19.exe - 1 error(s), 0 warning(s)

Share this post


Link to post
Share on other sites
i've done what you told me to do, but there's still some error. what should i do next?

--------------------Configuration: Lesson19 - Win32 Debug--------------------
Linking...
Lesson19.obj : error LNK2001: unresolved external symbol _auxDIBImageLoadA@4
Lesson19.obj : error LNK2001: unresolved external symbol _gluPerspective@32
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Lesson19.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.

Lesson19.exe - 4 error(s), 0 warning(s)

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