Sign in to follow this  

[Help] Falling Snow Effect using MS C++ v 6.0

This topic is 3740 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Guys... can you help me here... I want to make a snowfall simulator using MS C++ ver 6.0. I've already create but not done yet... i'm stuck with my program... :( Help me please... im one of you have the program, please share it to me.. Pleasee...

Share this post


Link to post
Share on other sites
First of all, you need to be more specific. What is holding you up? You say you've "already create", so what's the problem? (Nobody is probably going to just give you code based on what you've said so far.)

Secondly, be prepared for a slew of posts telling you to drop VC6. You can get Visual C++ 2005 Express for free, and it is immeasurably superior to VC6. There is no reason to still be using a non-standard C++ compiler like VC6, 10 years after it was released.

Share this post


Link to post
Share on other sites
To PCN and Smithy :

Thanks for your reply guys... yes, i'm stuck :( my snow won't fall naturally.. FYI, my program is based to Michael Asgard journal... i've already follows the instruction they said there... but still... :(

where can i send my program to you guys? please give me your email address...

Share this post


Link to post
Share on other sites
Please Download my File.. This is my unfisished snow project...

http://gudangupload.com/filelink.php?filecode=5ff4a2b22bba5826e911f6d4a260f082

Please..if one of you can fix it..please... help me...


Thanks.

Share this post


Link to post
Share on other sites
The board can't read your mind. We recognize that the snow doesn't look like it should - but that's really all you've told us.

  • Is it green?


  • Is it falling up?


  • Is it falling straight down without drifting?


  • Is it failing to accumulate?


All of these are ways in which snow might not look natural - and I can probably think of thousands of other ways too detailed to describe in a sentence. If you want help:

  • Assume no one has read the code you're talking about


  • Post code (using [ source ] [ /source ] tags)


  • Post screenshots of what you want and what you are getting.


  • Do not ask people to download random files from the internet - it makes us nervous and most people (myself included) simply won't do it.


  • Describe your problem in detail - simply saying it doesn't look right is far too vague for us to do anything other than make random guesses.

Share this post


Link to post
Share on other sites
[laughs] I mean like, does it fall in a straight path or does it do weird tings like swirl in circles and do flips? That stuff.

EDIT: I see I was beaten, also the link doesn't work, but I agree with cshowe, post source and screen shots for better help.

Share this post


Link to post
Share on other sites
I understand that... ok then...i'll show the code here.. :)

This is CxxxView code :


// OpenGL3DView.cpp : implementation of the COpenGL3DView class
//

#include "stdafx.h"
#include "OpenGL3D.h"

#include "OpenGL3DDoc.h"
#include "OpenGL3DView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

const int SNOW = 1;
const int MAX_ACC = 50;
/////////////////////////////////////////////////////////////////////////////
// COpenGL3DView

IMPLEMENT_DYNCREATE(COpenGL3DView, CView)

BEGIN_MESSAGE_MAP(COpenGL3DView, CView)
//{{AFX_MSG_MAP(COpenGL3DView)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_SIZE()
ON_WM_KEYDOWN()
ON_WM_TIMER()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COpenGL3DView construction/destruction

COpenGL3DView::COpenGL3DView()
{
srand((unsigned)time(NULL));
// TODO: add construction code here
m_eye = CBdVector(20, 50, 50);
m_look = CBdVector(20, 50, 0);
m_up = CBdVector(0, 1, 0);
UVN();
IsiMatrixKeModelView();

tTemp=0;

count = 0;
timeNextFall = 0;

width = 0;

///////////////////////////////
// Temperature between 0 till -10
Temperature = rand() % 11 - 10;
uWind = CBdVector(0, -3, 0);
DeltaT=0.1;
snow[0].initialize(Temperature, uWind, DeltaT);

t=0;


}

COpenGL3DView::~COpenGL3DView()
{
}

BOOL COpenGL3DView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// COpenGL3DView drawing

void COpenGL3DView::OnDraw(CDC* pDC)
{
COpenGL3DDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here

glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);


GambarSumbuXYZ();
CString text;
text.Format("time next fall: %lf", timeNextFall);
pDC->TextOut(100, 100, text);
// for each snows
for(int i = 0; i < count; i ++)
{
if(snow[i].getPos().Y() - 2 > 0)
{
glPushMatrix();
glTranslated(snow[i].getPos().X(), snow[i].getPos().Y(), snow[i].getPos().Z());
glCallList(SNOW);
glPopMatrix();
}
}
/*
HDC hDC = wglGetCurrentDC();
SwapBuffers(hDC);
*/

glFlush();
}

/////////////////////////////////////////////////////////////////////////////
// COpenGL3DView printing

BOOL COpenGL3DView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}

void COpenGL3DView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}

void COpenGL3DView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// COpenGL3DView diagnostics

#ifdef _DEBUG
void COpenGL3DView::AssertValid() const
{
CView::AssertValid();
}

void COpenGL3DView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}

COpenGL3DDoc* COpenGL3DView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COpenGL3DDoc)));
return (COpenGL3DDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// COpenGL3DView message handlers

int COpenGL3DView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;

// TODO: Add your specialized creation code here
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
//PFD_DOUBLEBUFFER,
PFD_SUPPORT_GDI, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
32, // 32-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};

HWND hWnd = GetSafeHwnd();
HDC hDC = ::GetDC(hWnd);

int iPixelFormat = ChoosePixelFormat(hDC, &pfd);
SetPixelFormat(hDC,iPixelFormat, &pfd);

HGLRC hRC = wglCreateContext(hDC);
if (hRC)
wglMakeCurrent(hDC, hRC);
else
return (-1);

return 0;
}

void COpenGL3DView::OnDestroy()
{
CView::OnDestroy();

// TODO: Add your message handler code here
HGLRC hRC = wglGetCurrentContext();

if (hRC)
{
wglMakeCurrent(NULL, NULL);

HWND hWnd = GetSafeHwnd();
HDC hDC = wglGetCurrentDC();
::ReleaseDC(hWnd, hDC);

wglDeleteContext(hRC);
}
}

void COpenGL3DView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
width = cx;
height = cy;
// TODO: Add your message handler code here
glViewport(0, 0, cx, cy);
// Tentukan projeksi
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, double(cx)/cy, 1, 10000);
// menentukan kamera
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(m_eye.X(), m_eye.Y(), m_eye.Z(),
m_look.X(), m_look.Y(), m_look.Z(),
m_up.X(), m_up.Y(), m_up.Z());
}

void COpenGL3DView::UVN()
{
m_n = (m_eye - m_look).Normalize();
m_u = (m_up * m_n).Normalize();
m_v = m_n * m_u;
}

void COpenGL3DView::IsiMatrixKeModelView()
{
m_matrix[0] = m_u.X();
m_matrix[1] = m_v.X();
m_matrix[2] = m_n.X();
m_matrix[3] = 0;

m_matrix[4] = m_u.Y();
m_matrix[5] = m_v.Y();
m_matrix[6] = m_n.Y();
m_matrix[7] = 0;

m_matrix[8] = m_u.Z();
m_matrix[9] = m_v.Z();
m_matrix[10] = m_n.Z();
m_matrix[11] = 0;

CBdVector d;
d.SetVector(-m_eye.DotProduct(m_u),
-m_eye.DotProduct(m_v),
-m_eye.DotProduct(m_n));

m_matrix[12] = d.X();
m_matrix[13] = d.Y();
m_matrix[14] = d.Z();
m_matrix[15] = 1;


glMatrixMode(GL_MODELVIEW);
glLoadMatrixd(m_matrix);

}

void COpenGL3DView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(nChar == VK_UP)
{
// Pitch(10);
GeserKamera(0, 0, 10);
Invalidate(false);
}
else if(nChar == VK_DOWN)
{
GeserKamera(0, 0, -10);
//Roll(-10);
Invalidate(false);
}
else if(nChar == VK_LEFT)
{
GeserKamera(10, 0, 0);
Invalidate(false);
}
else if(nChar == VK_RIGHT)
{
GeserKamera(-10, 0, 0);
Invalidate(false);
}
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}

void COpenGL3DView::Pitch(double sudutDerajat)
{
double sudut = sudutDerajat / 180 * 3.14;
CBdVector uAksen, vAksen, nAksen;
uAksen = m_u;
vAksen = m_v * cos(sudut) - m_n * sin(sudut);
nAksen = m_v * sin(sudut) + m_n * cos(sudut);

m_u = uAksen;
m_v = vAksen;
m_n = nAksen;
}

void COpenGL3DView::Yaw(double sudutDerajat)
{
double sudut = sudutDerajat / 180 * 3.14;
CBdVector uAksen, vAksen, nAksen;
uAksen = m_u * cos(sudut) + m_n * sin(sudut);
vAksen = m_v;
nAksen = m_u * -sin(sudut) + m_n * cos(sudut);

m_u = uAksen;
m_v = vAksen;
m_n = nAksen;
}

void COpenGL3DView::Roll(double sudutDerajat)
{
double sudut = sudutDerajat / 180 * 3.14;
CBdVector uAksen, vAksen, nAksen;
uAksen = m_u * cos(sudut) - m_v * sin(sudut);
vAksen = m_u * sin(sudut) + m_v * cos(sudut);
nAksen = m_n;

m_u = uAksen;
m_v = vAksen;
m_n = nAksen;
}

void COpenGL3DView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default

for(int i = 0; i < count; i++)
{
snow[i].recalculate(uWind, DeltaT);
}

t += DeltaT;
// kurangi waktu jatuh berikutnya
timeNextFall -= 3.7;

if(timeNextFall <= 0)
{
// acak waktu jatuh berikutnya
timeNextFall = rand() % 100;
// buat salju berikutnya
snow[++count].initialize(Temperature, uWind, DeltaT);

}


Invalidate(false);
CView::OnTimer(nIDEvent);
}

void COpenGL3DView::OnInitialUpdate()
{
CView::OnInitialUpdate();

// TODO: Add your specialized code here and/or call the base class
GambarLingkaran();
srand((unsigned)time(NULL));
r=rand()%5;
// randomX1=rand()%100;
// randomX2=rand()%150;
// randomX[0] = rand() % 200;
// mass[0] = (double)(rand() % 1000) / 100.0;
//timeNextFall = rand() % 200;
SetTimer(1, 100, NULL);
}

void COpenGL3DView::GeserKamera(double x, double y, double z)
{
CBdVector geser(x, y, z);
m_eye = m_eye + geser;
UVN();
IsiMatrixKeModelView();
}

void COpenGL3DView::GambarSumbuXYZ()
{
// gambar sumbu X
glColor3ub(255, 0, 0);
glBegin(GL_LINES);
glVertex3i(-1000, 0, 0);
glVertex3i(1000, 0, 0);
glEnd();
// gambar sumbu Y
glColor3ub(0, 255, 0);
glBegin(GL_LINES);
glVertex3i(0, -1000, 0);
glVertex3i(0, 1000, 0);
glEnd();
// gambar sumbu Z
glColor3ub(0, 0, 255);
glBegin(GL_LINES);
glVertex3i(0, 0, -1000);
glVertex3i(0, 0, 1000);
glEnd();
}

void COpenGL3DView::GambarLingkaran()
{
GLUquadricObj* quadObj = gluNewQuadric();
gluQuadricDrawstyle(quadObj, GLU_LINE);
glColor3f(1.0, 0.0, 0.0);
glNewList(SNOW, GL_COMPILE);
gluSphere(quadObj, 2, 10, 10);
glEndList();
}




and here is the CSnow class:



// Snow.cpp: implementation of the CSnow class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "OpenGL3D.h"
#include "Snow.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double MAX_ACC = 50;
const double GRAVITY = 9.8;

CSnow::CSnow()
{
// first position
// X beetween 0 till 100
double x, z;
x = rand() % 51;
// Z between -100 till 100
z = rand() % 201 - 100;
pos.SetVector(x, 50, z);
t = 0;
w = (double)(rand() % 16 + 45) / 180.0 * PI;
R = (rand() % 2000) / 1000.0;
}

CSnow::~CSnow()
{

}

void CSnow::initialize(double temperature, CBdVector wind, double deltaT)
{
// r
if(temperature > -0.061)
diameter = 0.04;
else
diameter = 0.015 * pow(abs(temperature), -0.35);
// density
if(temperature > -1) // wet snow
{
rho = 0.724 / diameter;
// Umaxy antara 0.5 - 1.5
Umaxy = (rand() % 11 + 5) / 10.0;
}
else // dry snow
{
rho = 0.170 / diameter;
// Umaxy antara 1 - 2
Umaxy = (rand() % 11 + 10) / 10.0;
}
//TRACE("Umaxy: %lf", Umaxy);
// gravitatiolan force
fGravity.SetVector(0, -mass() * GRAVITY, 0);
// snow velocity
uSnowflake.SetX(rand() % 9 - 4);
uSnowflake.SetY(-Umaxy);
uSnowflake.SetZ(0);
recalculate(wind, deltaT);
}

// snow mass
double CSnow::mass()
{
// volume salju
double volume = 4.0 / 3.0 * PI * pow((diameter / 2.0), 3);
// massa
return (volume * rho);
}

// re-calculate
void CSnow::recalculate(CBdVector wind, double deltaT)
{
t += deltaT;
// angular speed
w += R * deltaT;
// Ufluid
uFluid = wind - uSnowflake;
// Cvel
if(abs(uSnowflake.Magnitude()) > 0)
Cvel = uFluid.Magnitude() / uSnowflake.Magnitude();
else
Cvel = 10;
// Ucirc
CBdVector temp(-sin(w * t), 0, cos(w * t));
uCirc = temp * (Cvel * w * R);
// F drag
fDrag.SetX(pow(uFluid.X(), 2) * mass() * GRAVITY / pow(Umaxy, 2));
fDrag.SetY(pow(uFluid.Y(), 2) * mass() * GRAVITY / pow(Umaxy, 2));
fDrag.SetZ(pow(uFluid.Z(), 2) * mass() * GRAVITY / pow(Umaxy, 2));
// acceleration
a = (fGravity + fDrag) / mass();
if(Cvel > 1)
pos = pos + (uSnowflake + uCirc) * deltaT + a * (0.5 * pow(t, 2));
else
pos = pos + (uSnowflake) * deltaT + a * (0.5 * pow(t, 2));
if(abs(a.X()) < MAX_ACC)
uSnowflake.SetX(a.X() * deltaT + uSnowflake.X());
else
uSnowflake.SetX(wind.X());
if(abs(a.Y()) < MAX_ACC)
uSnowflake.SetY(a.Y() * deltaT + uSnowflake.Y());
else
uSnowflake.SetY(wind.Y());
if(abs(a.Z()) < MAX_ACC)
uSnowflake.SetZ(a.Z() * deltaT + uSnowflake.Z());
else
uSnowflake.SetZ(wind.Z());
}

CBdVector CSnow::getPos()
{
return pos;
}




And maybe you'll need the CbdVector Class :


// BdVector.h: interface for the CBdVector class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_BdVector_H__778FE319_AD4A_4D4B_BFCE_1D317A10FD03__INCLUDED_)
#define AFX_BdVector_H__778FE319_AD4A_4D4B_BFCE_1D317A10FD03__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CBdVector
{
private :
double m_x, m_y, m_z;

public :


virtual ~CBdVector();

// constructor
CBdVector(void):m_x(0), m_y(0), m_z(0)
{}
CBdVector(const double &X, const double &Y, const double &Z):m_x(X), m_y(Y), m_z(Z)
{}

// Modifier
void SetX (const double &x) {m_x = x; }
void SetY(const double &y) {m_y = y; }
void SetZ(const double &z) {m_z = z; }
void SetVector(const CBdVector &temp) { *this = temp; }
void SetVector(const double &x, const double &y, const double &z) {m_x = x; m_y = y; m_z = z; }

// Selector
double X(void) const {return m_x; }
double Y(void) const {return m_y; }
double Z(void) const {return m_z; }
CBdVector GetVector(void) const { return *this; }


// Binary operator overloading (vector = vector1 opr vector2)
CBdVector operator+(const CBdVector &vector2) const;
CBdVector operator-(const CBdVector &vector2) const;
CBdVector operator*(const CBdVector &vector2) const; // Cross product

// Unary operator - (minus)
CBdVector operator-(void) const;

// Overloading operator = (equal)
void operator=(const double &scalar);

// Vector division to scalar
CBdVector operator/(const double &scalar) const;

// Vector multiplication to scalar and vice versa
CBdVector operator*(const double &scalar) const;
friend CBdVector operator*(const double &scalar, const CBdVector &vector);

// Others vector operation

// Normalize the vector
CBdVector Normalize(void) const;

// Get the distance of two vector
double Distance(const CBdVector &vector2) const;

// Get the magnitude of a vector
double Magnitude(void) const;

// Dot product of two vector
double DotProduct(const CBdVector &vector2) const;

};

#endif // !defined(AFX_BdVector_H__778FE319_AD4A_4D4B_BFCE_1D317A10FD03__INCLUDED_)





Here's the screen shot :



and i want is the snow just like the openning screen of the DOTA games :)

Thanks

[Edited by - louisx on September 17, 2007 7:09:10 PM]

Share this post


Link to post
Share on other sites
Maybe you didn't look at your post, but it's a mess. The "source" tags shouldn't have those spaces. If you don't see nice, formatted source, then it didn't work and you should edit your post to fix it.

Also, your image tags clearly aren't working. You should use plain old HTML img tags, not that BBCode stuff.

Share this post


Link to post
Share on other sites
@Smithy

the image is still not working... i've done what you say... but the images still unseen... i do this method in another forums.. and it's worked... :(

and about the "Source" and "/Source" tags... i've have not any idea of that... i just dont understand.. :(

Share this post


Link to post
Share on other sites
Quote:
Original post by louisx
the image is still not working... i've done what you say... but the images still unseen... i do this method in another forums.. and it's worked... :(
Use the HTML <img> tag, like this...
<img src="http://img485.imageshack.us/img485/6087/snowyv7.jpg">
or even the HTML <a> tag so someone can choose if they want to load it or not...
<a href="http://img485.imageshack.us/img485/6087/snowyv7.jpg">link text<a>
Quote:
Original post by louisx
and about the "Source" and "/Source" tags... i've have not any idea of that... i just dont understand.. :(
You have it right, except you have spaces in the tag. You have
[ source ]...code...[ /source ]
instead of
[source]...code...[/source]
The Forum FAQ has all this info in it already.

You should also only post the relevant pieces of your code. Even with the nice source formatting that's still a lot of code to go through if only a small bit of it has anything to do with the current problem.

Share this post


Link to post
Share on other sites
to PCN :

as i mentioned before... it's an implemented one... :)

i get that from Michael Asgard thesis... about ""Realistic Modelling of Falling and Accumulating Snow". M. Aagaard, and D. Lerche. Master thesis. Lab of Computer Vision and Media Technology, Aalborg University, Denmark, 2004."

You can get that here : [url]http://www.cvmt.dk/Snow/[/url]

Thanks.

Share this post


Link to post
Share on other sites
to PCN :

as i mentioned before... it's an implemented one... :)

i get that from Michael Asgard thesis... about "Realistic Modelling of Falling and Accumulating Snow". M. Aagaard, and D. Lerche. Master thesis. Lab of Computer Vision and Media Technology, Aalborg University, Denmark, 2004."

You can get that here : [url]http://www.cvmt.dk/Snow/[/url]

Thanks.

Share this post


Link to post
Share on other sites
Quote:
Original post by louisx
and i want is the snow just like the openning screen of the DOTA games :)

Thanks



this is the part i'm confused about. I think the methods you're looking at may be too complex if you just want the effect from the menu screen (is that what you mean by 'opening screen'? Just the snow in the BG while you're in the lobby?).

If I've understood you properly then whatever you're looking at is probibally overly complicated (AFAIK the effect doesn't use anything complicated, looks like particles given a random start point and a slightly curved path to follow).

However, if I'm wrong and you're trying to simulate 3d snowfall and accumulation then please tell me.

Share this post


Link to post
Share on other sites
Hi

Don't know if it might help but for the most simple particle simulation like this clicky there are only few things needed:

1. The particle speed is always constant and it doesn't accelerate. Otherwise they would look more like rain and unrealistically.

2. Each frame the particle should get small random direction for X,Y,Z coordinates. This would make it look more realistic . You need to pick the value carefully so it would work with the speed value properly.

Thats probably it.

Share this post


Link to post
Share on other sites
To Winegums :

Yes, i'm trying to simulate 3d snowfall... but not accumulated.. :)

To Dminator :

Whoa... that's a great snowfall :D i love it very much ^^
umm... can you take a look of my code and..tell me which part that should i change into?and how much the value?

Thanks all :)

Share this post


Link to post
Share on other sites
Quote:
Original post by louisx

Whoa... that's a great snowfall :D i love it very much ^^
umm... can you take a look of my code and..tell me which part that should i change into?and how much the value?

Thanks all :)


Well I would rewrite it all together and make it simple, but I don't have time for that. Sorry.

I can suggest though that you check Crystal Space 3D engine. This is what inspired me to make a snow effect :)

Share this post


Link to post
Share on other sites
// Ucirc
CBdVector temp(-sin(w * t), 0, cos(w * t));
uCirc = temp * (Cvel * w * R);


here's the sine and cosine part... which one that i should change PCN?

Share this post


Link to post
Share on other sites
// Ucirc
CBdVector temp(-sin(w * t), 0, cos(w * t));
uCirc = temp * (Cvel * w * R);


here's the sine and cosine part... which one that i should change PCN?

Share this post


Link to post
Share on other sites
Lemme see, here. I never said change anything, but merely gave you something to create a method off of. If I were creating a snow method, I might do something like this:


//Initialize section
const int GRAVITY = 9.8;

typedef struct
{
bool _life;
float X, Y, Z;
float startX, startZ;
float _radius;
}snow;

snow Snow[50]; //We have 50 snow particles we can handle, change at will

//Set up section...
for( int i_a=0; i_a<50; i_a++)
{
Snow[i_a]._life=false; //All we want now is to set that this isn't alive at the moment
}

/*We randomly drop snow at different times*/
void ReleaseSnow()
{
for( int i_c=0; i_c<50; i_c++)
{
int _randomTime=rand()%10;
if(_randomTime==0)//If the random number hits 0 [chosen,can be anything] then release snow
if(!Snow[i_c]._life) //If that specific piece of snow isn't alive...
{
Snow[i_c]._life=true;
Snow[i_c].startX=rand()%Room_Width;
Snow[i_c].Y=(Room_Height/4); //Start at the fourth of the room.,[hopefully top]
Snow[i_c].startZ=rand()%Room_Depth;

Snow[i_c].X=startX;
Snow[i_c].Z=startZ;

Snow[i_c]._radius=1; //A field of 1 to float around in
InitSnowDir();
}
}
}

//UpdateSnow()
void UpdateSnow()
{
/*Go through each one and update it*/
for(int i_b=0; i_b<50; i_b++)
{
if(Snow[i_b]._life) //If this particle is currently alive
{
/*If the 'snow' has gone outside of it's radius boundary, send it to the other direction*/
//X values
if(Snow[i_b].X > Snow[i_b].startX+Snow[i_b]._radius)
{
Snow[i_b].X-=0.01;
}
if(Snow[i_b].X < Snow[i_b].startX-Snow[i_b]._radius)
{
Snow[i_b].X+=0.01;
}
//Z Values
if(Snow[i_b].Z > Snow[i_b].startZ+Snow[i_b]._radius)
{
Snow[i_b].Z-=0.01;
}
if(Snow[i_b].Z < Snow[i_b].startZ-Snow[i_b]._radius)
{
Snow[i_b].Z+=0.01;
}
//Y Values, gravity
if(Snow[i_b].Y < Room_height) //If hasn't touched ground
{
Snow[i_b].Y+=GRAVITY;
}
else
{
Snow[i_b]._life=false;
}
}
}






This wasn't meant to copy then paste into your program and work, but you can do so and edit this program to your requirements. I hope you get the idea I'm trying to get at. ^^ I left out the methods to make it move and in what direction. I left that to you. The snow will only 'bounce' off the boundary, but I never wrote any way to make it move. I'm sure you can figure that part out. If you need help, tell me or PM me. Add me in credits, please.

Share this post


Link to post
Share on other sites

This topic is 3740 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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