Jump to content
  • Advertisement
Sign in to follow this  
louisx

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

This topic is 3927 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
Advertisement
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.getPos().Y() - 2 > 0)
{
glPushMatrix();
glTranslated(snow.getPos().X(), snow.getPos().Y(), snow.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.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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!