fix: some file didn't have the svn:eol-style native yet

This commit is contained in:
erwin.coumans
2010-03-06 15:23:36 +00:00
parent 4fd48ac691
commit 81f04a4d48
641 changed files with 301123 additions and 301123 deletions

View File

@@ -1,35 +1,35 @@
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2008. Rama Hoetzlein, http://www.rchoetzlein.com
A fast CPU and GPU fluid simulator. See website above for details.
Notes
(April 2009)
-------------------
- Press 'h' for help screen. This shows keyboard cmds available.
- By default, GPU simulation is off.
When running the fluid_gpu.exe, press 'g' to start/stop GPU simulation.
- Disabling shadows in common_defs.h will greatly speed up the simulation
(You can also press 's' to render without shadows)
- As of April 2009, CUDA builds only under Visual Studio 2005, not VS 2008.
To enable the CUDA build in VS2005, set the BUILD_CUDA define in common_defs.h
Be sure this is turned off if you build with VS2008.
- The GPU integrator is not yet complete. Integration always takes place on the CPU, in both CPU and GPU modes. (As a result, this forces a bus transfer to and from the GPU per cycle. Once the integrator is finished, GPU simulation performance should increase significantly.)
- Occassionally, the GPU simulation with crash cuda, causing the screen to blink and particles to move randomly. This is believed to be due to a not-yet-found out of bounds condition.
ZLib License
-------------------
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2008. Rama Hoetzlein, http://www.rchoetzlein.com
A fast CPU and GPU fluid simulator. See website above for details.
Notes
(April 2009)
-------------------
- Press 'h' for help screen. This shows keyboard cmds available.
- By default, GPU simulation is off.
When running the fluid_gpu.exe, press 'g' to start/stop GPU simulation.
- Disabling shadows in common_defs.h will greatly speed up the simulation
(You can also press 's' to render without shadows)
- As of April 2009, CUDA builds only under Visual Studio 2005, not VS 2008.
To enable the CUDA build in VS2005, set the BUILD_CUDA define in common_defs.h
Be sure this is turned off if you build with VS2008.
- The GPU integrator is not yet complete. Integration always takes place on the CPU, in both CPU and GPU modes. (As a result, this forces a bus transfer to and from the GPU per cycle. Once the integrator is finished, GPU simulation performance should increase significantly.)
- Occassionally, the GPU simulation with crash cuda, causing the screen to blink and particles to move randomly. This is believed to be due to a not-yet-found out of bounds condition.
ZLib License
-------------------
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,52 +1,52 @@
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef COMMON_DEF
#define COMMON_DEF
// Global defs
//#define USE_SHADOWS // Disable if you don't have FBOs, or to greatly speed up demo.
// #define USE_JPEG
#define BUILD_CUDA // CUDA - Visual Studio 2005 only (as of April 2009)
#define TEX_SIZE 2048
#define LIGHT_NEAR 0.5
#define LIGHT_FAR 300.0
#define DEGtoRAD (3.141592/180.0)
#ifdef _MSC_VER
#include <windows.h>
#else
typedef unsigned int DWORD;
#endif
typedef unsigned int uint;
#define COLOR(r,g,b) ( (DWORD(r*255.0f)<<24) | (DWORD(g*255.0f)<<16) | (DWORD(b*255.0f)<<8) )
#define COLORA(r,g,b,a) ( (DWORD(r*255.0f)<<24) | (DWORD(g*255.0f)<<16) | (DWORD(b*255.0f)<<8) | DWORD(a*255.0f) )
#define RED(c) (float((c>>24) & 0xFF)/255.0)
#define GRN(c) (float((c>>16) & 0xFF)/255.0)
#define BLUE(c) (float((c>>8) & 0xFF)/255.0)
#define ALPH(c) (float(c & 0xFF)/255.0)
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef COMMON_DEF
#define COMMON_DEF
// Global defs
//#define USE_SHADOWS // Disable if you don't have FBOs, or to greatly speed up demo.
// #define USE_JPEG
#define BUILD_CUDA // CUDA - Visual Studio 2005 only (as of April 2009)
#define TEX_SIZE 2048
#define LIGHT_NEAR 0.5
#define LIGHT_FAR 300.0
#define DEGtoRAD (3.141592/180.0)
#ifdef _MSC_VER
#include <windows.h>
#else
typedef unsigned int DWORD;
#endif
typedef unsigned int uint;
#define COLOR(r,g,b) ( (DWORD(r*255.0f)<<24) | (DWORD(g*255.0f)<<16) | (DWORD(b*255.0f)<<8) )
#define COLORA(r,g,b,a) ( (DWORD(r*255.0f)<<24) | (DWORD(g*255.0f)<<16) | (DWORD(b*255.0f)<<8) | DWORD(a*255.0f) )
#define RED(c) (float((c>>24) & 0xFF)/255.0)
#define GRN(c) (float((c>>16) & 0xFF)/255.0)
#define BLUE(c) (float((c>>8) & 0xFF)/255.0)
#define ALPH(c) (float(c & 0xFF)/255.0)
#endif

View File

@@ -1,443 +1,443 @@
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2008. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include <vector.h>
#include "geomx.h"
#include "mdebug.h"
#include <assert.h>
GeomX::GeomX ()
{
mHeap = 0x0;
}
void GeomX::FreeBuffers ()
{
for (int n=0; n < (int) mBuf.size(); n++) {
free ( mBuf[n].data );
mBuf[n].data = 0x0;
}
mBuf.clear ();
if ( mHeap != 0x0 ) free ( mHeap );
mHeap = 0x0;
mHeapNum = 0;
mHeapMax = 0;
}
void GeomX::ResetHeap ()
{
mHeapNum = 0;
mHeapFree = -1;
}
int GeomX::GetSize ()
{
int sum = mHeapNum * sizeof(hval) ;
for (int n=0; n < (int) mBuf.size(); n++)
sum += mBuf[n].size;
sum += (int) mAttribute.size() * sizeof(GeomAttr);
return sum;
}
void GeomX::ClearAttributes ()
{
mAttribute.clear ();
}
int GeomX::CopyBuffer ( uchar bdest, uchar bsrc, GeomX& src )
{
if ( bsrc >= src.GetNumBuf() ) return -1;
if ( bdest >= GetNumBuf() ) {
for (int n=0; n <= bdest - GetNumBuf(); n++ )
AddBuffer ( 0, 0, 0 );
}
if ( mBuf[bdest].data != 0x0 ) {
free ( mBuf[bdest].data );
mBuf[bdest].data = 0x0;
}
GeomBuf* buf = src.GetBuffer( bsrc );
mBuf[bdest].dtype = buf->dtype;
mBuf[bdest].max = buf->max;
mBuf[bdest].num = buf->num;
mBuf[bdest].stride = buf->stride;
mBuf[bdest].size = buf->size;
mBuf[bdest].data = (char*) malloc ( mBuf[bdest].max * mBuf[bdest].stride );
memcpy ( mBuf[bdest].data, buf->data, mBuf[bdest].num * mBuf[bdest].stride );
return bdest;
}
void GeomX::CopyBuffers ( GeomX& src )
{
FreeBuffers ();
for (int n = 0; n < src.GetNumBuf(); n++)
CopyBuffer ( n, n, src );
CopyHeap ( src );
}
void GeomX::CopyHeap ( GeomX& src )
{
hpos num, max, freepos;
hval* src_data = src.GetHeap ( num, max, freepos );
if ( mHeap != 0x0 ) {
free ( mHeap );
mHeap = 0x0;
}
mHeap = (hval*) malloc ( max * sizeof(hval) );
mHeapMax = max;
mHeapNum = num;
mHeapFree = freepos;
memcpy ( mHeap, src_data, mHeapNum * sizeof(hval) );
}
hval* GeomX::GetHeap ( hpos& num, hpos& max, hpos& free )
{
num = mHeapNum;
max = mHeapMax;
free = mHeapFree;
return mHeap;
}
void GeomX::CopyAttributes ( GeomX& src )
{
GeomAttr* attr;
ClearAttributes ();
int a;
for (int n = 0; n < src.GetNumAttr(); n++) {
attr = src.GetAttribute ( n );
a = AddAttribute ( (uchar) attr->buf, attr->name, attr->stride, false );
mAttribute[a].offset = attr->offset;
}
}
void GeomX::AddHeap ( int max )
{
mHeap = (hval*) malloc ( max * sizeof(hval ) );
mHeapMax = max;
mHeapNum = 0;
mHeapFree = -1;
}
int GeomX::AddAttribute ( uchar b, std::string name, ushort stride )
{
return AddAttribute ( b, name, stride, true );
}
int GeomX::AddAttribute ( uchar b, std::string name, ushort stride, bool bExtend )
{
GeomBuf* buf = &mBuf[b];
GeomAttr attr;
attr.buf = b;
attr.name = name;
attr.offset = buf->stride;
attr.stride = stride;
if ( bExtend ) {
int new_stride = buf->stride + attr.stride;
char* new_data = (char*) malloc ( buf->max * new_stride );
char* old_data = buf->data;
for (int n=0; n < buf->num; n++) {
memcpy ( new_data, old_data, buf->stride );
old_data += buf->stride;
new_data += new_stride;
}
free ( buf->data );
buf->data = new_data;
buf->stride = new_stride;
}
mAttribute.push_back ( attr );
return (int) mAttribute.size()-1;
}
int GeomX::GetAttribute ( std::string name )
{
for (int n=0; n < (int) mAttribute.size(); n++) {
if ( mAttribute[n].name.compare ( name ) == 0 )
return n;
}
return -1;
}
int GeomX::GetAttrOffset ( std::string name )
{
for (int n=0; n < (int) mAttribute.size(); n++) {
if ( mAttribute[n].name.compare ( name ) == 0 )
return mAttribute[n].offset;
}
return -1;
}
int GeomX::AddBuffer ( uchar typ, ushort stride, int max )
{
GeomBuf buf;
buf.dtype = typ;
buf.stride = stride;
buf.max = max;
buf.num = 0;
buf.size = 0;
buf.data = (char*) malloc ( buf.max * buf.stride );
mBuf.push_back ( buf );
return (int) mBuf.size()-1;
}
void GeomX::ResetBuffer ( uchar b, int n )
{
mBuf[b].max = n;
if ( mBuf[b].data != 0x0 ) free ( mBuf[b].data );
char* new_data = (char*) malloc ( mBuf[b].max * mBuf[b].stride );
mBuf[b].data = new_data;
mBuf[b].num = 0;
mBuf[b].size = mBuf[b].num*mBuf[b].stride;
}
char* GeomX::AddElem ( uchar b, href& ndx )
{
if ( mBuf[b].num >= mBuf[b].max ) {
if ( long(mBuf[b].max) * 2 > ELEM_MAX ) {
error.PrintF ( "geom", "Maximum number of elements reached.\n" );
error.Exit ();
}
mBuf[b].max *= 2;
char* new_data = (char*) malloc ( mBuf[b].max * mBuf[b].stride );
memcpy ( new_data, mBuf[b].data, mBuf[b].num*mBuf[b].stride );
free ( mBuf[b].data );
mBuf[b].data = new_data;
}
mBuf[b].num++;
mBuf[b].size += mBuf[b].stride;
ndx = mBuf[b].num-1;
return mBuf[b].data + ndx*mBuf[b].stride;
}
char* GeomX::RandomElem ( uchar b, href& ndx )
{
ndx = mBuf[b].num * rand() / RAND_MAX;
return mBuf[b].data + ndx*mBuf[b].stride;
}
int GeomX::AddElem ( uchar b, char* data )
{
if ( mBuf[b].num >= mBuf[b].max ) {
mBuf[b].max *= 2;
char* new_data = (char*) malloc ( mBuf[b].max * mBuf[b].stride );
memcpy ( new_data, mBuf[b].data, mBuf[b].num*mBuf[b].stride );
free ( mBuf[b].data );
mBuf[b].data = new_data;
}
memcpy ( mBuf[b].data + mBuf[b].num*mBuf[b].stride, data, mBuf[b].stride );
mBuf[b].num++;
mBuf[b].size += mBuf[b].stride;
return mBuf[b].num-1;
}
bool GeomX::DelElem ( uchar b, int n )
{
if ( n >= 0 && n < mBuf[b].num ) {
memcpy ( mBuf[b].data + n*mBuf[b].stride, mBuf[b].data + (mBuf[b].num-1)*mBuf[b].stride, mBuf[b].stride );
mBuf[b].num--;
mBuf[b].size -= mBuf[b].stride;
return true;
}
return false;
}
hpos GeomX::HeapExpand ( ushort size, ushort& ret )
{
mHeapMax *= 2;
if ( mHeapMax > HEAP_MAX ) {
error.PrintF ( "geom", "Geom heap size exceeds range of index.\n" );
error.Exit ();
}
hval* pNewHeap = (hval*) malloc ( mHeapMax * sizeof(hval) );
if ( pNewHeap == 0x0 ) {
error.PrintF ( "geom", "Geom heap out of memory.\n" );
error.Exit ();
}
memcpy ( pNewHeap, mHeap, mHeapNum*sizeof(hval) );
free ( mHeap );
mHeap = pNewHeap;
ret = size;
assert ( mHeapNum >= 0 && mHeapNum < mHeapMax );
return mHeapNum;
}
#define LIST_INIT 4
hpos GeomX::HeapAlloc ( ushort size, ushort& ret )
{
hval* pPrev = 0x0;
hval* pCurr = mHeap + mHeapFree;
hpos pos = -1;
if ( mHeapNum + size < mHeapMax ) {
// Heap not yet full.
pos = mHeapNum;
ret = size;
mHeapNum += size;
} else {
// Heap full, search free space
if ( mHeapFree == -1 ) {
pos = HeapExpand ( size, ret );
mHeapNum += ret;
} else {
while ( *pCurr < size && pCurr != mHeap-1 ) {
pPrev = pCurr;
pCurr = mHeap + * (hpos*) (pCurr + FPOS);
}
if ( pCurr != mHeap-1 ) {
// Found free space.
if ( pPrev == 0x0 ) {
mHeapFree = * (hpos*) (pCurr + FPOS);
assert ( mHeapFree >= -1 );
} else {
* (hpos*) (pPrev+FPOS) = * (hpos*) (pCurr+FPOS);
}
pos = pCurr-mHeap;
ret = *pCurr;
} else {
// Heap full, no free space. Expand heap.
pos = HeapExpand ( size, ret );
mHeapNum += ret;
}
}
}
assert ( pos >= 0 && pos <= mHeapNum );
memset ( mHeap+pos, 0, size*sizeof(hval) );
return pos;
}
void GeomX::HeapAddFree ( hpos pos, int size )
{
// memset ( mHeap+pos, 0xFF, size*sizeof(hval) );
if ( pos < mHeapFree || mHeapFree == -1 ) {
// Lowest position. Insert at head of heap.
* (hpos*) (mHeap+pos) = size;
* (hpos*) (mHeap+pos + FPOS) = mHeapFree;
mHeapFree = pos;
if ( mHeapFree != -1 && *(hpos*) (mHeap+mHeapFree+FPOS) == 0x0 ) { error.PrintF ( "geomx", "ERROR: Heap pointer 0. pHeapFree, %d\n", pos ); error.Exit (); }
assert ( mHeapFree >= -1 );
} else {
hval* pCurr = mHeap + pos;
hval* pPrev = 0x0;
hval* pNext = mHeap + mHeapFree;
if ( pCurr == pNext ) { // Freeing the first block
mHeapFree = * (hpos*) (pCurr + FPOS);
* (hpos*) (mHeap+mHeapFree + FPOS) = 0xFFFFFFFF;
* (hpos*) (pCurr + FPOS) = 0xFFFFFFFF;
* (hpos*) pCurr = 0xFFFFFFFF;
return;
}
// Find first block greater than new free pos.
while ( pNext < pCurr && pNext != mHeap-1 ) {
pPrev = pNext;
pNext = mHeap + * (hpos*) (pNext + FPOS);
}
int x = 0;
if ( pPrev + *(pPrev) == pCurr ) { // Prev block touches current one (expand previous)
* (hpos*) pPrev += size; // - prev.size = prev.size + curr.size
x=1;
} else if ( pCurr + size == pNext && pNext != mHeap-1 ) { // Curr block touches next one (expand current block)
* (hpos*) (pPrev + FPOS) = pos; // - prev.next = curr
* (hpos*) (pCurr + FPOS) = * (hpos*) (pNext + FPOS); // - curr.next = next.next
* (hpos*) pCurr = size + * (hpos*) pNext; // - curr.size = size + next.size
* (hpos*) (pNext) = 0xFFFFFFFF; // - curr = null
* (hpos*) (pNext + FPOS) = 0xFFFFFFFF; // - curr.next = null
x=2;
} else { // Otherwise (linked list insert)
* (hpos*) (pPrev + FPOS) = pos; // - prev.next = curr
if ( pNext != mHeap-1 )
* (hpos*) (pCurr + FPOS) = pNext - mHeap; // - curr.next = next
else
* (hpos*) (pCurr + FPOS) = 0xFFFFFFFF; // - curr.next = null (no next node)
* (hpos*) pCurr = size; // - curr.size = size
x=3;
}
if ( pCurr !=mHeap-1 && *(hpos*) (pCurr+FPOS) == 0x0 ) { error.PrintF ( "geomx", "ERROR: Heap pointer 0. pCurr, %d, %d\n", x, pos ); error.Exit (); }
if ( pPrev !=mHeap-1 && *(hpos*) (pPrev+FPOS) == 0x0 ) { error.PrintF ( "geomx", "ERROR: Heap pointer 0. pPrev, %d, %d\n", x, pos ); error.Exit (); }
if ( pNext !=mHeap-1 && *(hpos*) (pNext+FPOS) == 0x0 ) { error.PrintF ( "geomx", "ERROR: Heap pointer 0. pNext, %d, %d\n", x, pos ); error.Exit (); }
if ( *(hpos*) (mHeap+mHeapFree+FPOS) == 0x0 ) { error.PrintF ( "geomx", "ERROR: Heap pointer 0. pHeapFree, %d, %d\n", x, pos ); error.Exit (); }
// -- check for bugs (remove eventually)
pNext = mHeap + mHeapFree;
while ( pNext != mHeap-1 ) {
pPrev = pNext;
pNext = mHeap + * (hpos*) (pNext + FPOS);
if ( pNext < pPrev && pNext != mHeap-1 ) {
error.PrintF ( "geomx", "ERROR: Heap free space out of order. %d, %d\n", x, pos );
error.Exit ();
}
}
//---
}
}
void GeomX::ClearRefs ( hList& list )
{
list.cnt = 0;
list.max = 0;
list.pos = 0;
}
hval GeomX::AddRef ( hval r, hList& list, hval delta )
{
if ( list.max == 0 ) {
list.cnt = 1;
list.pos = HeapAlloc ( LIST_INIT, list.max );
*(mHeap + list.pos) = r+delta;
} else {
if ( list.cnt >= list.max ) {
int siz = list.max;
hpos new_pos = HeapAlloc ( siz+LIST_INIT, list.max ); // Alloc new location
//printf ( "MOVE %d -> %d\n", list.pos, new_pos );
memcpy ( mHeap+new_pos, mHeap+list.pos, list.cnt*sizeof(hval) ); // Copy data to new location
HeapAddFree ( list.pos, siz ); // Free old location
list.pos = new_pos;
}
*(mHeap + list.pos + list.cnt) = r+delta;
list.cnt++;
}
return list.pos;
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2008. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include <vector.h>
#include "geomx.h"
#include "mdebug.h"
#include <assert.h>
GeomX::GeomX ()
{
mHeap = 0x0;
}
void GeomX::FreeBuffers ()
{
for (int n=0; n < (int) mBuf.size(); n++) {
free ( mBuf[n].data );
mBuf[n].data = 0x0;
}
mBuf.clear ();
if ( mHeap != 0x0 ) free ( mHeap );
mHeap = 0x0;
mHeapNum = 0;
mHeapMax = 0;
}
void GeomX::ResetHeap ()
{
mHeapNum = 0;
mHeapFree = -1;
}
int GeomX::GetSize ()
{
int sum = mHeapNum * sizeof(hval) ;
for (int n=0; n < (int) mBuf.size(); n++)
sum += mBuf[n].size;
sum += (int) mAttribute.size() * sizeof(GeomAttr);
return sum;
}
void GeomX::ClearAttributes ()
{
mAttribute.clear ();
}
int GeomX::CopyBuffer ( uchar bdest, uchar bsrc, GeomX& src )
{
if ( bsrc >= src.GetNumBuf() ) return -1;
if ( bdest >= GetNumBuf() ) {
for (int n=0; n <= bdest - GetNumBuf(); n++ )
AddBuffer ( 0, 0, 0 );
}
if ( mBuf[bdest].data != 0x0 ) {
free ( mBuf[bdest].data );
mBuf[bdest].data = 0x0;
}
GeomBuf* buf = src.GetBuffer( bsrc );
mBuf[bdest].dtype = buf->dtype;
mBuf[bdest].max = buf->max;
mBuf[bdest].num = buf->num;
mBuf[bdest].stride = buf->stride;
mBuf[bdest].size = buf->size;
mBuf[bdest].data = (char*) malloc ( mBuf[bdest].max * mBuf[bdest].stride );
memcpy ( mBuf[bdest].data, buf->data, mBuf[bdest].num * mBuf[bdest].stride );
return bdest;
}
void GeomX::CopyBuffers ( GeomX& src )
{
FreeBuffers ();
for (int n = 0; n < src.GetNumBuf(); n++)
CopyBuffer ( n, n, src );
CopyHeap ( src );
}
void GeomX::CopyHeap ( GeomX& src )
{
hpos num, max, freepos;
hval* src_data = src.GetHeap ( num, max, freepos );
if ( mHeap != 0x0 ) {
free ( mHeap );
mHeap = 0x0;
}
mHeap = (hval*) malloc ( max * sizeof(hval) );
mHeapMax = max;
mHeapNum = num;
mHeapFree = freepos;
memcpy ( mHeap, src_data, mHeapNum * sizeof(hval) );
}
hval* GeomX::GetHeap ( hpos& num, hpos& max, hpos& free )
{
num = mHeapNum;
max = mHeapMax;
free = mHeapFree;
return mHeap;
}
void GeomX::CopyAttributes ( GeomX& src )
{
GeomAttr* attr;
ClearAttributes ();
int a;
for (int n = 0; n < src.GetNumAttr(); n++) {
attr = src.GetAttribute ( n );
a = AddAttribute ( (uchar) attr->buf, attr->name, attr->stride, false );
mAttribute[a].offset = attr->offset;
}
}
void GeomX::AddHeap ( int max )
{
mHeap = (hval*) malloc ( max * sizeof(hval ) );
mHeapMax = max;
mHeapNum = 0;
mHeapFree = -1;
}
int GeomX::AddAttribute ( uchar b, std::string name, ushort stride )
{
return AddAttribute ( b, name, stride, true );
}
int GeomX::AddAttribute ( uchar b, std::string name, ushort stride, bool bExtend )
{
GeomBuf* buf = &mBuf[b];
GeomAttr attr;
attr.buf = b;
attr.name = name;
attr.offset = buf->stride;
attr.stride = stride;
if ( bExtend ) {
int new_stride = buf->stride + attr.stride;
char* new_data = (char*) malloc ( buf->max * new_stride );
char* old_data = buf->data;
for (int n=0; n < buf->num; n++) {
memcpy ( new_data, old_data, buf->stride );
old_data += buf->stride;
new_data += new_stride;
}
free ( buf->data );
buf->data = new_data;
buf->stride = new_stride;
}
mAttribute.push_back ( attr );
return (int) mAttribute.size()-1;
}
int GeomX::GetAttribute ( std::string name )
{
for (int n=0; n < (int) mAttribute.size(); n++) {
if ( mAttribute[n].name.compare ( name ) == 0 )
return n;
}
return -1;
}
int GeomX::GetAttrOffset ( std::string name )
{
for (int n=0; n < (int) mAttribute.size(); n++) {
if ( mAttribute[n].name.compare ( name ) == 0 )
return mAttribute[n].offset;
}
return -1;
}
int GeomX::AddBuffer ( uchar typ, ushort stride, int max )
{
GeomBuf buf;
buf.dtype = typ;
buf.stride = stride;
buf.max = max;
buf.num = 0;
buf.size = 0;
buf.data = (char*) malloc ( buf.max * buf.stride );
mBuf.push_back ( buf );
return (int) mBuf.size()-1;
}
void GeomX::ResetBuffer ( uchar b, int n )
{
mBuf[b].max = n;
if ( mBuf[b].data != 0x0 ) free ( mBuf[b].data );
char* new_data = (char*) malloc ( mBuf[b].max * mBuf[b].stride );
mBuf[b].data = new_data;
mBuf[b].num = 0;
mBuf[b].size = mBuf[b].num*mBuf[b].stride;
}
char* GeomX::AddElem ( uchar b, href& ndx )
{
if ( mBuf[b].num >= mBuf[b].max ) {
if ( long(mBuf[b].max) * 2 > ELEM_MAX ) {
error.PrintF ( "geom", "Maximum number of elements reached.\n" );
error.Exit ();
}
mBuf[b].max *= 2;
char* new_data = (char*) malloc ( mBuf[b].max * mBuf[b].stride );
memcpy ( new_data, mBuf[b].data, mBuf[b].num*mBuf[b].stride );
free ( mBuf[b].data );
mBuf[b].data = new_data;
}
mBuf[b].num++;
mBuf[b].size += mBuf[b].stride;
ndx = mBuf[b].num-1;
return mBuf[b].data + ndx*mBuf[b].stride;
}
char* GeomX::RandomElem ( uchar b, href& ndx )
{
ndx = mBuf[b].num * rand() / RAND_MAX;
return mBuf[b].data + ndx*mBuf[b].stride;
}
int GeomX::AddElem ( uchar b, char* data )
{
if ( mBuf[b].num >= mBuf[b].max ) {
mBuf[b].max *= 2;
char* new_data = (char*) malloc ( mBuf[b].max * mBuf[b].stride );
memcpy ( new_data, mBuf[b].data, mBuf[b].num*mBuf[b].stride );
free ( mBuf[b].data );
mBuf[b].data = new_data;
}
memcpy ( mBuf[b].data + mBuf[b].num*mBuf[b].stride, data, mBuf[b].stride );
mBuf[b].num++;
mBuf[b].size += mBuf[b].stride;
return mBuf[b].num-1;
}
bool GeomX::DelElem ( uchar b, int n )
{
if ( n >= 0 && n < mBuf[b].num ) {
memcpy ( mBuf[b].data + n*mBuf[b].stride, mBuf[b].data + (mBuf[b].num-1)*mBuf[b].stride, mBuf[b].stride );
mBuf[b].num--;
mBuf[b].size -= mBuf[b].stride;
return true;
}
return false;
}
hpos GeomX::HeapExpand ( ushort size, ushort& ret )
{
mHeapMax *= 2;
if ( mHeapMax > HEAP_MAX ) {
error.PrintF ( "geom", "Geom heap size exceeds range of index.\n" );
error.Exit ();
}
hval* pNewHeap = (hval*) malloc ( mHeapMax * sizeof(hval) );
if ( pNewHeap == 0x0 ) {
error.PrintF ( "geom", "Geom heap out of memory.\n" );
error.Exit ();
}
memcpy ( pNewHeap, mHeap, mHeapNum*sizeof(hval) );
free ( mHeap );
mHeap = pNewHeap;
ret = size;
assert ( mHeapNum >= 0 && mHeapNum < mHeapMax );
return mHeapNum;
}
#define LIST_INIT 4
hpos GeomX::HeapAlloc ( ushort size, ushort& ret )
{
hval* pPrev = 0x0;
hval* pCurr = mHeap + mHeapFree;
hpos pos = -1;
if ( mHeapNum + size < mHeapMax ) {
// Heap not yet full.
pos = mHeapNum;
ret = size;
mHeapNum += size;
} else {
// Heap full, search free space
if ( mHeapFree == -1 ) {
pos = HeapExpand ( size, ret );
mHeapNum += ret;
} else {
while ( *pCurr < size && pCurr != mHeap-1 ) {
pPrev = pCurr;
pCurr = mHeap + * (hpos*) (pCurr + FPOS);
}
if ( pCurr != mHeap-1 ) {
// Found free space.
if ( pPrev == 0x0 ) {
mHeapFree = * (hpos*) (pCurr + FPOS);
assert ( mHeapFree >= -1 );
} else {
* (hpos*) (pPrev+FPOS) = * (hpos*) (pCurr+FPOS);
}
pos = pCurr-mHeap;
ret = *pCurr;
} else {
// Heap full, no free space. Expand heap.
pos = HeapExpand ( size, ret );
mHeapNum += ret;
}
}
}
assert ( pos >= 0 && pos <= mHeapNum );
memset ( mHeap+pos, 0, size*sizeof(hval) );
return pos;
}
void GeomX::HeapAddFree ( hpos pos, int size )
{
// memset ( mHeap+pos, 0xFF, size*sizeof(hval) );
if ( pos < mHeapFree || mHeapFree == -1 ) {
// Lowest position. Insert at head of heap.
* (hpos*) (mHeap+pos) = size;
* (hpos*) (mHeap+pos + FPOS) = mHeapFree;
mHeapFree = pos;
if ( mHeapFree != -1 && *(hpos*) (mHeap+mHeapFree+FPOS) == 0x0 ) { error.PrintF ( "geomx", "ERROR: Heap pointer 0. pHeapFree, %d\n", pos ); error.Exit (); }
assert ( mHeapFree >= -1 );
} else {
hval* pCurr = mHeap + pos;
hval* pPrev = 0x0;
hval* pNext = mHeap + mHeapFree;
if ( pCurr == pNext ) { // Freeing the first block
mHeapFree = * (hpos*) (pCurr + FPOS);
* (hpos*) (mHeap+mHeapFree + FPOS) = 0xFFFFFFFF;
* (hpos*) (pCurr + FPOS) = 0xFFFFFFFF;
* (hpos*) pCurr = 0xFFFFFFFF;
return;
}
// Find first block greater than new free pos.
while ( pNext < pCurr && pNext != mHeap-1 ) {
pPrev = pNext;
pNext = mHeap + * (hpos*) (pNext + FPOS);
}
int x = 0;
if ( pPrev + *(pPrev) == pCurr ) { // Prev block touches current one (expand previous)
* (hpos*) pPrev += size; // - prev.size = prev.size + curr.size
x=1;
} else if ( pCurr + size == pNext && pNext != mHeap-1 ) { // Curr block touches next one (expand current block)
* (hpos*) (pPrev + FPOS) = pos; // - prev.next = curr
* (hpos*) (pCurr + FPOS) = * (hpos*) (pNext + FPOS); // - curr.next = next.next
* (hpos*) pCurr = size + * (hpos*) pNext; // - curr.size = size + next.size
* (hpos*) (pNext) = 0xFFFFFFFF; // - curr = null
* (hpos*) (pNext + FPOS) = 0xFFFFFFFF; // - curr.next = null
x=2;
} else { // Otherwise (linked list insert)
* (hpos*) (pPrev + FPOS) = pos; // - prev.next = curr
if ( pNext != mHeap-1 )
* (hpos*) (pCurr + FPOS) = pNext - mHeap; // - curr.next = next
else
* (hpos*) (pCurr + FPOS) = 0xFFFFFFFF; // - curr.next = null (no next node)
* (hpos*) pCurr = size; // - curr.size = size
x=3;
}
if ( pCurr !=mHeap-1 && *(hpos*) (pCurr+FPOS) == 0x0 ) { error.PrintF ( "geomx", "ERROR: Heap pointer 0. pCurr, %d, %d\n", x, pos ); error.Exit (); }
if ( pPrev !=mHeap-1 && *(hpos*) (pPrev+FPOS) == 0x0 ) { error.PrintF ( "geomx", "ERROR: Heap pointer 0. pPrev, %d, %d\n", x, pos ); error.Exit (); }
if ( pNext !=mHeap-1 && *(hpos*) (pNext+FPOS) == 0x0 ) { error.PrintF ( "geomx", "ERROR: Heap pointer 0. pNext, %d, %d\n", x, pos ); error.Exit (); }
if ( *(hpos*) (mHeap+mHeapFree+FPOS) == 0x0 ) { error.PrintF ( "geomx", "ERROR: Heap pointer 0. pHeapFree, %d, %d\n", x, pos ); error.Exit (); }
// -- check for bugs (remove eventually)
pNext = mHeap + mHeapFree;
while ( pNext != mHeap-1 ) {
pPrev = pNext;
pNext = mHeap + * (hpos*) (pNext + FPOS);
if ( pNext < pPrev && pNext != mHeap-1 ) {
error.PrintF ( "geomx", "ERROR: Heap free space out of order. %d, %d\n", x, pos );
error.Exit ();
}
}
//---
}
}
void GeomX::ClearRefs ( hList& list )
{
list.cnt = 0;
list.max = 0;
list.pos = 0;
}
hval GeomX::AddRef ( hval r, hList& list, hval delta )
{
if ( list.max == 0 ) {
list.cnt = 1;
list.pos = HeapAlloc ( LIST_INIT, list.max );
*(mHeap + list.pos) = r+delta;
} else {
if ( list.cnt >= list.max ) {
int siz = list.max;
hpos new_pos = HeapAlloc ( siz+LIST_INIT, list.max ); // Alloc new location
//printf ( "MOVE %d -> %d\n", list.pos, new_pos );
memcpy ( mHeap+new_pos, mHeap+list.pos, list.cnt*sizeof(hval) ); // Copy data to new location
HeapAddFree ( list.pos, siz ); // Free old location
list.pos = new_pos;
}
*(mHeap + list.pos + list.cnt) = r+delta;
list.cnt++;
}
return list.pos;
}

View File

@@ -1,125 +1,125 @@
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2008. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef DEF_GEOM
#define DEF_GEOM
#include <vector>
#define HEAP_MAX 2147483640 // largest heap size (range of hpos)
#define ELEM_MAX 2147483640 // largest number of elements in a buffer (range of hval)
//#define ELEM_MAX 32768 // largest number of elements in a buffer (range of hval)
#define BUF_UNDEF 255
#define FPOS 2 // free position offsets
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef signed int hpos; // pointers into heap
typedef signed int hval; // values in heap
typedef hval href; // values are typically references
struct hList {
ushort cnt;
ushort max;
hpos pos;
};
class GeomAttr {
public:
GeomAttr() { name = ""; buf = 0; stride = 0; offset = 0; }
std::string name;
ushort buf;
ushort stride;
ushort offset;
};
class GeomBuf {
public:
GeomBuf() { dtype = 0; num = 0; max = 0; stride = 0; data = 0x0; }
uchar dtype;
hval num;
hval max;
long size;
ushort stride;
char* data;
};
class GeomX {
public:
GeomX ();
// virtual objType GetType () { return 'geom'; }
// Basic geometry setup
void FreeBuffers ();
void ClearAttributes ();
void AddHeap ( int max );
int CopyBuffer ( uchar bdest, uchar bsrc, GeomX& src );
void CopyBuffers ( GeomX& src );
void CopyAttributes ( GeomX& src );
void CopyHeap ( GeomX& src );
void ResetBuffer ( uchar b, int n );
void ResetHeap ();
int AddBuffer ( uchar typ, ushort stride, int max );
int AddAttribute ( uchar b, std::string name, ushort stride );
int AddAttribute ( uchar b, std::string name, ushort stride, bool bExtend );
int GetAttribute ( std::string name );
int GetAttrOffset ( std::string name );
int NumElem ( uchar b ) { if ( b==BUF_UNDEF) return 0; else return mBuf[b].num; }
int MaxElem ( uchar b ) { if ( b==BUF_UNDEF) return 0; else return mBuf[b].max; }
int GetStride ( uchar b ) { return mBuf[b].stride; }
char* GetElem ( uchar b, int n ) { return mBuf[b].data + n*mBuf[b].stride; }
char* RandomElem ( uchar b, href& ndx );
char* AddElem ( uchar b, href& pos );
int AddElem ( uchar b, char* data );
bool DelElem ( uchar b, int n );
char* GetStart ( uchar b ) { return mBuf[b].data; }
char* GetEnd ( uchar b ) { return mBuf[b].data + mBuf[b].num*mBuf[b].stride; }
GeomBuf* GetBuffer ( uchar b ) { return &mBuf[b]; }
GeomAttr* GetAttribute ( int n ) { return &mAttribute[n]; }
int GetNumBuf () { return (int) mBuf.size(); }
int GetNumAttr () { return (int) mAttribute.size(); }
hval* GetHeap ( hpos& num, hpos& max, hpos& free );
int GetSize ();
/*int AddRef ( int b, int n, int ref, ushort listpos );
int AddRef ( int b, int n, int ref, bool bUseHeap, ushort listpos, ushort width );*/
void ClearRefs ( hList& list );
hval AddRef ( hval r, hList& list, hval delta );
hpos HeapAlloc ( ushort size, ushort& ret );
hpos HeapExpand ( ushort size, ushort& ret );
void HeapAddFree ( hpos pos, int size );
protected:
std::vector< GeomBuf > mBuf;
std::vector< GeomAttr > mAttribute;
hpos mHeapNum;
hpos mHeapMax;
hpos mHeapFree;
hval* mHeap;
};
#endif
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2008. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef DEF_GEOM
#define DEF_GEOM
#include <vector>
#define HEAP_MAX 2147483640 // largest heap size (range of hpos)
#define ELEM_MAX 2147483640 // largest number of elements in a buffer (range of hval)
//#define ELEM_MAX 32768 // largest number of elements in a buffer (range of hval)
#define BUF_UNDEF 255
#define FPOS 2 // free position offsets
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef signed int hpos; // pointers into heap
typedef signed int hval; // values in heap
typedef hval href; // values are typically references
struct hList {
ushort cnt;
ushort max;
hpos pos;
};
class GeomAttr {
public:
GeomAttr() { name = ""; buf = 0; stride = 0; offset = 0; }
std::string name;
ushort buf;
ushort stride;
ushort offset;
};
class GeomBuf {
public:
GeomBuf() { dtype = 0; num = 0; max = 0; stride = 0; data = 0x0; }
uchar dtype;
hval num;
hval max;
long size;
ushort stride;
char* data;
};
class GeomX {
public:
GeomX ();
// virtual objType GetType () { return 'geom'; }
// Basic geometry setup
void FreeBuffers ();
void ClearAttributes ();
void AddHeap ( int max );
int CopyBuffer ( uchar bdest, uchar bsrc, GeomX& src );
void CopyBuffers ( GeomX& src );
void CopyAttributes ( GeomX& src );
void CopyHeap ( GeomX& src );
void ResetBuffer ( uchar b, int n );
void ResetHeap ();
int AddBuffer ( uchar typ, ushort stride, int max );
int AddAttribute ( uchar b, std::string name, ushort stride );
int AddAttribute ( uchar b, std::string name, ushort stride, bool bExtend );
int GetAttribute ( std::string name );
int GetAttrOffset ( std::string name );
int NumElem ( uchar b ) { if ( b==BUF_UNDEF) return 0; else return mBuf[b].num; }
int MaxElem ( uchar b ) { if ( b==BUF_UNDEF) return 0; else return mBuf[b].max; }
int GetStride ( uchar b ) { return mBuf[b].stride; }
char* GetElem ( uchar b, int n ) { return mBuf[b].data + n*mBuf[b].stride; }
char* RandomElem ( uchar b, href& ndx );
char* AddElem ( uchar b, href& pos );
int AddElem ( uchar b, char* data );
bool DelElem ( uchar b, int n );
char* GetStart ( uchar b ) { return mBuf[b].data; }
char* GetEnd ( uchar b ) { return mBuf[b].data + mBuf[b].num*mBuf[b].stride; }
GeomBuf* GetBuffer ( uchar b ) { return &mBuf[b]; }
GeomAttr* GetAttribute ( int n ) { return &mAttribute[n]; }
int GetNumBuf () { return (int) mBuf.size(); }
int GetNumAttr () { return (int) mAttribute.size(); }
hval* GetHeap ( hpos& num, hpos& max, hpos& free );
int GetSize ();
/*int AddRef ( int b, int n, int ref, ushort listpos );
int AddRef ( int b, int n, int ref, bool bUseHeap, ushort listpos, ushort width );*/
void ClearRefs ( hList& list );
hval AddRef ( hval r, hList& list, hval delta );
hpos HeapAlloc ( ushort size, ushort& ret );
hpos HeapExpand ( ushort size, ushort& ret );
void HeapAddFree ( hpos pos, int size );
protected:
std::vector< GeomBuf > mBuf;
std::vector< GeomAttr > mAttribute;
hpos mHeapNum;
hpos mHeapMax;
hpos mHeapFree;
hval* mHeap;
};
#endif

View File

@@ -1,402 +1,402 @@
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "common_defs.h"
#include "gl_helper.h"
#include <math.h>
// Shadow Light
float light_proj[16];
float light_x, light_y, light_z;
float light_tox, light_toy, light_toz;
float light_mfov;
// Fonts
void *font = GLUT_BITMAP_8_BY_13;
void *fonts[] = {GLUT_BITMAP_9_BY_15,
GLUT_BITMAP_TIMES_ROMAN_10,
GLUT_BITMAP_TIMES_ROMAN_24};
// Timing
mint::Time tm_last;
int tm_cnt;
float tm_fps;
GLuint glSphere = 65535;
float glRadius = 0.0;
void setSphereRadius ( float r )
{
if ( glRadius == r ) return;
glRadius = r;
// GL sphere
if ( glSphere != 65535 ) glDeleteLists ( glSphere, 1 );
glSphere = glGenLists ( 1 );
float x, y, z, x1, y1, z1;
glNewList ( glSphere, GL_COMPILE );
glBegin ( GL_TRIANGLE_STRIP );
for ( float tilt=-90; tilt <= 90; tilt += 10.0) {
for ( float ang=0; ang <= 360; ang += 30.0) {
x = sin ( ang*DEGtoRAD) * cos ( tilt*DEGtoRAD );
y = cos ( ang*DEGtoRAD) * cos ( tilt*DEGtoRAD );
z = sin ( tilt*DEGtoRAD ) ;
x1 = sin ( ang*DEGtoRAD) * cos ( (tilt+10.0)*DEGtoRAD ) ;
y1 = cos ( ang*DEGtoRAD) * cos ( (tilt+10.0)*DEGtoRAD ) ;
z1 = sin ( (tilt+10.0)*DEGtoRAD );
glNormal3f ( x, y, z ); glVertex3f ( x*r, y*r, z*r );
glNormal3f ( x1, y1, z1 ); glVertex3f ( x1*r, y1*r, z1*r );
}
}
glEnd ();
glEndList ();
}
void drawSphere ()
{
if ( glRadius == 0.0 ) setSphereRadius ( 1.0 );
glCallList ( glSphere );
}
// Check if there have been any openGL problems
void checkOpenGL ()
{
GLenum errCode = glGetError();
if (errCode != GL_NO_ERROR) {
const GLubyte* errString = gluErrorString(errCode);
fprintf( stderr, "OpenGL error: %s\n", errString );
}
}
void drawText ( int x, int y, char* msg)
{
int len, i;
glRasterPos2f(x, y);
len = (int) strlen(msg);
for (i = 0; i < len; i++)
glutBitmapCharacter(font, msg[i]);
}
void drawGrid ()
{
glColor3f ( 0.3, 0.3, 0.3 );
glBegin ( GL_LINES );
for (float x=-40; x<=40.0; x+=10.0 ) {
glVertex3f ( x, -40.0, 0 );
glVertex3f ( x, 40.0, 0 );
}
for (float y=-40; y<=40.0; y+=10.0 ) {
glVertex3f ( -40.0, y, 0 );
glVertex3f ( 40.0, y, 0 );
}
glEnd ();
}
void measureFPS ()
{
// Measure FPS
mint::Time tm_elaps;
if ( ++tm_cnt > 5 ) {
tm_elaps.SetSystemTime ( ACC_NSEC ); // get current sytem time - accurate to 1 ns
tm_elaps = tm_elaps - tm_last; // get elapsed time from 5 frames ago
tm_fps = 5.0 * 1000.0 / tm_elaps.GetMSec (); // compute fps
tm_cnt = 0; // reset frame counter
tm_last.SetSystemTime ( ACC_NSEC );
}
}
void checkFrameBuffers ()
{
GLenum status;
status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
switch(status) {
case GL_FRAMEBUFFER_COMPLETE_EXT: printf ( "FBO complete\n" ); break;
case GL_FRAMEBUFFER_UNSUPPORTED_EXT: printf ( "FBO format unsupported\n"); break;
default: printf ( "Unknown FBO error\n");
}
}
void disableShadows ()
{
glDisable ( GL_TEXTURE_2D );
glActiveTextureARB( GL_TEXTURE1_ARB );
glBindTexture ( GL_TEXTURE_2D, 0 );
glDisable ( GL_TEXTURE_GEN_S );
glDisable ( GL_TEXTURE_GEN_T );
glDisable ( GL_TEXTURE_GEN_R );
glDisable ( GL_TEXTURE_GEN_Q );
glActiveTextureARB( GL_TEXTURE2_ARB );
glBindTexture ( GL_TEXTURE_2D, 0 );
glDisable ( GL_TEXTURE_GEN_S );
glDisable ( GL_TEXTURE_GEN_T );
glDisable ( GL_TEXTURE_GEN_R );
glDisable ( GL_TEXTURE_GEN_Q );
}
#ifdef USE_SHADOWS
// Materials & Textures
GLuint shadow1_id = 0; // display buffer shadows
GLuint shadow2_id = 0; // display buffer shadows
// Frame buffer
GLuint frameBufferObject = 0; // frame buffer shadows
void createFrameBuffer ()
{
//Generate the frame buffer object
glGenFramebuffersEXT (1, &frameBufferObject);
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, frameBufferObject); // Turn on frame buffer object
glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, shadow1_id, 0);
glDrawBuffer (GL_NONE); // Set Draw & ReadBuffer to none since we're rendering depth only
glReadBuffer (GL_NONE);
checkFrameBuffers (); // Check completeness of frame buffer object (no need for stencil and depth attachement)
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0); // Turn off frame buffer object
}
void createShadowTextures ()
{
// Create depth texture maps
glActiveTextureARB( GL_TEXTURE1_ARB );
glGenTextures( 1, &shadow1_id );
glBindTexture ( GL_TEXTURE_2D, shadow1_id );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
//-- sets region outside shadow to 0
//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER_ARB );
//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER_ARB );
//-- sets region outside shadow to 1 (border edge color)
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D ( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24_ARB, TEX_SIZE, TEX_SIZE, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0);
glActiveTextureARB( GL_TEXTURE2_ARB );
glGenTextures( 1, &shadow2_id );
glBindTexture ( GL_TEXTURE_2D, shadow2_id );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER_ARB );
//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER_ARB );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D ( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24_ARB, TEX_SIZE, TEX_SIZE, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0);
}
void computeLightMatrix ( int n, int tx, int ty )
{
int lnum = n;
// Construct projective texturing matrix
// S - light bias matrix
glMatrixMode ( GL_MODELVIEW );
glLoadIdentity ();
glTranslatef ( 0.5, 0.5, 0.5 );
glScalef ( 0.5, 0.5, 0.5 );
// Plight - light projection matrix
gluPerspective ( light_mfov*2.0, float(tx) / ty, LIGHT_NEAR, LIGHT_FAR );
// L^-1 - light view inverse matrix
gluLookAt ( light_x, light_y, light_z, light_tox, light_toy, light_toz, 0, 0, 1);
glPushMatrix ();
glGetFloatv ( GL_MODELVIEW_MATRIX, light_proj );
glPopMatrix ();
}
void renderDepthMap_Clear ( float wx, float wy )
{
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, frameBufferObject);
glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, shadow1_id, 0);
glActiveTextureARB( GL_TEXTURE1_ARB ); // TEXTURE1 = shadow map stage
glViewport (1, 1, TEX_SIZE-2, TEX_SIZE-2); // Note: Avoid artifact cause by drawing into border pixels
glClear ( GL_DEPTH_BUFFER_BIT );
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
glViewport ( 0, 0, (GLsizei) wx, (GLsizei) wy );
}
void renderDepthMap_FrameBuffer ( int n, float wx, float wy )
{
float vmat[16];
computeLightMatrix ( n, TEX_SIZE, TEX_SIZE );
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, frameBufferObject);
if ( n == 0 ) {
glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, shadow1_id, 0);
} else {
glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, shadow2_id, 0);
}
if ( n == 0 ) glActiveTextureARB( GL_TEXTURE1_ARB ); // TEXTURE1 = shadow map stage
else glActiveTextureARB( GL_TEXTURE2_ARB ); // TEXTURE2 = shadow map stage
glViewport (1, 1, TEX_SIZE-2, TEX_SIZE-2); // Note: Avoid artifact cause by drawing into border pixels
glClear ( GL_DEPTH_BUFFER_BIT );
glLoadIdentity();
// Plight - projection matrix of light
glMatrixMode ( GL_PROJECTION ); // Setup projection for depth-map rendering
glLoadIdentity ();
gluPerspective ( light_mfov*2.0, float(TEX_SIZE) / TEX_SIZE, LIGHT_NEAR, LIGHT_FAR );
// L^-1 - light view matrix (gluLookAt computes inverse)
glMatrixMode ( GL_MODELVIEW); // Setup view for depth-map rendering
glLoadIdentity ();
gluLookAt ( light_x, light_y, light_z, light_tox, light_toy, light_toz, 0, 0, 1);
glPushMatrix (); // Save view matrix for later
glGetFloatv ( GL_MODELVIEW_MATRIX, vmat );
glPopMatrix ();
glDisable ( GL_LIGHTING );
glColor4f ( 1, 1, 1, 1 );
glShadeModel (GL_FLAT); // No shading (faster)
glEnable ( GL_CULL_FACE );
glCullFace ( GL_FRONT );
glEnable ( GL_POLYGON_OFFSET_FILL );
glPolygonOffset ( 50.0, 0.1 ); // Depth bias
drawScene ( &vmat[0], false ); // Draw scene.
glDisable ( GL_POLYGON_OFFSET_FILL );
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
glViewport ( 0, 0, (GLsizei) wx, (GLsizei) wy );
//glCullFace (GL_BACK); // Restore render states
//glBindTexture ( GL_TEXTURE_2D, 0);
}
void renderShadowStage ( int n, float* vmat )
{
GLfloat pos[4];
GLfloat row[4];
computeLightMatrix ( n, TEX_SIZE, TEX_SIZE );
if ( n == 0 ) {
glActiveTextureARB( GL_TEXTURE1_ARB ); // TEXTURE1 = shadow map stage #1
} else {
glActiveTextureARB( GL_TEXTURE2_ARB ); // TEXTURE2 = shadow map stage #2
}
glEnable ( GL_TEXTURE_2D );
if ( n == 0 ) glBindTexture ( GL_TEXTURE_2D, shadow1_id );
else glBindTexture ( GL_TEXTURE_2D, shadow2_id );
glMatrixMode( GL_MODELVIEW );
glLoadMatrixf ( vmat );
row[0] = light_proj[0]; row[1] = light_proj[4]; row[2] = light_proj[8]; row[3] = light_proj[12];
glTexGenfv(GL_S, GL_EYE_PLANE, &row[0] );
row[0] = light_proj[1]; row[1] = light_proj[5]; row[2] = light_proj[9]; row[3] = light_proj[13];
glTexGenfv(GL_T, GL_EYE_PLANE, &row[0] );
row[0] = light_proj[2]; row[1] = light_proj[6]; row[2] = light_proj[10]; row[3] = light_proj[14];
glTexGenfv(GL_R, GL_EYE_PLANE, &row[0] );
row[0] = light_proj[3]; row[1] = light_proj[7]; row[2] = light_proj[11]; row[3] = light_proj[15];
glTexGenfv(GL_Q, GL_EYE_PLANE, &row[0] );
glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glEnable(GL_TEXTURE_GEN_Q);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE ) ;
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE ) ;
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS ) ;
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_CONSTANT ) ;
pos[0] = 0.20;
pos[1] = 0.20;
pos[2] = 0.20;
pos[3] = 0.20;
glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &pos[0] );
}
void renderShadows ( float* vmat )
{
GLfloat pos[4];
renderShadowStage ( 0, vmat );
// renderShadowStage ( 1, vmat );
glActiveTextureARB( GL_TEXTURE0_ARB ); // Render Tex 0 - Base render
glDisable ( GL_TEXTURE_GEN_S );
glDisable ( GL_TEXTURE_GEN_T );
glDisable ( GL_TEXTURE_GEN_R );
glDisable ( GL_TEXTURE_GEN_Q );
glTexEnvi ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glEnable ( GL_LIGHTING );
glLightModeli (GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SEPARATE_SPECULAR_COLOR_EXT);
glEnable ( GL_LIGHT0 );
pos[0] = light_x; pos[1] = light_y; pos[2] = light_z; pos[3] = 1.0;
glLightfv ( GL_LIGHT0, GL_POSITION, &pos[0] );
/* glEnable ( GL_LIGHT1 );
pos[0] = light[1].x; pos[1] = light[1].y; pos[2] = light[1].z; pos[3] = 1.0;
glLightfv ( GL_LIGHT1, GL_POSITION, &pos[0] );*/
}
void setShadowLight ( float fx, float fy, float fz, float tx, float ty, float tz, float fov )
{
light_x = fx;
light_y = fy;
light_z = fz;
light_tox = tx;
light_toy = ty;
light_toz = tz;
light_mfov = fov;
}
void setShadowLightColor ( float dr, float dg, float db, float sr, float sg, float sb )
{
GLfloat amb[4] = {0.0,0.0,0.0,1};
GLfloat dif[4];
GLfloat spec[4];
GLfloat pos[4] = {0.0,0.0,0.0, 100.0};
glEnable(GL_LIGHT0);
dif[0] = dr; dif[1] = dg; dif[2] = db; dif[3] = 1;
spec[0] = sr; spec[1] = sg; spec[2] = sb; spec[3] = 1;
glLightfv(GL_LIGHT0, GL_AMBIENT, &amb[0] );
glLightfv(GL_LIGHT0, GL_DIFFUSE, &dif[0] );
glLightfv(GL_LIGHT0, GL_SPECULAR, &spec[0] );
}
#endif
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "common_defs.h"
#include "gl_helper.h"
#include <math.h>
// Shadow Light
float light_proj[16];
float light_x, light_y, light_z;
float light_tox, light_toy, light_toz;
float light_mfov;
// Fonts
void *font = GLUT_BITMAP_8_BY_13;
void *fonts[] = {GLUT_BITMAP_9_BY_15,
GLUT_BITMAP_TIMES_ROMAN_10,
GLUT_BITMAP_TIMES_ROMAN_24};
// Timing
mint::Time tm_last;
int tm_cnt;
float tm_fps;
GLuint glSphere = 65535;
float glRadius = 0.0;
void setSphereRadius ( float r )
{
if ( glRadius == r ) return;
glRadius = r;
// GL sphere
if ( glSphere != 65535 ) glDeleteLists ( glSphere, 1 );
glSphere = glGenLists ( 1 );
float x, y, z, x1, y1, z1;
glNewList ( glSphere, GL_COMPILE );
glBegin ( GL_TRIANGLE_STRIP );
for ( float tilt=-90; tilt <= 90; tilt += 10.0) {
for ( float ang=0; ang <= 360; ang += 30.0) {
x = sin ( ang*DEGtoRAD) * cos ( tilt*DEGtoRAD );
y = cos ( ang*DEGtoRAD) * cos ( tilt*DEGtoRAD );
z = sin ( tilt*DEGtoRAD ) ;
x1 = sin ( ang*DEGtoRAD) * cos ( (tilt+10.0)*DEGtoRAD ) ;
y1 = cos ( ang*DEGtoRAD) * cos ( (tilt+10.0)*DEGtoRAD ) ;
z1 = sin ( (tilt+10.0)*DEGtoRAD );
glNormal3f ( x, y, z ); glVertex3f ( x*r, y*r, z*r );
glNormal3f ( x1, y1, z1 ); glVertex3f ( x1*r, y1*r, z1*r );
}
}
glEnd ();
glEndList ();
}
void drawSphere ()
{
if ( glRadius == 0.0 ) setSphereRadius ( 1.0 );
glCallList ( glSphere );
}
// Check if there have been any openGL problems
void checkOpenGL ()
{
GLenum errCode = glGetError();
if (errCode != GL_NO_ERROR) {
const GLubyte* errString = gluErrorString(errCode);
fprintf( stderr, "OpenGL error: %s\n", errString );
}
}
void drawText ( int x, int y, char* msg)
{
int len, i;
glRasterPos2f(x, y);
len = (int) strlen(msg);
for (i = 0; i < len; i++)
glutBitmapCharacter(font, msg[i]);
}
void drawGrid ()
{
glColor3f ( 0.3, 0.3, 0.3 );
glBegin ( GL_LINES );
for (float x=-40; x<=40.0; x+=10.0 ) {
glVertex3f ( x, -40.0, 0 );
glVertex3f ( x, 40.0, 0 );
}
for (float y=-40; y<=40.0; y+=10.0 ) {
glVertex3f ( -40.0, y, 0 );
glVertex3f ( 40.0, y, 0 );
}
glEnd ();
}
void measureFPS ()
{
// Measure FPS
mint::Time tm_elaps;
if ( ++tm_cnt > 5 ) {
tm_elaps.SetSystemTime ( ACC_NSEC ); // get current sytem time - accurate to 1 ns
tm_elaps = tm_elaps - tm_last; // get elapsed time from 5 frames ago
tm_fps = 5.0 * 1000.0 / tm_elaps.GetMSec (); // compute fps
tm_cnt = 0; // reset frame counter
tm_last.SetSystemTime ( ACC_NSEC );
}
}
void checkFrameBuffers ()
{
GLenum status;
status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
switch(status) {
case GL_FRAMEBUFFER_COMPLETE_EXT: printf ( "FBO complete\n" ); break;
case GL_FRAMEBUFFER_UNSUPPORTED_EXT: printf ( "FBO format unsupported\n"); break;
default: printf ( "Unknown FBO error\n");
}
}
void disableShadows ()
{
glDisable ( GL_TEXTURE_2D );
glActiveTextureARB( GL_TEXTURE1_ARB );
glBindTexture ( GL_TEXTURE_2D, 0 );
glDisable ( GL_TEXTURE_GEN_S );
glDisable ( GL_TEXTURE_GEN_T );
glDisable ( GL_TEXTURE_GEN_R );
glDisable ( GL_TEXTURE_GEN_Q );
glActiveTextureARB( GL_TEXTURE2_ARB );
glBindTexture ( GL_TEXTURE_2D, 0 );
glDisable ( GL_TEXTURE_GEN_S );
glDisable ( GL_TEXTURE_GEN_T );
glDisable ( GL_TEXTURE_GEN_R );
glDisable ( GL_TEXTURE_GEN_Q );
}
#ifdef USE_SHADOWS
// Materials & Textures
GLuint shadow1_id = 0; // display buffer shadows
GLuint shadow2_id = 0; // display buffer shadows
// Frame buffer
GLuint frameBufferObject = 0; // frame buffer shadows
void createFrameBuffer ()
{
//Generate the frame buffer object
glGenFramebuffersEXT (1, &frameBufferObject);
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, frameBufferObject); // Turn on frame buffer object
glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, shadow1_id, 0);
glDrawBuffer (GL_NONE); // Set Draw & ReadBuffer to none since we're rendering depth only
glReadBuffer (GL_NONE);
checkFrameBuffers (); // Check completeness of frame buffer object (no need for stencil and depth attachement)
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0); // Turn off frame buffer object
}
void createShadowTextures ()
{
// Create depth texture maps
glActiveTextureARB( GL_TEXTURE1_ARB );
glGenTextures( 1, &shadow1_id );
glBindTexture ( GL_TEXTURE_2D, shadow1_id );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
//-- sets region outside shadow to 0
//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER_ARB );
//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER_ARB );
//-- sets region outside shadow to 1 (border edge color)
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D ( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24_ARB, TEX_SIZE, TEX_SIZE, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0);
glActiveTextureARB( GL_TEXTURE2_ARB );
glGenTextures( 1, &shadow2_id );
glBindTexture ( GL_TEXTURE_2D, shadow2_id );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER_ARB );
//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER_ARB );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D ( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24_ARB, TEX_SIZE, TEX_SIZE, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0);
}
void computeLightMatrix ( int n, int tx, int ty )
{
int lnum = n;
// Construct projective texturing matrix
// S - light bias matrix
glMatrixMode ( GL_MODELVIEW );
glLoadIdentity ();
glTranslatef ( 0.5, 0.5, 0.5 );
glScalef ( 0.5, 0.5, 0.5 );
// Plight - light projection matrix
gluPerspective ( light_mfov*2.0, float(tx) / ty, LIGHT_NEAR, LIGHT_FAR );
// L^-1 - light view inverse matrix
gluLookAt ( light_x, light_y, light_z, light_tox, light_toy, light_toz, 0, 0, 1);
glPushMatrix ();
glGetFloatv ( GL_MODELVIEW_MATRIX, light_proj );
glPopMatrix ();
}
void renderDepthMap_Clear ( float wx, float wy )
{
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, frameBufferObject);
glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, shadow1_id, 0);
glActiveTextureARB( GL_TEXTURE1_ARB ); // TEXTURE1 = shadow map stage
glViewport (1, 1, TEX_SIZE-2, TEX_SIZE-2); // Note: Avoid artifact cause by drawing into border pixels
glClear ( GL_DEPTH_BUFFER_BIT );
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
glViewport ( 0, 0, (GLsizei) wx, (GLsizei) wy );
}
void renderDepthMap_FrameBuffer ( int n, float wx, float wy )
{
float vmat[16];
computeLightMatrix ( n, TEX_SIZE, TEX_SIZE );
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, frameBufferObject);
if ( n == 0 ) {
glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, shadow1_id, 0);
} else {
glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, shadow2_id, 0);
}
if ( n == 0 ) glActiveTextureARB( GL_TEXTURE1_ARB ); // TEXTURE1 = shadow map stage
else glActiveTextureARB( GL_TEXTURE2_ARB ); // TEXTURE2 = shadow map stage
glViewport (1, 1, TEX_SIZE-2, TEX_SIZE-2); // Note: Avoid artifact cause by drawing into border pixels
glClear ( GL_DEPTH_BUFFER_BIT );
glLoadIdentity();
// Plight - projection matrix of light
glMatrixMode ( GL_PROJECTION ); // Setup projection for depth-map rendering
glLoadIdentity ();
gluPerspective ( light_mfov*2.0, float(TEX_SIZE) / TEX_SIZE, LIGHT_NEAR, LIGHT_FAR );
// L^-1 - light view matrix (gluLookAt computes inverse)
glMatrixMode ( GL_MODELVIEW); // Setup view for depth-map rendering
glLoadIdentity ();
gluLookAt ( light_x, light_y, light_z, light_tox, light_toy, light_toz, 0, 0, 1);
glPushMatrix (); // Save view matrix for later
glGetFloatv ( GL_MODELVIEW_MATRIX, vmat );
glPopMatrix ();
glDisable ( GL_LIGHTING );
glColor4f ( 1, 1, 1, 1 );
glShadeModel (GL_FLAT); // No shading (faster)
glEnable ( GL_CULL_FACE );
glCullFace ( GL_FRONT );
glEnable ( GL_POLYGON_OFFSET_FILL );
glPolygonOffset ( 50.0, 0.1 ); // Depth bias
drawScene ( &vmat[0], false ); // Draw scene.
glDisable ( GL_POLYGON_OFFSET_FILL );
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
glViewport ( 0, 0, (GLsizei) wx, (GLsizei) wy );
//glCullFace (GL_BACK); // Restore render states
//glBindTexture ( GL_TEXTURE_2D, 0);
}
void renderShadowStage ( int n, float* vmat )
{
GLfloat pos[4];
GLfloat row[4];
computeLightMatrix ( n, TEX_SIZE, TEX_SIZE );
if ( n == 0 ) {
glActiveTextureARB( GL_TEXTURE1_ARB ); // TEXTURE1 = shadow map stage #1
} else {
glActiveTextureARB( GL_TEXTURE2_ARB ); // TEXTURE2 = shadow map stage #2
}
glEnable ( GL_TEXTURE_2D );
if ( n == 0 ) glBindTexture ( GL_TEXTURE_2D, shadow1_id );
else glBindTexture ( GL_TEXTURE_2D, shadow2_id );
glMatrixMode( GL_MODELVIEW );
glLoadMatrixf ( vmat );
row[0] = light_proj[0]; row[1] = light_proj[4]; row[2] = light_proj[8]; row[3] = light_proj[12];
glTexGenfv(GL_S, GL_EYE_PLANE, &row[0] );
row[0] = light_proj[1]; row[1] = light_proj[5]; row[2] = light_proj[9]; row[3] = light_proj[13];
glTexGenfv(GL_T, GL_EYE_PLANE, &row[0] );
row[0] = light_proj[2]; row[1] = light_proj[6]; row[2] = light_proj[10]; row[3] = light_proj[14];
glTexGenfv(GL_R, GL_EYE_PLANE, &row[0] );
row[0] = light_proj[3]; row[1] = light_proj[7]; row[2] = light_proj[11]; row[3] = light_proj[15];
glTexGenfv(GL_Q, GL_EYE_PLANE, &row[0] );
glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glEnable(GL_TEXTURE_GEN_Q);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE ) ;
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE ) ;
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS ) ;
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_CONSTANT ) ;
pos[0] = 0.20;
pos[1] = 0.20;
pos[2] = 0.20;
pos[3] = 0.20;
glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &pos[0] );
}
void renderShadows ( float* vmat )
{
GLfloat pos[4];
renderShadowStage ( 0, vmat );
// renderShadowStage ( 1, vmat );
glActiveTextureARB( GL_TEXTURE0_ARB ); // Render Tex 0 - Base render
glDisable ( GL_TEXTURE_GEN_S );
glDisable ( GL_TEXTURE_GEN_T );
glDisable ( GL_TEXTURE_GEN_R );
glDisable ( GL_TEXTURE_GEN_Q );
glTexEnvi ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glEnable ( GL_LIGHTING );
glLightModeli (GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SEPARATE_SPECULAR_COLOR_EXT);
glEnable ( GL_LIGHT0 );
pos[0] = light_x; pos[1] = light_y; pos[2] = light_z; pos[3] = 1.0;
glLightfv ( GL_LIGHT0, GL_POSITION, &pos[0] );
/* glEnable ( GL_LIGHT1 );
pos[0] = light[1].x; pos[1] = light[1].y; pos[2] = light[1].z; pos[3] = 1.0;
glLightfv ( GL_LIGHT1, GL_POSITION, &pos[0] );*/
}
void setShadowLight ( float fx, float fy, float fz, float tx, float ty, float tz, float fov )
{
light_x = fx;
light_y = fy;
light_z = fz;
light_tox = tx;
light_toy = ty;
light_toz = tz;
light_mfov = fov;
}
void setShadowLightColor ( float dr, float dg, float db, float sr, float sg, float sb )
{
GLfloat amb[4] = {0.0,0.0,0.0,1};
GLfloat dif[4];
GLfloat spec[4];
GLfloat pos[4] = {0.0,0.0,0.0, 100.0};
glEnable(GL_LIGHT0);
dif[0] = dr; dif[1] = dg; dif[2] = db; dif[3] = 1;
spec[0] = sr; spec[1] = sg; spec[2] = sb; spec[3] = 1;
glLightfv(GL_LIGHT0, GL_AMBIENT, &amb[0] );
glLightfv(GL_LIGHT0, GL_DIFFUSE, &dif[0] );
glLightfv(GL_LIGHT0, GL_SPECULAR, &spec[0] );
}
#endif

View File

@@ -1,89 +1,89 @@
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef GL_HELPER
#define GL_HELPER
#include "common_defs.h"
#include <glee.h>
#include <gl/glext.h>
#ifdef _MSC_VER // Windows
#ifdef USE_SHADOWS
#include <gl/glee.h>
#include <gl/glext.h>
#endif
#include <gl/glut.h>
#else // Linux
#ifdef USE_SHADOWS
#include "GLee.h"
#endif
#include <GL/glext.h>
#include <GL/glut.h>
#endif
#include "image.h"
#include "mtime.h"
extern void checkOpenGL ();
extern void drawText ( int x, int y, char* msg);
extern void drawGrid ();
extern void measureFPS ();
extern mint::Time tm_last;
extern int tm_cnt;
extern float tm_fps;
extern void disableShadows ();
extern void checkFrameBuffers ();
extern GLuint glSphere;
extern float glRadius;
extern void setSphereRadius ( float f );
extern void drawSphere ();
#ifdef USE_SHADOWS
extern void setShadowLight ( float fx, float fy, float fz, float tx, float ty, float tz, float fov );
extern void setShadowLightColor ( float dr, float dg, float db, float sr, float sg, float sb );
extern void createFrameBuffer ();
extern void createShadowTextures ();
extern void computeLightMatrix ( int n, int tx, int ty );
extern void renderDepthMap_Clear ( float wx, float wy );
extern void renderDepthMap_FrameBuffer ( int n, float wx, float wy );
extern void renderShadowStage ( int n, float* vmat );
extern void renderShadows ( float* vmat );
extern void drawScene ( float* view_mat, bool bShaders ); // provided by user
extern float light_proj[16];
extern float light_x, light_y, light_z;
extern float light_tox, light_toy, light_toz;
extern float light_mfov;
extern GLuint shadow1_id;
extern GLuint shadow2_id;
#endif
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef GL_HELPER
#define GL_HELPER
#include "common_defs.h"
#include <glee.h>
#include <gl/glext.h>
#ifdef _MSC_VER // Windows
#ifdef USE_SHADOWS
#include <gl/glee.h>
#include <gl/glext.h>
#endif
#include <gl/glut.h>
#else // Linux
#ifdef USE_SHADOWS
#include "GLee.h"
#endif
#include <GL/glext.h>
#include <GL/glut.h>
#endif
#include "image.h"
#include "mtime.h"
extern void checkOpenGL ();
extern void drawText ( int x, int y, char* msg);
extern void drawGrid ();
extern void measureFPS ();
extern mint::Time tm_last;
extern int tm_cnt;
extern float tm_fps;
extern void disableShadows ();
extern void checkFrameBuffers ();
extern GLuint glSphere;
extern float glRadius;
extern void setSphereRadius ( float f );
extern void drawSphere ();
#ifdef USE_SHADOWS
extern void setShadowLight ( float fx, float fy, float fz, float tx, float ty, float tz, float fov );
extern void setShadowLightColor ( float dr, float dg, float db, float sr, float sg, float sb );
extern void createFrameBuffer ();
extern void createShadowTextures ();
extern void computeLightMatrix ( int n, int tx, int ty );
extern void renderDepthMap_Clear ( float wx, float wy );
extern void renderDepthMap_FrameBuffer ( int n, float wx, float wy );
extern void renderShadowStage ( int n, float* vmat );
extern void renderShadows ( float* vmat );
extern void drawScene ( float* view_mat, bool bShaders ); // provided by user
extern float light_proj[16];
extern float light_x, light_y, light_z;
extern float light_tox, light_toy, light_toz;
extern float light_mfov;
extern GLuint shadow1_id;
extern GLuint shadow2_id;
#endif
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,23 +1,23 @@
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "matrix.h"
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "matrix.h"

View File

@@ -1,429 +1,429 @@
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <memory.h>
#include <math.h>
//*********** NOTE
//
// LOOK AT MovieTrackPoint. IN ORDER FOR VECTORS AND MATRICIES TO BE USED IN OBJECTS
// THAT WILL BE USED IN stl::vectors, THEIR CONSTRUCTORS AND OPERATORS MUST TAKE ONLY
// const PARAMETERS. LOOK AT MatrixF and Vector2DF.. THIS WAS NOT YET DONE WITH
// THE OTHER MATRIX AND VECTOR CLASSES (Vector2DC, Vector2DI, MatrixC, MatrixI, ...)
//
#ifndef MATRIX_DEF
#define MATRIX_DEF
#include "vector.h"
#include "mdebug.h"
//#define MATRIX_INITIALIZE // Initializes vectors
class MatrixC; // Forward Referencing
class MatrixI;
class MatrixF;
class Matrix {
public:
// Member Virtual Functions
virtual Matrix &operator= (unsigned char c)=0;
virtual Matrix &operator= (int c)=0;
virtual Matrix &operator= (double c)=0;
virtual Matrix &operator= (MatrixC &op)=0;
virtual Matrix &operator= (MatrixI &op)=0;
virtual Matrix &operator= (MatrixF &op)=0;
virtual Matrix &operator+= (unsigned char c)=0;
virtual Matrix &operator+= (int c)=0;
virtual Matrix &operator+= (double c)=0;
virtual Matrix &operator+= (MatrixC &op)=0;
virtual Matrix &operator+= (MatrixI &op)=0;
virtual Matrix &operator+= (MatrixF &op)=0;
virtual Matrix &operator-= (unsigned char c)=0;
virtual Matrix &operator-= (int c)=0;
virtual Matrix &operator-= (double c)=0;
virtual Matrix &operator-= (MatrixC &op)=0;
virtual Matrix &operator-= (MatrixI &op)=0;
virtual Matrix &operator-= (MatrixF &op)=0;
virtual Matrix &operator*= (unsigned char c)=0;
virtual Matrix &operator*= (int c)=0;
virtual Matrix &operator*= (double c)=0;
virtual Matrix &operator*= (MatrixC &op)=0;
virtual Matrix &operator*= (MatrixI &op)=0;
virtual Matrix &operator*= (MatrixF &op)=0;
virtual Matrix &operator/= (unsigned char c)=0;
virtual Matrix &operator/= (int c)=0;
virtual Matrix &operator/= (double c)=0;
virtual Matrix &operator/= (MatrixC &op)=0;
virtual Matrix &operator/= (MatrixI &op)=0;
virtual Matrix &operator/= (MatrixF &op)=0;
virtual Matrix &Multiply (MatrixF &op)=0;
virtual Matrix &Resize (int x, int y)=0;
virtual Matrix &ResizeSafe (int x, int y)=0;
virtual Matrix &InsertRow (int r)=0;
virtual Matrix &InsertCol (int c)=0;
virtual Matrix &Transpose (void)=0;
virtual Matrix &Identity (int order)=0;
/*inline Matrix &RotateX (double ang);
inline Matrix &RotateY (double ang);
inline Matrix &RotateZ (double ang); */
virtual Matrix &Basis (Vector3DF &c1, Vector3DF &c2, Vector3DF &c3)=0;
virtual Matrix &GaussJordan (MatrixF &b) { return *this; }
virtual Matrix &ConjugateGradient (MatrixF &b) { return *this; }
virtual int GetRows(void)=0;
virtual int GetCols(void)=0;
virtual int GetLength(void)=0;
virtual unsigned char *GetDataC (void)=0;
virtual int *GetDataI (void)=0;
virtual double *GetDataF (void)=0;
virtual double GetF (int r, int c);
};
// MatrixC Declaration
#define VNAME C
#define VTYPE unsigned char
class MatrixC {
public:
VTYPE *data;
int rows, cols, len;
// Constructors/Destructors
inline MatrixC ();
inline ~MatrixC ();
inline MatrixC (int r, int c);
// Member Functions
inline VTYPE &operator () (int c, int r);
inline MatrixC &operator= (unsigned char c);
inline MatrixC &operator= (int c);
inline MatrixC &operator= (double c);
inline MatrixC &operator= (MatrixC &op);
inline MatrixC &operator= (MatrixI &op);
inline MatrixC &operator= (MatrixF &op);
inline MatrixC &operator+= (unsigned char c);
inline MatrixC &operator+= (int c);
inline MatrixC &operator+= (double c);
inline MatrixC &operator+= (MatrixC &op);
inline MatrixC &operator+= (MatrixI &op);
inline MatrixC &operator+= (MatrixF &op);
inline MatrixC &operator-= (unsigned char c);
inline MatrixC &operator-= (int c);
inline MatrixC &operator-= (double c);
inline MatrixC &operator-= (MatrixC &op);
inline MatrixC &operator-= (MatrixI &op);
inline MatrixC &operator-= (MatrixF &op);
inline MatrixC &operator*= (unsigned char c);
inline MatrixC &operator*= (int c);
inline MatrixC &operator*= (double c);
inline MatrixC &operator*= (MatrixC &op);
inline MatrixC &operator*= (MatrixI &op);
inline MatrixC &operator*= (MatrixF &op);
inline MatrixC &operator/= (unsigned char c);
inline MatrixC &operator/= (int c);
inline MatrixC &operator/= (double c);
inline MatrixC &operator/= (MatrixC &op);
inline MatrixC &operator/= (MatrixI &op);
inline MatrixC &operator/= (MatrixF &op);
inline MatrixC &Multiply (MatrixF &op);
inline MatrixC &Resize (int x, int y);
inline MatrixC &ResizeSafe (int x, int y);
inline MatrixC &InsertRow (int r);
inline MatrixC &InsertCol (int c);
inline MatrixC &Transpose (void);
inline MatrixC &Identity (int order);
inline MatrixC &Basis (Vector3DF &c1, Vector3DF &c2, Vector3DF &c3);
inline MatrixC &GaussJordan (MatrixF &b);
inline int GetX();
inline int GetY();
inline int GetRows(void);
inline int GetCols(void);
inline int GetLength(void);
inline VTYPE *GetData(void);
inline unsigned char *GetDataC (void) {return data;}
inline int *GetDataI (void) {return NULL;}
inline double *GetDataF (void) {return NULL;}
inline double GetF (int r, int c);
};
#undef VNAME
#undef VTYPE
// MatrixI Declaration
#define VNAME I
#define VTYPE int
class MatrixI {
public:
VTYPE *data;
int rows, cols, len;
// Constructors/Destructors
inline MatrixI ();
inline ~MatrixI ();
inline MatrixI (int r, int c);
// Member Functions
inline VTYPE &operator () (int c, int r);
inline MatrixI &operator= (unsigned char c);
inline MatrixI &operator= (int c);
inline MatrixI &operator= (double c);
inline MatrixI &operator= (MatrixC &op);
inline MatrixI &operator= (MatrixI &op);
inline MatrixI &operator= (MatrixF &op);
inline MatrixI &operator+= (unsigned char c);
inline MatrixI &operator+= (int c);
inline MatrixI &operator+= (double c);
inline MatrixI &operator+= (MatrixC &op);
inline MatrixI &operator+= (MatrixI &op);
inline MatrixI &operator+= (MatrixF &op);
inline MatrixI &operator-= (unsigned char c);
inline MatrixI &operator-= (int c);
inline MatrixI &operator-= (double c);
inline MatrixI &operator-= (MatrixC &op);
inline MatrixI &operator-= (MatrixI &op);
inline MatrixI &operator-= (MatrixF &op);
inline MatrixI &operator*= (unsigned char c);
inline MatrixI &operator*= (int c);
inline MatrixI &operator*= (double c);
inline MatrixI &operator*= (MatrixC &op);
inline MatrixI &operator*= (MatrixI &op);
inline MatrixI &operator*= (MatrixF &op);
inline MatrixI &operator/= (unsigned char c);
inline MatrixI &operator/= (int c);
inline MatrixI &operator/= (double c);
inline MatrixI &operator/= (MatrixC &op);
inline MatrixI &operator/= (MatrixI &op);
inline MatrixI &operator/= (MatrixF &op);
inline MatrixI &Multiply (MatrixF &op);
inline MatrixI &Resize (int x, int y);
inline MatrixI &ResizeSafe (int x, int y);
inline MatrixI &InsertRow (int r);
inline MatrixI &InsertCol (int c);
inline MatrixI &Transpose (void);
inline MatrixI &Identity (int order);
inline MatrixI &Basis (Vector3DF &c1, Vector3DF &c2, Vector3DF &c3);
inline MatrixI &GaussJordan (MatrixF &b);
inline int GetX();
inline int GetY();
inline int GetRows(void);
inline int GetCols(void);
inline int GetLength(void);
inline VTYPE *GetData(void);
inline unsigned char *GetDataC (void) {return NULL;}
inline int *GetDataI (void) {return data;}
inline double *GetDataF (void) {return NULL;}
inline double GetF (int r, int c);
};
#undef VNAME
#undef VTYPE
// MatrixF Declaration
#define VNAME F
#define VTYPE double
class MatrixF {
public:
VTYPE *data;
int rows, cols, len;
// Constructors/Destructors
inline MatrixF ();
inline ~MatrixF ();
inline MatrixF (const int r, const int c);
// Member Functions
inline VTYPE GetVal ( int c, int r );
inline VTYPE &operator () (const int c, const int r);
inline MatrixF &operator= (const unsigned char c);
inline MatrixF &operator= (const int c);
inline MatrixF &operator= (const double c);
inline MatrixF &operator= (const MatrixC &op);
inline MatrixF &operator= (const MatrixI &op);
inline MatrixF &operator= (const MatrixF &op);
inline MatrixF &operator+= (const unsigned char c);
inline MatrixF &operator+= (const int c);
inline MatrixF &operator+= (const double c);
inline MatrixF &operator+= (const MatrixC &op);
inline MatrixF &operator+= (const MatrixI &op);
inline MatrixF &operator+= (const MatrixF &op);
inline MatrixF &operator-= (const unsigned char c);
inline MatrixF &operator-= (const int c);
inline MatrixF &operator-= (const double c);
inline MatrixF &operator-= (const MatrixC &op);
inline MatrixF &operator-= (const MatrixI &op);
inline MatrixF &operator-= (const MatrixF &op);
inline MatrixF &operator*= (const unsigned char c);
inline MatrixF &operator*= (const int c);
inline MatrixF &operator*= (const double c);
inline MatrixF &operator*= (const MatrixC &op);
inline MatrixF &operator*= (const MatrixI &op);
inline MatrixF &operator*= (const MatrixF &op);
inline MatrixF &operator/= (const unsigned char c);
inline MatrixF &operator/= (const int c);
inline MatrixF &operator/= (const double c);
inline MatrixF &operator/= (const MatrixC &op);
inline MatrixF &operator/= (const MatrixI &op);
inline MatrixF &operator/= (const MatrixF &op);
inline MatrixF &Multiply4x4 (const MatrixF &op);
inline MatrixF &Multiply (const MatrixF &op);
inline MatrixF &Resize (const int x, const int y);
inline MatrixF &ResizeSafe (const int x, const int y);
inline MatrixF &InsertRow (const int r);
inline MatrixF &InsertCol (const int c);
inline MatrixF &Transpose (void);
inline MatrixF &Identity (const int order);
inline MatrixF &RotateX (const double ang);
inline MatrixF &RotateY (const double ang);
inline MatrixF &RotateZ (const double ang);
inline MatrixF &Ortho (double sx, double sy, double n, double f);
inline MatrixF &Translate (double tx, double ty, double tz);
inline MatrixF &Basis (const Vector3DF &c1, const Vector3DF &c2, const Vector3DF &c3);
inline MatrixF &GaussJordan (MatrixF &b);
inline MatrixF &ConjugateGradient (MatrixF &b);
inline MatrixF &Submatrix ( MatrixF& b, int mx, int my);
inline MatrixF &MatrixVector5 (MatrixF& x, int mrows, MatrixF& b );
inline MatrixF &ConjugateGradient5 (MatrixF &b, int mrows );
inline double Dot ( MatrixF& b );
inline void Print ( char* fname );
inline int GetX();
inline int GetY();
inline int GetRows(void);
inline int GetCols(void);
inline int GetLength(void);
inline VTYPE *GetData(void);
inline void GetRowVec (int r, Vector3DF &v);
inline unsigned char *GetDataC (void) const {return NULL;}
inline int *GetDataI (void) const {return NULL;}
inline double *GetDataF (void) const {return data;}
inline double GetF (const int r, const int c);
};
#undef VNAME
#undef VTYPE
// MatrixF Declaration
#define VNAME F
#define VTYPE float
class Matrix4F {
public:
VTYPE data[16];
// Constructors/Destructors
inline Matrix4F ();
// Member Functions
inline VTYPE &operator () (const int n) { return data[n]; }
inline VTYPE &operator () (const int c, const int r) { return data[ (r<<2)+c ]; }
inline Matrix4F &operator= (const unsigned char c);
inline Matrix4F &operator= (const int c);
inline Matrix4F &operator= (const double c);
inline Matrix4F &operator+= (const unsigned char c);
inline Matrix4F &operator+= (const int c);
inline Matrix4F &operator+= (const double c);
inline Matrix4F &operator-= (const unsigned char c);
inline Matrix4F &operator-= (const int c);
inline Matrix4F &operator-= (const double c);
inline Matrix4F &operator*= (const unsigned char c);
inline Matrix4F &operator*= (const int c);
inline Matrix4F &operator*= (const double c);
inline Matrix4F &operator/= (const unsigned char c);
inline Matrix4F &operator/= (const int c);
inline Matrix4F &operator/= (const double c);
inline Matrix4F &Multiply (const Matrix4F &op);
inline Matrix4F &Transpose (void);
inline Matrix4F &Identity (const int order);
inline Matrix4F &RotateX (const double ang);
inline Matrix4F &RotateY (const double ang);
inline Matrix4F &RotateZ (const double ang);
inline Matrix4F &Ortho (double sx, double sy, double n, double f);
inline Matrix4F &Translate (double tx, double ty, double tz);
inline Matrix4F &Basis (const Vector3DF &c1, const Vector3DF &c2, const Vector3DF &c3);
// Scale-Rotate-Translate (compound matrix)
inline Matrix4F &SRT (const Vector3DF &c1, const Vector3DF &c2, const Vector3DF &c3, const Vector3DF& t, const Vector3DF& s);
inline Matrix4F &SRT (const Vector3DF &c1, const Vector3DF &c2, const Vector3DF &c3, const Vector3DF& t, const float s);
// invTranslate-invRotate-invScale (compound matrix)
inline Matrix4F &InvTRS (const Vector3DF &c1, const Vector3DF &c2, const Vector3DF &c3, const Vector3DF& t, const Vector3DF& s);
inline Matrix4F &InvTRS (const Vector3DF &c1, const Vector3DF &c2, const Vector3DF &c3, const Vector3DF& t, const float s);
inline int GetX() { return 4; }
inline int GetY() { return 4; }
inline int GetRows(void) { return 4; }
inline int GetCols(void) { return 4; }
inline int GetLength(void) { return 16; }
inline VTYPE *GetData(void) { return data; }
inline void GetRowVec (int r, Vector3DF &v);
inline unsigned char *GetDataC (void) const {return NULL;}
inline int *GetDataI (void) const {return NULL;}
inline float *GetDataF (void) const {return (float*) data;}
inline float GetF (const int r, const int c);
};
#undef VNAME
#undef VTYPE
// Matrix Code Definitions (Inlined)
#include "matrix.cci"
#endif
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <memory.h>
#include <math.h>
//*********** NOTE
//
// LOOK AT MovieTrackPoint. IN ORDER FOR VECTORS AND MATRICIES TO BE USED IN OBJECTS
// THAT WILL BE USED IN stl::vectors, THEIR CONSTRUCTORS AND OPERATORS MUST TAKE ONLY
// const PARAMETERS. LOOK AT MatrixF and Vector2DF.. THIS WAS NOT YET DONE WITH
// THE OTHER MATRIX AND VECTOR CLASSES (Vector2DC, Vector2DI, MatrixC, MatrixI, ...)
//
#ifndef MATRIX_DEF
#define MATRIX_DEF
#include "vector.h"
#include "mdebug.h"
//#define MATRIX_INITIALIZE // Initializes vectors
class MatrixC; // Forward Referencing
class MatrixI;
class MatrixF;
class Matrix {
public:
// Member Virtual Functions
virtual Matrix &operator= (unsigned char c)=0;
virtual Matrix &operator= (int c)=0;
virtual Matrix &operator= (double c)=0;
virtual Matrix &operator= (MatrixC &op)=0;
virtual Matrix &operator= (MatrixI &op)=0;
virtual Matrix &operator= (MatrixF &op)=0;
virtual Matrix &operator+= (unsigned char c)=0;
virtual Matrix &operator+= (int c)=0;
virtual Matrix &operator+= (double c)=0;
virtual Matrix &operator+= (MatrixC &op)=0;
virtual Matrix &operator+= (MatrixI &op)=0;
virtual Matrix &operator+= (MatrixF &op)=0;
virtual Matrix &operator-= (unsigned char c)=0;
virtual Matrix &operator-= (int c)=0;
virtual Matrix &operator-= (double c)=0;
virtual Matrix &operator-= (MatrixC &op)=0;
virtual Matrix &operator-= (MatrixI &op)=0;
virtual Matrix &operator-= (MatrixF &op)=0;
virtual Matrix &operator*= (unsigned char c)=0;
virtual Matrix &operator*= (int c)=0;
virtual Matrix &operator*= (double c)=0;
virtual Matrix &operator*= (MatrixC &op)=0;
virtual Matrix &operator*= (MatrixI &op)=0;
virtual Matrix &operator*= (MatrixF &op)=0;
virtual Matrix &operator/= (unsigned char c)=0;
virtual Matrix &operator/= (int c)=0;
virtual Matrix &operator/= (double c)=0;
virtual Matrix &operator/= (MatrixC &op)=0;
virtual Matrix &operator/= (MatrixI &op)=0;
virtual Matrix &operator/= (MatrixF &op)=0;
virtual Matrix &Multiply (MatrixF &op)=0;
virtual Matrix &Resize (int x, int y)=0;
virtual Matrix &ResizeSafe (int x, int y)=0;
virtual Matrix &InsertRow (int r)=0;
virtual Matrix &InsertCol (int c)=0;
virtual Matrix &Transpose (void)=0;
virtual Matrix &Identity (int order)=0;
/*inline Matrix &RotateX (double ang);
inline Matrix &RotateY (double ang);
inline Matrix &RotateZ (double ang); */
virtual Matrix &Basis (Vector3DF &c1, Vector3DF &c2, Vector3DF &c3)=0;
virtual Matrix &GaussJordan (MatrixF &b) { return *this; }
virtual Matrix &ConjugateGradient (MatrixF &b) { return *this; }
virtual int GetRows(void)=0;
virtual int GetCols(void)=0;
virtual int GetLength(void)=0;
virtual unsigned char *GetDataC (void)=0;
virtual int *GetDataI (void)=0;
virtual double *GetDataF (void)=0;
virtual double GetF (int r, int c);
};
// MatrixC Declaration
#define VNAME C
#define VTYPE unsigned char
class MatrixC {
public:
VTYPE *data;
int rows, cols, len;
// Constructors/Destructors
inline MatrixC ();
inline ~MatrixC ();
inline MatrixC (int r, int c);
// Member Functions
inline VTYPE &operator () (int c, int r);
inline MatrixC &operator= (unsigned char c);
inline MatrixC &operator= (int c);
inline MatrixC &operator= (double c);
inline MatrixC &operator= (MatrixC &op);
inline MatrixC &operator= (MatrixI &op);
inline MatrixC &operator= (MatrixF &op);
inline MatrixC &operator+= (unsigned char c);
inline MatrixC &operator+= (int c);
inline MatrixC &operator+= (double c);
inline MatrixC &operator+= (MatrixC &op);
inline MatrixC &operator+= (MatrixI &op);
inline MatrixC &operator+= (MatrixF &op);
inline MatrixC &operator-= (unsigned char c);
inline MatrixC &operator-= (int c);
inline MatrixC &operator-= (double c);
inline MatrixC &operator-= (MatrixC &op);
inline MatrixC &operator-= (MatrixI &op);
inline MatrixC &operator-= (MatrixF &op);
inline MatrixC &operator*= (unsigned char c);
inline MatrixC &operator*= (int c);
inline MatrixC &operator*= (double c);
inline MatrixC &operator*= (MatrixC &op);
inline MatrixC &operator*= (MatrixI &op);
inline MatrixC &operator*= (MatrixF &op);
inline MatrixC &operator/= (unsigned char c);
inline MatrixC &operator/= (int c);
inline MatrixC &operator/= (double c);
inline MatrixC &operator/= (MatrixC &op);
inline MatrixC &operator/= (MatrixI &op);
inline MatrixC &operator/= (MatrixF &op);
inline MatrixC &Multiply (MatrixF &op);
inline MatrixC &Resize (int x, int y);
inline MatrixC &ResizeSafe (int x, int y);
inline MatrixC &InsertRow (int r);
inline MatrixC &InsertCol (int c);
inline MatrixC &Transpose (void);
inline MatrixC &Identity (int order);
inline MatrixC &Basis (Vector3DF &c1, Vector3DF &c2, Vector3DF &c3);
inline MatrixC &GaussJordan (MatrixF &b);
inline int GetX();
inline int GetY();
inline int GetRows(void);
inline int GetCols(void);
inline int GetLength(void);
inline VTYPE *GetData(void);
inline unsigned char *GetDataC (void) {return data;}
inline int *GetDataI (void) {return NULL;}
inline double *GetDataF (void) {return NULL;}
inline double GetF (int r, int c);
};
#undef VNAME
#undef VTYPE
// MatrixI Declaration
#define VNAME I
#define VTYPE int
class MatrixI {
public:
VTYPE *data;
int rows, cols, len;
// Constructors/Destructors
inline MatrixI ();
inline ~MatrixI ();
inline MatrixI (int r, int c);
// Member Functions
inline VTYPE &operator () (int c, int r);
inline MatrixI &operator= (unsigned char c);
inline MatrixI &operator= (int c);
inline MatrixI &operator= (double c);
inline MatrixI &operator= (MatrixC &op);
inline MatrixI &operator= (MatrixI &op);
inline MatrixI &operator= (MatrixF &op);
inline MatrixI &operator+= (unsigned char c);
inline MatrixI &operator+= (int c);
inline MatrixI &operator+= (double c);
inline MatrixI &operator+= (MatrixC &op);
inline MatrixI &operator+= (MatrixI &op);
inline MatrixI &operator+= (MatrixF &op);
inline MatrixI &operator-= (unsigned char c);
inline MatrixI &operator-= (int c);
inline MatrixI &operator-= (double c);
inline MatrixI &operator-= (MatrixC &op);
inline MatrixI &operator-= (MatrixI &op);
inline MatrixI &operator-= (MatrixF &op);
inline MatrixI &operator*= (unsigned char c);
inline MatrixI &operator*= (int c);
inline MatrixI &operator*= (double c);
inline MatrixI &operator*= (MatrixC &op);
inline MatrixI &operator*= (MatrixI &op);
inline MatrixI &operator*= (MatrixF &op);
inline MatrixI &operator/= (unsigned char c);
inline MatrixI &operator/= (int c);
inline MatrixI &operator/= (double c);
inline MatrixI &operator/= (MatrixC &op);
inline MatrixI &operator/= (MatrixI &op);
inline MatrixI &operator/= (MatrixF &op);
inline MatrixI &Multiply (MatrixF &op);
inline MatrixI &Resize (int x, int y);
inline MatrixI &ResizeSafe (int x, int y);
inline MatrixI &InsertRow (int r);
inline MatrixI &InsertCol (int c);
inline MatrixI &Transpose (void);
inline MatrixI &Identity (int order);
inline MatrixI &Basis (Vector3DF &c1, Vector3DF &c2, Vector3DF &c3);
inline MatrixI &GaussJordan (MatrixF &b);
inline int GetX();
inline int GetY();
inline int GetRows(void);
inline int GetCols(void);
inline int GetLength(void);
inline VTYPE *GetData(void);
inline unsigned char *GetDataC (void) {return NULL;}
inline int *GetDataI (void) {return data;}
inline double *GetDataF (void) {return NULL;}
inline double GetF (int r, int c);
};
#undef VNAME
#undef VTYPE
// MatrixF Declaration
#define VNAME F
#define VTYPE double
class MatrixF {
public:
VTYPE *data;
int rows, cols, len;
// Constructors/Destructors
inline MatrixF ();
inline ~MatrixF ();
inline MatrixF (const int r, const int c);
// Member Functions
inline VTYPE GetVal ( int c, int r );
inline VTYPE &operator () (const int c, const int r);
inline MatrixF &operator= (const unsigned char c);
inline MatrixF &operator= (const int c);
inline MatrixF &operator= (const double c);
inline MatrixF &operator= (const MatrixC &op);
inline MatrixF &operator= (const MatrixI &op);
inline MatrixF &operator= (const MatrixF &op);
inline MatrixF &operator+= (const unsigned char c);
inline MatrixF &operator+= (const int c);
inline MatrixF &operator+= (const double c);
inline MatrixF &operator+= (const MatrixC &op);
inline MatrixF &operator+= (const MatrixI &op);
inline MatrixF &operator+= (const MatrixF &op);
inline MatrixF &operator-= (const unsigned char c);
inline MatrixF &operator-= (const int c);
inline MatrixF &operator-= (const double c);
inline MatrixF &operator-= (const MatrixC &op);
inline MatrixF &operator-= (const MatrixI &op);
inline MatrixF &operator-= (const MatrixF &op);
inline MatrixF &operator*= (const unsigned char c);
inline MatrixF &operator*= (const int c);
inline MatrixF &operator*= (const double c);
inline MatrixF &operator*= (const MatrixC &op);
inline MatrixF &operator*= (const MatrixI &op);
inline MatrixF &operator*= (const MatrixF &op);
inline MatrixF &operator/= (const unsigned char c);
inline MatrixF &operator/= (const int c);
inline MatrixF &operator/= (const double c);
inline MatrixF &operator/= (const MatrixC &op);
inline MatrixF &operator/= (const MatrixI &op);
inline MatrixF &operator/= (const MatrixF &op);
inline MatrixF &Multiply4x4 (const MatrixF &op);
inline MatrixF &Multiply (const MatrixF &op);
inline MatrixF &Resize (const int x, const int y);
inline MatrixF &ResizeSafe (const int x, const int y);
inline MatrixF &InsertRow (const int r);
inline MatrixF &InsertCol (const int c);
inline MatrixF &Transpose (void);
inline MatrixF &Identity (const int order);
inline MatrixF &RotateX (const double ang);
inline MatrixF &RotateY (const double ang);
inline MatrixF &RotateZ (const double ang);
inline MatrixF &Ortho (double sx, double sy, double n, double f);
inline MatrixF &Translate (double tx, double ty, double tz);
inline MatrixF &Basis (const Vector3DF &c1, const Vector3DF &c2, const Vector3DF &c3);
inline MatrixF &GaussJordan (MatrixF &b);
inline MatrixF &ConjugateGradient (MatrixF &b);
inline MatrixF &Submatrix ( MatrixF& b, int mx, int my);
inline MatrixF &MatrixVector5 (MatrixF& x, int mrows, MatrixF& b );
inline MatrixF &ConjugateGradient5 (MatrixF &b, int mrows );
inline double Dot ( MatrixF& b );
inline void Print ( char* fname );
inline int GetX();
inline int GetY();
inline int GetRows(void);
inline int GetCols(void);
inline int GetLength(void);
inline VTYPE *GetData(void);
inline void GetRowVec (int r, Vector3DF &v);
inline unsigned char *GetDataC (void) const {return NULL;}
inline int *GetDataI (void) const {return NULL;}
inline double *GetDataF (void) const {return data;}
inline double GetF (const int r, const int c);
};
#undef VNAME
#undef VTYPE
// MatrixF Declaration
#define VNAME F
#define VTYPE float
class Matrix4F {
public:
VTYPE data[16];
// Constructors/Destructors
inline Matrix4F ();
// Member Functions
inline VTYPE &operator () (const int n) { return data[n]; }
inline VTYPE &operator () (const int c, const int r) { return data[ (r<<2)+c ]; }
inline Matrix4F &operator= (const unsigned char c);
inline Matrix4F &operator= (const int c);
inline Matrix4F &operator= (const double c);
inline Matrix4F &operator+= (const unsigned char c);
inline Matrix4F &operator+= (const int c);
inline Matrix4F &operator+= (const double c);
inline Matrix4F &operator-= (const unsigned char c);
inline Matrix4F &operator-= (const int c);
inline Matrix4F &operator-= (const double c);
inline Matrix4F &operator*= (const unsigned char c);
inline Matrix4F &operator*= (const int c);
inline Matrix4F &operator*= (const double c);
inline Matrix4F &operator/= (const unsigned char c);
inline Matrix4F &operator/= (const int c);
inline Matrix4F &operator/= (const double c);
inline Matrix4F &Multiply (const Matrix4F &op);
inline Matrix4F &Transpose (void);
inline Matrix4F &Identity (const int order);
inline Matrix4F &RotateX (const double ang);
inline Matrix4F &RotateY (const double ang);
inline Matrix4F &RotateZ (const double ang);
inline Matrix4F &Ortho (double sx, double sy, double n, double f);
inline Matrix4F &Translate (double tx, double ty, double tz);
inline Matrix4F &Basis (const Vector3DF &c1, const Vector3DF &c2, const Vector3DF &c3);
// Scale-Rotate-Translate (compound matrix)
inline Matrix4F &SRT (const Vector3DF &c1, const Vector3DF &c2, const Vector3DF &c3, const Vector3DF& t, const Vector3DF& s);
inline Matrix4F &SRT (const Vector3DF &c1, const Vector3DF &c2, const Vector3DF &c3, const Vector3DF& t, const float s);
// invTranslate-invRotate-invScale (compound matrix)
inline Matrix4F &InvTRS (const Vector3DF &c1, const Vector3DF &c2, const Vector3DF &c3, const Vector3DF& t, const Vector3DF& s);
inline Matrix4F &InvTRS (const Vector3DF &c1, const Vector3DF &c2, const Vector3DF &c3, const Vector3DF& t, const float s);
inline int GetX() { return 4; }
inline int GetY() { return 4; }
inline int GetRows(void) { return 4; }
inline int GetCols(void) { return 4; }
inline int GetLength(void) { return 16; }
inline VTYPE *GetData(void) { return data; }
inline void GetRowVec (int r, Vector3DF &v);
inline unsigned char *GetDataC (void) const {return NULL;}
inline int *GetDataI (void) const {return NULL;}
inline float *GetDataF (void) const {return (float*) data;}
inline float GetF (const int r, const int c);
};
#undef VNAME
#undef VTYPE
// Matrix Code Definitions (Inlined)
#include "matrix.cci"
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,160 +1,160 @@
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef DEF_MESH
#define DEF_MESH
#include <vector>
#include <gl/glut.h>
#include "geomx.h"
#include "mesh_info.h"
#include "vector.h"
//#include "mfile.h"
//#define MESH_DEBUG
#ifdef MESH_DEBUG
#define VERT_DELTA 10000
#define EDGE_DELTA 20000
#define FACE_DELTA 30000
#else
#define VERT_DELTA 0
#define EDGE_DELTA 0
#define FACE_DELTA 0
#endif
#define PLY_UINT 0
#define PLY_INT 1
#define PLY_FLOAT 2
#define PLY_LIST 3
#define PLY_VERTS 4
#define PLY_FACES 5
struct PlyProperty {
char type;
std::string name;
};
struct PlyElement {
int num;
char type; // 0 = vert, 1 = face
std::vector<PlyProperty> prop_list;
};
class Mesh : public GeomX, public MeshInfo {
public:
Mesh ();
//virtual objType GetType () { return 'mesh'; }
// Distributed functions
//virtual void onUpdate ( objData dat, mint::Event* e );
//void UpdateMesh ();
// Generic functions
void InitStatic ();
void DrawGL ( float* viewmat );
void DrawFaceGL ( float* viewmat );
void Measure ();
Mesh& operator= ( Mesh& op2 );
// Load PLY mesh
void LoadPly ( char* fname, float s );
void AddPlyElement ( char typ, int n );
void AddPlyProperty ( char typ, std::string name );
void LoadPlyVerts ();
void LoadPlyFaces ();
int FindPlyElem ( char typ );
int FindPlyProp ( int elem, std::string name );
// Vertex, Face, Edge functions
xref AddVert (float x, float y, float z ) { return (this->*m_AddVertFunc) (x, y, z); }
xref AddFaceFast (xref v1, xref v2, xref v3 ) { return (this->*m_AddFaceFast3Func) (v1, v2, v3); }
xref AddFaceFast (xref v1, xref v2, xref v3, xref v4 ) { return (this->*m_AddFaceFast4Func) (v1, v2, v3, v4); }
xref (Mesh::*m_AddVertFunc) (float x, float y, float z);
xref (Mesh::*m_AddFaceFast3Func) (xref v1, xref v2, xref v3);
xref (Mesh::*m_AddFaceFast4Func) (xref v1, xref v2, xref v3, xref v4);
int NumVert () { return NumElem ( m_Vbuf ); }
int NumEdge () { return NumElem ( m_Ebuf ); }
int NumFace () { return NumElem ( m_Fbuf ); }
void IncFace ( int n ) { m_CurrF += n; }
void DebugHeap ();
// FVF - Face-Vertex-Face Mesh
void CreateFVF ();
void ClearFVF ();
void SetFuncFVF ();
xref AddVertFVF ( float x, float y, float z );
xref AddFaceFast3FVF ( xref v1, xref v2, xref v3 );
xref AddFaceFast4FVF ( xref v1, xref v2, xref v3, xref v4 );
VertFVF* GetVertFVF ( int n ) { return (VertFVF*) (mBuf[m_Vbuf].data + n*mBuf[m_Vbuf].stride); }
FaceFVF* GetFaceFVF ( int n ) { return (FaceFVF*) (mBuf[m_Fbuf].data + n*mBuf[m_Fbuf].stride); }
void* GetExtraFVF ( VertFVF* v ) { return ((char*) v + miBufSize[(int) FVF][BVert]); }
void ComputeNormalsFVF ();
void SetNormalFVF ( int n, Vector3DF norm );
void SetColorFVF ( int n, DWORD clr );
void SmoothFVF ( int iter );
void DebugFVF ();
void DrawVertsFVF ( float* viewmat, int a, int b );
void DrawFacesFVF ( float* viewmat, int a, int b );
// CM - Connected Mesh
void CreateCM ();
void SetFuncCM ();
xref AddVertCM ( float x, float y, float z );
xref AddFaceFast3CM ( xref v1, xref v2, xref v3 );
xref AddFaceFast4CM ( xref v1, xref v2, xref v3, xref v4 );
xref AddEdgeCM ( xref v1, xref v2 );
xref FindEdgeCM ( xref v1, xref v2 );
VertCM* GetVertCM ( int n ) { return (VertCM*) (mBuf[m_Vbuf].data + n*mBuf[m_Vbuf].stride); }
EdgeCM* GetEdgeCM ( int n ) { return (EdgeCM*) (mBuf[m_Ebuf].data + n*mBuf[m_Ebuf].stride); }
FaceCM* GetFaceCM ( int n ) { return (FaceCM*) (mBuf[m_Fbuf].data + n*mBuf[m_Fbuf].stride); }
void* GetExtraCM ( VertCM* v ) { return ((char*) v + miBufSize[(int) CM][BVert] ); }
void DebugCM ();
void DrawVertsCM ( float* viewmat, int a, int b );
void DrawFacesCM ( float* viewmat, int a, int b );
void DrawEdgesCM ( float* viewmat, int a, int b );
MFormat GetMeshBufs ( char& v, char& e, char& f ) { v = m_Vbuf; e = m_Ebuf; f = m_Fbuf; return m_Mform; }
protected:
MFormat m_Mform; // Mesh format
char m_Vbuf;
char m_Ebuf;
char m_Fbuf;
int m_CurrF;
std::vector< PlyElement* > m_Ply;
//File m_File;
int m_PlyCurrElem;
static bool mbInitStatic;
Vector3DF mT;
};
#endif
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef DEF_MESH
#define DEF_MESH
#include <vector>
#include <gl/glut.h>
#include "geomx.h"
#include "mesh_info.h"
#include "vector.h"
//#include "mfile.h"
//#define MESH_DEBUG
#ifdef MESH_DEBUG
#define VERT_DELTA 10000
#define EDGE_DELTA 20000
#define FACE_DELTA 30000
#else
#define VERT_DELTA 0
#define EDGE_DELTA 0
#define FACE_DELTA 0
#endif
#define PLY_UINT 0
#define PLY_INT 1
#define PLY_FLOAT 2
#define PLY_LIST 3
#define PLY_VERTS 4
#define PLY_FACES 5
struct PlyProperty {
char type;
std::string name;
};
struct PlyElement {
int num;
char type; // 0 = vert, 1 = face
std::vector<PlyProperty> prop_list;
};
class Mesh : public GeomX, public MeshInfo {
public:
Mesh ();
//virtual objType GetType () { return 'mesh'; }
// Distributed functions
//virtual void onUpdate ( objData dat, mint::Event* e );
//void UpdateMesh ();
// Generic functions
void InitStatic ();
void DrawGL ( float* viewmat );
void DrawFaceGL ( float* viewmat );
void Measure ();
Mesh& operator= ( Mesh& op2 );
// Load PLY mesh
void LoadPly ( char* fname, float s );
void AddPlyElement ( char typ, int n );
void AddPlyProperty ( char typ, std::string name );
void LoadPlyVerts ();
void LoadPlyFaces ();
int FindPlyElem ( char typ );
int FindPlyProp ( int elem, std::string name );
// Vertex, Face, Edge functions
xref AddVert (float x, float y, float z ) { return (this->*m_AddVertFunc) (x, y, z); }
xref AddFaceFast (xref v1, xref v2, xref v3 ) { return (this->*m_AddFaceFast3Func) (v1, v2, v3); }
xref AddFaceFast (xref v1, xref v2, xref v3, xref v4 ) { return (this->*m_AddFaceFast4Func) (v1, v2, v3, v4); }
xref (Mesh::*m_AddVertFunc) (float x, float y, float z);
xref (Mesh::*m_AddFaceFast3Func) (xref v1, xref v2, xref v3);
xref (Mesh::*m_AddFaceFast4Func) (xref v1, xref v2, xref v3, xref v4);
int NumVert () { return NumElem ( m_Vbuf ); }
int NumEdge () { return NumElem ( m_Ebuf ); }
int NumFace () { return NumElem ( m_Fbuf ); }
void IncFace ( int n ) { m_CurrF += n; }
void DebugHeap ();
// FVF - Face-Vertex-Face Mesh
void CreateFVF ();
void ClearFVF ();
void SetFuncFVF ();
xref AddVertFVF ( float x, float y, float z );
xref AddFaceFast3FVF ( xref v1, xref v2, xref v3 );
xref AddFaceFast4FVF ( xref v1, xref v2, xref v3, xref v4 );
VertFVF* GetVertFVF ( int n ) { return (VertFVF*) (mBuf[m_Vbuf].data + n*mBuf[m_Vbuf].stride); }
FaceFVF* GetFaceFVF ( int n ) { return (FaceFVF*) (mBuf[m_Fbuf].data + n*mBuf[m_Fbuf].stride); }
void* GetExtraFVF ( VertFVF* v ) { return ((char*) v + miBufSize[(int) FVF][BVert]); }
void ComputeNormalsFVF ();
void SetNormalFVF ( int n, Vector3DF norm );
void SetColorFVF ( int n, DWORD clr );
void SmoothFVF ( int iter );
void DebugFVF ();
void DrawVertsFVF ( float* viewmat, int a, int b );
void DrawFacesFVF ( float* viewmat, int a, int b );
// CM - Connected Mesh
void CreateCM ();
void SetFuncCM ();
xref AddVertCM ( float x, float y, float z );
xref AddFaceFast3CM ( xref v1, xref v2, xref v3 );
xref AddFaceFast4CM ( xref v1, xref v2, xref v3, xref v4 );
xref AddEdgeCM ( xref v1, xref v2 );
xref FindEdgeCM ( xref v1, xref v2 );
VertCM* GetVertCM ( int n ) { return (VertCM*) (mBuf[m_Vbuf].data + n*mBuf[m_Vbuf].stride); }
EdgeCM* GetEdgeCM ( int n ) { return (EdgeCM*) (mBuf[m_Ebuf].data + n*mBuf[m_Ebuf].stride); }
FaceCM* GetFaceCM ( int n ) { return (FaceCM*) (mBuf[m_Fbuf].data + n*mBuf[m_Fbuf].stride); }
void* GetExtraCM ( VertCM* v ) { return ((char*) v + miBufSize[(int) CM][BVert] ); }
void DebugCM ();
void DrawVertsCM ( float* viewmat, int a, int b );
void DrawFacesCM ( float* viewmat, int a, int b );
void DrawEdgesCM ( float* viewmat, int a, int b );
MFormat GetMeshBufs ( char& v, char& e, char& f ) { v = m_Vbuf; e = m_Ebuf; f = m_Fbuf; return m_Mform; }
protected:
MFormat m_Mform; // Mesh format
char m_Vbuf;
char m_Ebuf;
char m_Fbuf;
int m_CurrF;
std::vector< PlyElement* > m_Ply;
//File m_File;
int m_PlyCurrElem;
static bool mbInitStatic;
Vector3DF mT;
};
#endif

View File

@@ -1,97 +1,97 @@
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef DEF_MESH_INFO
#define DEF_MESH_INFO
#include "common_defs.h"
//#include "mint_config.h"
typedef signed int xref;
#define MAX_MFORMAT 10
#define MAX_BFORMAT 5
// CM - Connected mesh
struct FaceCM {
xref e1, e2, e3, e4;
xref v1, v2, v3, v4;
};
struct EdgeCM {
xref v1, v2;
xref f1, f2;
};
struct VertCM {
hList elist;
hList flist;
float x, y, z;
};
// FVF - Face-vertex-face mesh
struct FaceFVF {
xref v1, v2, v3, v4;
};
struct VertFVF {
hList flist;
float x, y, z;
};
// Extra attributes
struct AttrPos {
float x, y, z;
};
struct AttrClr {
DWORD clr;
};
struct AttrNorm {
float nx, ny, nz;
};
struct AttrTex {
float tu, tv;
};
class MeshInfo {
public:
enum MFormat { // Mesh format
UDef = 0,
VV = 1, // Vertex-Vertex
FV = 2, // Face-Vertex
FVF = 3,
WE = 4, // Winged-Edge
CM = 5 // Connected-Mesh
};
enum BFormat { // Buffer format
BVert = 0,
BEdge = 1,
BFace = 2,
};
enum AFormat { // Extra Attribute formats
APos = 0,
AClr = 1,
ANorm = 2,
ATex = 3
};
static int BufSize ( MFormat m, BFormat b ) { return miBufSize[(int) m][(int) b]; }
static int miBufSize [MAX_MFORMAT][MAX_BFORMAT];
};
#endif
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef DEF_MESH_INFO
#define DEF_MESH_INFO
#include "common_defs.h"
//#include "mint_config.h"
typedef signed int xref;
#define MAX_MFORMAT 10
#define MAX_BFORMAT 5
// CM - Connected mesh
struct FaceCM {
xref e1, e2, e3, e4;
xref v1, v2, v3, v4;
};
struct EdgeCM {
xref v1, v2;
xref f1, f2;
};
struct VertCM {
hList elist;
hList flist;
float x, y, z;
};
// FVF - Face-vertex-face mesh
struct FaceFVF {
xref v1, v2, v3, v4;
};
struct VertFVF {
hList flist;
float x, y, z;
};
// Extra attributes
struct AttrPos {
float x, y, z;
};
struct AttrClr {
DWORD clr;
};
struct AttrNorm {
float nx, ny, nz;
};
struct AttrTex {
float tu, tv;
};
class MeshInfo {
public:
enum MFormat { // Mesh format
UDef = 0,
VV = 1, // Vertex-Vertex
FV = 2, // Face-Vertex
FVF = 3,
WE = 4, // Winged-Edge
CM = 5 // Connected-Mesh
};
enum BFormat { // Buffer format
BVert = 0,
BEdge = 1,
BFace = 2,
};
enum AFormat { // Extra Attribute formats
APos = 0,
AClr = 1,
ANorm = 2,
ATex = 3
};
static int BufSize ( MFormat m, BFormat b ) { return miBufSize[(int) m][(int) b]; }
static int miBufSize [MAX_MFORMAT][MAX_BFORMAT];
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,165 +1,165 @@
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2008. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef DEF_POINT_SET
#define DEF_POINT_SET
#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "common_defs.h"
#include "geomx.h"
#include "vector.h"
typedef signed int xref;
#define MAX_NEIGHBOR 80
#define MAX_PARAM 21
// Scalar params
#define PNT_DRAWMODE 0
#define PNT_SPHERE 0
#define PNT_POINT 1
#define PNT_DRAWSIZE 1
#define POINT_GRAV 2
#define PLANE_GRAV 3
// Vector params
#define EMIT_POS 0
#define EMIT_ANG 1
#define EMIT_DANG 2
#define EMIT_SPREAD 3
#define EMIT_RATE 4
#define POINT_GRAV_POS 5
#define PLANE_GRAV_DIR 6
#define BPOINT 0
#define BPARTICLE 1
struct Point {
Vector3DF pos;
DWORD clr;
int next;
};
struct Particle {
Vector3DF pos;
DWORD clr;
int next;
Vector3DF vel;
Vector3DF vel_eval;
unsigned short age;
};
class PointSet : public GeomX {
public:
PointSet ();
// Point Sets
virtual void Initialize ( int mode, int max );
virtual void Draw ( float* view_mat, float rad );
virtual void Reset ();
virtual int AddPoint ();
virtual int AddPointReuse ();
Point* GetPoint ( int n ) { return (Point*) GetElem(0, n); }
int NumPoints () { return NumElem(0); }
// Metablobs
virtual float GetValue ( float x, float y, float z );
virtual Vector3DF GetGradient ( float x, float y, float z );
// virtual float GetValue ( float x, float y, float z, Vector3DF& dir );
virtual DWORD GetColor ( float x, float y, float z );
// Particle system
virtual void Run ();
virtual void Advance ();
virtual void Emit ( float spacing );
// Misc
virtual void AddVolume ( Vector3DF min, Vector3DF max, float spacing );
// Parameters
void SetParam (int p, float v ) { m_Param[p] = v; }
void SetParam (int p, int v ) { m_Param[p] = (float) v; }
float GetParam ( int p ) { return (float) m_Param[p]; }
Vector3DF GetVec ( int p ) { return m_Vec[p]; }
void SetVec ( int p, Vector3DF v ) { m_Vec[p] = v; }
void Toggle ( int p ) { m_Toggle[p] = !m_Toggle[p]; }
bool GetToggle ( int p ) { return m_Toggle[p]; }
float GetDT() { return (float) m_DT; }
// Spatial Subdivision
void Grid_Setup ( Vector3DF min, Vector3DF max, float sim_scale, float cell_size, float border );
void Grid_Create ();
void Grid_InsertParticles ();
void Grid_Draw ( float* view_mat );
void Grid_FindCells ( Vector3DF p, float radius );
int Grid_FindCell ( Vector3DF p );
Vector3DF GetGridRes () { return m_GridRes; }
Vector3DF GetGridMin () { return m_GridMin; }
Vector3DF GetGridMax () { return m_GridMax; }
Vector3DF GetGridDelta () { return m_GridDelta; }
int GetGridCell ( int x, int y, int z );
Point* firstGridParticle ( int gc, int& p );
Point* nextGridParticle ( int& p );
unsigned short* getNeighborTable ( int n, int& cnt );
protected:
int m_Frame;
// Parameters
double m_Param [ MAX_PARAM ]; // see defines above
Vector3DF m_Vec [ MAX_PARAM ];
bool m_Toggle [ MAX_PARAM ];
// Particle System
double m_DT;
double m_Time;
// Spatial Grid
std::vector< int > m_Grid;
std::vector< int > m_GridCnt;
int m_GridTotal; // total # cells
Vector3DF m_GridMin; // volume of grid (may not match domain volume exactly)
Vector3DF m_GridMax;
Vector3DF m_GridRes; // resolution in each axis
Vector3DF m_GridSize; // physical size in each axis
Vector3DF m_GridDelta;
float m_GridCellsize;
int m_GridCell[27];
// Neighbor Table
unsigned short m_NC[65536]; // neighbor table (600k)
unsigned short m_Neighbor[65536][MAX_NEIGHBOR];
float m_NDist[65536][MAX_NEIGHBOR];
static int m_pcurr;
};
#endif
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2008. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef DEF_POINT_SET
#define DEF_POINT_SET
#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "common_defs.h"
#include "geomx.h"
#include "vector.h"
typedef signed int xref;
#define MAX_NEIGHBOR 80
#define MAX_PARAM 21
// Scalar params
#define PNT_DRAWMODE 0
#define PNT_SPHERE 0
#define PNT_POINT 1
#define PNT_DRAWSIZE 1
#define POINT_GRAV 2
#define PLANE_GRAV 3
// Vector params
#define EMIT_POS 0
#define EMIT_ANG 1
#define EMIT_DANG 2
#define EMIT_SPREAD 3
#define EMIT_RATE 4
#define POINT_GRAV_POS 5
#define PLANE_GRAV_DIR 6
#define BPOINT 0
#define BPARTICLE 1
struct Point {
Vector3DF pos;
DWORD clr;
int next;
};
struct Particle {
Vector3DF pos;
DWORD clr;
int next;
Vector3DF vel;
Vector3DF vel_eval;
unsigned short age;
};
class PointSet : public GeomX {
public:
PointSet ();
// Point Sets
virtual void Initialize ( int mode, int max );
virtual void Draw ( float* view_mat, float rad );
virtual void Reset ();
virtual int AddPoint ();
virtual int AddPointReuse ();
Point* GetPoint ( int n ) { return (Point*) GetElem(0, n); }
int NumPoints () { return NumElem(0); }
// Metablobs
virtual float GetValue ( float x, float y, float z );
virtual Vector3DF GetGradient ( float x, float y, float z );
// virtual float GetValue ( float x, float y, float z, Vector3DF& dir );
virtual DWORD GetColor ( float x, float y, float z );
// Particle system
virtual void Run ();
virtual void Advance ();
virtual void Emit ( float spacing );
// Misc
virtual void AddVolume ( Vector3DF min, Vector3DF max, float spacing );
// Parameters
void SetParam (int p, float v ) { m_Param[p] = v; }
void SetParam (int p, int v ) { m_Param[p] = (float) v; }
float GetParam ( int p ) { return (float) m_Param[p]; }
Vector3DF GetVec ( int p ) { return m_Vec[p]; }
void SetVec ( int p, Vector3DF v ) { m_Vec[p] = v; }
void Toggle ( int p ) { m_Toggle[p] = !m_Toggle[p]; }
bool GetToggle ( int p ) { return m_Toggle[p]; }
float GetDT() { return (float) m_DT; }
// Spatial Subdivision
void Grid_Setup ( Vector3DF min, Vector3DF max, float sim_scale, float cell_size, float border );
void Grid_Create ();
void Grid_InsertParticles ();
void Grid_Draw ( float* view_mat );
void Grid_FindCells ( Vector3DF p, float radius );
int Grid_FindCell ( Vector3DF p );
Vector3DF GetGridRes () { return m_GridRes; }
Vector3DF GetGridMin () { return m_GridMin; }
Vector3DF GetGridMax () { return m_GridMax; }
Vector3DF GetGridDelta () { return m_GridDelta; }
int GetGridCell ( int x, int y, int z );
Point* firstGridParticle ( int gc, int& p );
Point* nextGridParticle ( int& p );
unsigned short* getNeighborTable ( int n, int& cnt );
protected:
int m_Frame;
// Parameters
double m_Param [ MAX_PARAM ]; // see defines above
Vector3DF m_Vec [ MAX_PARAM ];
bool m_Toggle [ MAX_PARAM ];
// Particle System
double m_DT;
double m_Time;
// Spatial Grid
std::vector< int > m_Grid;
std::vector< int > m_GridCnt;
int m_GridTotal; // total # cells
Vector3DF m_GridMin; // volume of grid (may not match domain volume exactly)
Vector3DF m_GridMax;
Vector3DF m_GridRes; // resolution in each axis
Vector3DF m_GridSize; // physical size in each axis
Vector3DF m_GridDelta;
float m_GridCellsize;
int m_GridCell[27];
// Neighbor Table
unsigned short m_NC[65536]; // neighbor table (600k)
unsigned short m_Neighbor[65536][MAX_NEIGHBOR];
float m_NDist[65536][MAX_NEIGHBOR];
static int m_pcurr;
};
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,70 +1,70 @@
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "vector.h"
#include "matrix.h"
Vector3DF &Vector3DF::operator*= (const MatrixF &op)
{
double *m = op.GetDataF ();
double xa, ya, za;
xa = x * (*m++); ya = x * (*m++); za = x * (*m++); m++;
xa += y * (*m++); ya += y * (*m++); za += y * (*m++); m++;
xa += z * (*m++); ya += z * (*m++); za += z * (*m++); m++;
xa += (*m++); ya += (*m++); za += (*m++);
x = (float) xa; y = (float) ya; z = (float) za;
return *this;
}
Vector3DF &Vector3DF::operator*= (const Matrix4F &op)
{
float xa, ya, za;
xa = x * op.data[0] + y * op.data[4] + z * op.data[8] + op.data[12];
ya = x * op.data[1] + y * op.data[5] + z * op.data[9] + op.data[13];
za = x * op.data[2] + y * op.data[6] + z * op.data[10] + op.data[14];
x = xa; y = ya; z = za;
return *this;
}
Vector4DF &Vector4DF::operator*= (const MatrixF &op)
{
double *m = op.GetDataF ();
double xa, ya, za, wa;
xa = x * (*m++); ya = x * (*m++); za = x * (*m++); wa = x * (*m++);
xa += y * (*m++); ya += y * (*m++); za += y * (*m++); wa += y * (*m++);
xa += z * (*m++); ya += z * (*m++); za += z * (*m++); wa += z * (*m++);
xa += w * (*m++); ya += w * (*m++); za += w * (*m++); wa += w * (*m++);
x = xa; y = ya; z = za; w = wa;
return *this;
}
Vector4DF &Vector4DF::operator*= (const Matrix4F &op)
{
double xa, ya, za, wa;
xa = x * op.data[0] + y * op.data[4] + z * op.data[8] + w * op.data[12];
ya = x * op.data[1] + y * op.data[5] + z * op.data[9] + w * op.data[13];
za = x * op.data[2] + y * op.data[6] + z * op.data[10] + w * op.data[14];
wa = x * op.data[3] + y * op.data[7] + z * op.data[11] + w * op.data[15];
x = xa; y = ya; z = za; w = wa;
return *this;
}
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "vector.h"
#include "matrix.h"
Vector3DF &Vector3DF::operator*= (const MatrixF &op)
{
double *m = op.GetDataF ();
double xa, ya, za;
xa = x * (*m++); ya = x * (*m++); za = x * (*m++); m++;
xa += y * (*m++); ya += y * (*m++); za += y * (*m++); m++;
xa += z * (*m++); ya += z * (*m++); za += z * (*m++); m++;
xa += (*m++); ya += (*m++); za += (*m++);
x = (float) xa; y = (float) ya; z = (float) za;
return *this;
}
Vector3DF &Vector3DF::operator*= (const Matrix4F &op)
{
float xa, ya, za;
xa = x * op.data[0] + y * op.data[4] + z * op.data[8] + op.data[12];
ya = x * op.data[1] + y * op.data[5] + z * op.data[9] + op.data[13];
za = x * op.data[2] + y * op.data[6] + z * op.data[10] + op.data[14];
x = xa; y = ya; z = za;
return *this;
}
Vector4DF &Vector4DF::operator*= (const MatrixF &op)
{
double *m = op.GetDataF ();
double xa, ya, za, wa;
xa = x * (*m++); ya = x * (*m++); za = x * (*m++); wa = x * (*m++);
xa += y * (*m++); ya += y * (*m++); za += y * (*m++); wa += y * (*m++);
xa += z * (*m++); ya += z * (*m++); za += z * (*m++); wa += z * (*m++);
xa += w * (*m++); ya += w * (*m++); za += w * (*m++); wa += w * (*m++);
x = xa; y = ya; z = za; w = wa;
return *this;
}
Vector4DF &Vector4DF::operator*= (const Matrix4F &op)
{
double xa, ya, za, wa;
xa = x * op.data[0] + y * op.data[4] + z * op.data[8] + w * op.data[12];
ya = x * op.data[1] + y * op.data[5] + z * op.data[9] + w * op.data[13];
za = x * op.data[2] + y * op.data[6] + z * op.data[10] + w * op.data[14];
wa = x * op.data[3] + y * op.data[7] + z * op.data[11] + w * op.data[15];
x = xa; y = ya; z = za; w = wa;
return *this;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,306 +1,306 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="fluids"
ProjectGUID="{F9F0795D-4C39-41F4-9381-25C616D69FB2}"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="common;fluids;marching;sphere_scan;marching_tris"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="glee_2008d.lib"
OutputFile="$(OutDir)/fluids_debug.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;C:\Program Files\NVIDIA Corporation\Cg\lib&quot;"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(OutDir)/cgdemo.pdb"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="3"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="fluids;common;marching;sphere_scan;marching_tris;&quot;$(CUDA_INC_PATH)&quot;;../../Glut"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/fluids.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="../../Glut"
IgnoreDefaultLibraryNames="libcmtd.lib"
GenerateDebugInformation="false"
SubSystem="1"
OptimizeReferences="0"
EnableCOMDATFolding="0"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="fluids"
>
<File
RelativePath=".\fluids\fluid.cpp"
>
</File>
<File
RelativePath=".\fluids\fluid.h"
>
</File>
<File
RelativePath=".\fluids\fluid_system.cpp"
>
</File>
<File
RelativePath=".\fluids\fluid_system.h"
>
</File>
</Filter>
<Filter
Name="common"
>
<File
RelativePath=".\common\common_defs.h"
>
</File>
<File
RelativePath=".\common\geomx.cpp"
>
</File>
<File
RelativePath=".\common\geomx.h"
>
</File>
<File
RelativePath=".\common\gl_helper.cpp"
>
</File>
<File
RelativePath=".\common\gl_helper.h"
>
</File>
<File
RelativePath=".\common\image.cpp"
>
</File>
<File
RelativePath=".\common\image.h"
>
</File>
<File
RelativePath=".\common\matrix-inline.h"
>
</File>
<File
RelativePath=".\common\matrix.cci"
>
</File>
<File
RelativePath=".\common\matrix.cpp"
>
</File>
<File
RelativePath=".\common\matrix.h"
>
</File>
<File
RelativePath=".\common\mdebug.cpp"
>
</File>
<File
RelativePath=".\common\mdebug.h"
>
</File>
<File
RelativePath=".\common\mtime.cpp"
>
</File>
<File
RelativePath=".\common\mtime.h"
>
</File>
<File
RelativePath=".\common\point_set.cpp"
>
</File>
<File
RelativePath=".\common\point_set.h"
>
</File>
<File
RelativePath=".\common\vector-inline.h"
>
</File>
<File
RelativePath=".\common\vector.cci"
>
</File>
<File
RelativePath=".\common\vector.cpp"
>
</File>
<File
RelativePath=".\common\vector.h"
>
</File>
</Filter>
<File
RelativePath=".\common\GLee.c"
>
</File>
<File
RelativePath=".\main.cpp"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="fluids"
ProjectGUID="{F9F0795D-4C39-41F4-9381-25C616D69FB2}"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="common;fluids;marching;sphere_scan;marching_tris"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="glee_2008d.lib"
OutputFile="$(OutDir)/fluids_debug.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;C:\Program Files\NVIDIA Corporation\Cg\lib&quot;"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(OutDir)/cgdemo.pdb"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="3"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="fluids;common;marching;sphere_scan;marching_tris;&quot;$(CUDA_INC_PATH)&quot;;../../Glut"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/fluids.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="../../Glut"
IgnoreDefaultLibraryNames="libcmtd.lib"
GenerateDebugInformation="false"
SubSystem="1"
OptimizeReferences="0"
EnableCOMDATFolding="0"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="fluids"
>
<File
RelativePath=".\fluids\fluid.cpp"
>
</File>
<File
RelativePath=".\fluids\fluid.h"
>
</File>
<File
RelativePath=".\fluids\fluid_system.cpp"
>
</File>
<File
RelativePath=".\fluids\fluid_system.h"
>
</File>
</Filter>
<Filter
Name="common"
>
<File
RelativePath=".\common\common_defs.h"
>
</File>
<File
RelativePath=".\common\geomx.cpp"
>
</File>
<File
RelativePath=".\common\geomx.h"
>
</File>
<File
RelativePath=".\common\gl_helper.cpp"
>
</File>
<File
RelativePath=".\common\gl_helper.h"
>
</File>
<File
RelativePath=".\common\image.cpp"
>
</File>
<File
RelativePath=".\common\image.h"
>
</File>
<File
RelativePath=".\common\matrix-inline.h"
>
</File>
<File
RelativePath=".\common\matrix.cci"
>
</File>
<File
RelativePath=".\common\matrix.cpp"
>
</File>
<File
RelativePath=".\common\matrix.h"
>
</File>
<File
RelativePath=".\common\mdebug.cpp"
>
</File>
<File
RelativePath=".\common\mdebug.h"
>
</File>
<File
RelativePath=".\common\mtime.cpp"
>
</File>
<File
RelativePath=".\common\mtime.h"
>
</File>
<File
RelativePath=".\common\point_set.cpp"
>
</File>
<File
RelativePath=".\common\point_set.h"
>
</File>
<File
RelativePath=".\common\vector-inline.h"
>
</File>
<File
RelativePath=".\common\vector.cci"
>
</File>
<File
RelativePath=".\common\vector.cpp"
>
</File>
<File
RelativePath=".\common\vector.h"
>
</File>
</Filter>
<File
RelativePath=".\common\GLee.c"
>
</File>
<File
RelativePath=".\main.cpp"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -1,44 +1,44 @@
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2008. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef DEF_FLUID
#define DEF_FLUID
#include "vector.h"
#include "common_defs.h"
struct Fluid {
public:
Vector3DF pos; // Basic particle (must match Particle class)
DWORD clr;
int next;
Vector3DF vel;
Vector3DF vel_eval;
unsigned short age;
float pressure; // Smoothed Particle Hydrodynamics
float density;
Vector3DF sph_force;
};
#endif /*PARTICLE_H_*/
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2008. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef DEF_FLUID
#define DEF_FLUID
#include "vector.h"
#include "common_defs.h"
struct Fluid {
public:
Vector3DF pos; // Basic particle (must match Particle class)
DWORD clr;
int next;
Vector3DF vel;
Vector3DF vel_eval;
unsigned short age;
float pressure; // Smoothed Particle Hydrodynamics
float density;
Vector3DF sph_force;
};
#endif /*PARTICLE_H_*/

File diff suppressed because it is too large Load Diff

View File

@@ -1,71 +1,71 @@
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include <cutil.h>
#include <cstdlib>
#include <cstdio>
#include <string.h>
#if defined(__APPLE__) || defined(MACOSX)
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <cuda_gl_interop.h>
#include "fluid_system_kern.cu"
extern "C"
{
// Compute number of blocks to create
int iDivUp (int a, int b) {
return (a % b != 0) ? (a / b + 1) : (a / b);
}
void computeNumBlocks (int numPnts, int minThreads, int &numBlocks, int &numThreads)
{
numThreads = min( minThreads, numPnts );
numBlocks = iDivUp ( numPnts, numThreads );
}
void Grid_InsertParticlesCUDA ( uchar* data, uint stride, uint numPoints )
{
int numThreads, numBlocks;
computeNumBlocks (numPoints, 256, numBlocks, numThreads);
// transfer point data to device
char* pntData;
size = numPoints * stride;
cudaMalloc( (void**) &pntData, size);
cudaMemcpy( pntData, data, size, cudaMemcpyHostToDevice);
// execute the kernel
insertParticles<<< numBlocks, numThreads >>> ( pntData, stride );
// transfer data back to host
cudaMemcpy( data, pntData, cudaMemcpyDeviceToHost);
// check if kernel invocation generated an error
CUT_CHECK_ERROR("Kernel execution failed");
CUDA_SAFE_CALL(cudaGLUnmapBufferObject(vboPos));
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include <cutil.h>
#include <cstdlib>
#include <cstdio>
#include <string.h>
#if defined(__APPLE__) || defined(MACOSX)
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <cuda_gl_interop.h>
#include "fluid_system_kern.cu"
extern "C"
{
// Compute number of blocks to create
int iDivUp (int a, int b) {
return (a % b != 0) ? (a / b + 1) : (a / b);
}
void computeNumBlocks (int numPnts, int minThreads, int &numBlocks, int &numThreads)
{
numThreads = min( minThreads, numPnts );
numBlocks = iDivUp ( numPnts, numThreads );
}
void Grid_InsertParticlesCUDA ( uchar* data, uint stride, uint numPoints )
{
int numThreads, numBlocks;
computeNumBlocks (numPoints, 256, numBlocks, numThreads);
// transfer point data to device
char* pntData;
size = numPoints * stride;
cudaMalloc( (void**) &pntData, size);
cudaMemcpy( pntData, data, size, cudaMemcpyHostToDevice);
// execute the kernel
insertParticles<<< numBlocks, numThreads >>> ( pntData, stride );
// transfer data back to host
cudaMemcpy( data, pntData, cudaMemcpyDeviceToHost);
// check if kernel invocation generated an error
CUT_CHECK_ERROR("Kernel execution failed");
CUDA_SAFE_CALL(cudaGLUnmapBufferObject(vboPos));
}

View File

@@ -1,106 +1,106 @@
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2008. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef DEF_FLUID_SYS
#define DEF_FLUID_SYS
#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "point_set.h"
#include "fluid.h"
// Scalar params
#define SPH_SIMSIZE 4
#define SPH_SIMSCALE 5
#define SPH_VISC 6
#define SPH_RESTDENSITY 7
#define SPH_PMASS 8
#define SPH_PRADIUS 9
#define SPH_PDIST 10
#define SPH_SMOOTHRADIUS 11
#define SPH_INTSTIFF 12
#define SPH_EXTSTIFF 13
#define SPH_EXTDAMP 14
#define SPH_LIMIT 15
#define BOUND_ZMIN_SLOPE 16
#define FORCE_XMAX_SIN 17
#define FORCE_XMIN_SIN 18
#define MAX_FRAC 19
#define CLR_MODE 20
// Vector params
#define SPH_VOLMIN 7
#define SPH_VOLMAX 8
#define SPH_INITMIN 9
#define SPH_INITMAX 10
// Toggles
#define SPH_GRID 0
#define SPH_DEBUG 1
#define WRAP_X 2
#define WALL_BARRIER 3
#define LEVY_BARRIER 4
#define DRAIN_BARRIER 5
#define USE_CUDA 6
#define MAX_PARAM 21
#define BFLUID 2
class FluidSystem : public PointSet {
public:
FluidSystem ();
// Basic Particle System
virtual void Initialize ( int mode, int nmax );
virtual void Reset ( int nmax );
virtual void Run ();
virtual void Advance ();
virtual int AddPoint ();
virtual int AddPointReuse ();
Fluid* AddFluid () { return (Fluid*) GetElem(0, AddPointReuse()); }
Fluid* GetFluid (int n) { return (Fluid*) GetElem(0, n); }
// Smoothed Particle Hydrodynamics
void SPH_Setup ();
void SPH_CreateExample ( int n, int nmax );
void SPH_DrawDomain ();
void SPH_ComputeKernels ();
void SPH_ComputePressureSlow (); // O(n^2)
void SPH_ComputePressureGrid (); // O(kn) - spatial grid
void SPH_ComputeForceSlow (); // O(n^2)
void SPH_ComputeForceGrid (); // O(kn) - spatial grid
void SPH_ComputeForceGridNC (); // O(cn) - neighbor table
private:
// Smoothed Particle Hydrodynamics
double m_R2, m_Poly6Kern, m_LapKern, m_SpikyKern; // Kernel functions
};
#endif
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2008. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef DEF_FLUID_SYS
#define DEF_FLUID_SYS
#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "point_set.h"
#include "fluid.h"
// Scalar params
#define SPH_SIMSIZE 4
#define SPH_SIMSCALE 5
#define SPH_VISC 6
#define SPH_RESTDENSITY 7
#define SPH_PMASS 8
#define SPH_PRADIUS 9
#define SPH_PDIST 10
#define SPH_SMOOTHRADIUS 11
#define SPH_INTSTIFF 12
#define SPH_EXTSTIFF 13
#define SPH_EXTDAMP 14
#define SPH_LIMIT 15
#define BOUND_ZMIN_SLOPE 16
#define FORCE_XMAX_SIN 17
#define FORCE_XMIN_SIN 18
#define MAX_FRAC 19
#define CLR_MODE 20
// Vector params
#define SPH_VOLMIN 7
#define SPH_VOLMAX 8
#define SPH_INITMIN 9
#define SPH_INITMAX 10
// Toggles
#define SPH_GRID 0
#define SPH_DEBUG 1
#define WRAP_X 2
#define WALL_BARRIER 3
#define LEVY_BARRIER 4
#define DRAIN_BARRIER 5
#define USE_CUDA 6
#define MAX_PARAM 21
#define BFLUID 2
class FluidSystem : public PointSet {
public:
FluidSystem ();
// Basic Particle System
virtual void Initialize ( int mode, int nmax );
virtual void Reset ( int nmax );
virtual void Run ();
virtual void Advance ();
virtual int AddPoint ();
virtual int AddPointReuse ();
Fluid* AddFluid () { return (Fluid*) GetElem(0, AddPointReuse()); }
Fluid* GetFluid (int n) { return (Fluid*) GetElem(0, n); }
// Smoothed Particle Hydrodynamics
void SPH_Setup ();
void SPH_CreateExample ( int n, int nmax );
void SPH_DrawDomain ();
void SPH_ComputeKernels ();
void SPH_ComputePressureSlow (); // O(n^2)
void SPH_ComputePressureGrid (); // O(kn) - spatial grid
void SPH_ComputeForceSlow (); // O(n^2)
void SPH_ComputeForceGrid (); // O(kn) - spatial grid
void SPH_ComputeForceGridNC (); // O(cn) - neighbor table
private:
// Smoothed Particle Hydrodynamics
double m_R2, m_Poly6Kern, m_LapKern, m_SpikyKern; // Kernel functions
};
#endif

View File

@@ -1,250 +1,250 @@
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2008. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
//#include "C:\CUDA\common\inc\cutil.h" // cutil32.lib
#include <string.h>
#include "../CUDA/btCudaDefines.h"
#if defined(__APPLE__) || defined(MACOSX)
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <cuda_gl_interop.h>
#include "radixsort.cu"
#include "fluid_system_kern.cu" // build kernel
FluidParams fcuda;
__device__ char* bufPnts; // point data (array of Fluid structs)
__device__ char* bufPntSort; // point data (array of Fluid structs)
__device__ uint* bufHash[2]; // point grid hash
__device__ int* bufGrid;
extern "C"
{
// Initialize CUDA
void cudaInit(int argc, char **argv)
{
//CUT_DEVICE_INIT(argc, argv);
cudaDeviceProp p;
cudaGetDeviceProperties ( &p, 0);
printf ( "-- CUDA --\n" );
printf ( "Name: %s\n", p.name );
printf ( "Revision: %d.%d\n", p.major, p.minor );
printf ( "Global Mem: %d\n", p.totalGlobalMem );
printf ( "Shared/Blk: %d\n", p.sharedMemPerBlock );
printf ( "Regs/Blk: %d\n", p.regsPerBlock );
printf ( "Warp Size: %d\n", p.warpSize );
printf ( "Mem Pitch: %d\n", p.memPitch );
printf ( "Thrds/Blk: %d\n", p.maxThreadsPerBlock );
printf ( "Const Mem: %d\n", p.totalConstMem );
printf ( "Clock Rate: %d\n", p.clockRate );
BT_GPU_SAFE_CALL ( cudaMalloc ( (void**) &bufPnts, 10 ) );
BT_GPU_SAFE_CALL ( cudaMalloc ( (void**) &bufPntSort, 10 ) );
BT_GPU_SAFE_CALL ( cudaMalloc ( (void**) &bufHash, 10 ) );
BT_GPU_SAFE_CALL ( cudaMalloc ( (void**) &bufGrid, 10 ) );
};
// Compute number of blocks to create
int iDivUp (int a, int b) {
return (a % b != 0) ? (a / b + 1) : (a / b);
}
void computeNumBlocks (int numPnts, int maxThreads, int &numBlocks, int &numThreads)
{
numThreads = min( maxThreads, numPnts );
numBlocks = iDivUp ( numPnts, numThreads );
}
void FluidClearCUDA ()
{
BT_GPU_SAFE_CALL ( cudaFree ( bufPnts ) );
BT_GPU_SAFE_CALL ( cudaFree ( bufPntSort ) );
BT_GPU_SAFE_CALL ( cudaFree ( bufHash[0] ) );
BT_GPU_SAFE_CALL ( cudaFree ( bufHash[1] ) );
BT_GPU_SAFE_CALL ( cudaFree ( bufGrid ) );
}
void FluidSetupCUDA ( int num, int stride, float3 min, float3 max, float3 res, float3 size, int chk )
{
fcuda.min = make_float3(min.x, min.y, min.z);
fcuda.max = make_float3(max.x, max.y, max.z);
fcuda.res = make_float3(res.x, res.y, res.z);
fcuda.size = make_float3(size.x, size.y, size.z);
fcuda.pnts = num;
fcuda.delta.x = res.x / size.x;
fcuda.delta.y = res.y / size.y;
fcuda.delta.z = res.z / size.z;
fcuda.cells = res.x*res.y*res.z;
fcuda.chk = chk;
computeNumBlocks ( fcuda.pnts, 256, fcuda.numBlocks, fcuda.numThreads); // particles
computeNumBlocks ( fcuda.cells, 256, fcuda.gridBlocks, fcuda.gridThreads); // grid cell
fcuda.szPnts = (fcuda.numBlocks * fcuda.numThreads) * stride;
fcuda.szHash = (fcuda.numBlocks * fcuda.numThreads) * sizeof(uint2); // <cell, particle> pairs
fcuda.szGrid = (fcuda.gridBlocks * fcuda.gridThreads) * sizeof(uint);
fcuda.stride = stride;
printf ( "pnts: %d, t:%dx%d=%d, bufPnts:%d, bufHash:%d\n", fcuda.pnts, fcuda.numBlocks, fcuda.numThreads, fcuda.numBlocks*fcuda.numThreads, fcuda.szPnts, fcuda.szHash );
printf ( "grds: %d, t:%dx%d=%d, bufGrid:%d, Res: %dx%dx%d\n", fcuda.cells, fcuda.gridBlocks, fcuda.gridThreads, fcuda.gridBlocks*fcuda.gridThreads, fcuda.szGrid, (int) fcuda.res.x, (int) fcuda.res.y, (int) fcuda.res.z );
BT_GPU_SAFE_CALL ( cudaMalloc ( (void**) &bufPnts, fcuda.szPnts ) );
BT_GPU_SAFE_CALL ( cudaMalloc ( (void**) &bufPntSort, fcuda.szPnts ) );
BT_GPU_SAFE_CALL ( cudaMalloc ( (void**) &bufHash[0], fcuda.szHash ) );
BT_GPU_SAFE_CALL ( cudaMalloc ( (void**) &bufHash[1], fcuda.szHash ) );
BT_GPU_SAFE_CALL ( cudaMalloc ( (void**) &bufGrid, fcuda.szGrid ) );
printf ( "POINTERS\n");
printf ( "bufPnts: %p\n", bufPnts );
printf ( "bufPntSort: %p\n", bufPntSort );
printf ( "bufHash0: %p\n", bufHash[0] );
printf ( "bufHash1: %p\n", bufHash[1] );
printf ( "bufGrid: %p\n", bufGrid );
BT_GPU_SAFE_CALL ( cudaMemcpyToSymbol ( simData, &fcuda, sizeof(FluidParams) ) );
cudaThreadSynchronize ();
}
void FluidParamCUDA ( float sim_scale, float smooth_rad, float mass, float rest, float stiff, float visc )
{
fcuda.sim_scale = sim_scale;
fcuda.smooth_rad = smooth_rad;
fcuda.r2 = smooth_rad * smooth_rad;
fcuda.pmass = mass;
fcuda.rest_dens = rest;
fcuda.stiffness = stiff;
fcuda.visc = visc;
fcuda.pdist = pow ( fcuda.pmass / fcuda.rest_dens, 1/3.0f );
fcuda.poly6kern = 315.0f / (64.0f * 3.141592 * pow( smooth_rad, 9.0f) );
fcuda.spikykern = -45.0f / (3.141592 * pow( smooth_rad, 6.0f) );
fcuda.lapkern = 45.0f / (3.141592 * pow( smooth_rad, 6.0f) );
BT_GPU_SAFE_CALL( cudaMemcpyToSymbol ( simData, &fcuda, sizeof(FluidParams) ) );
cudaThreadSynchronize ();
}
void TransferToCUDA ( char* data, int* grid, int numPoints )
{
BT_GPU_SAFE_CALL( cudaMemcpy ( bufPnts, data, numPoints * fcuda.stride, cudaMemcpyHostToDevice ) );
cudaThreadSynchronize ();
}
void TransferFromCUDA ( char* data, int* grid, int numPoints )
{
BT_GPU_SAFE_CALL( cudaMemcpy ( data, bufPntSort, numPoints * fcuda.stride, cudaMemcpyDeviceToHost ) );
cudaThreadSynchronize ();
BT_GPU_SAFE_CALL( cudaMemcpy ( grid, bufGrid, fcuda.cells * sizeof(uint), cudaMemcpyDeviceToHost ) );
}
void Grid_InsertParticlesCUDA ()
{
BT_GPU_SAFE_CALL( cudaMemset ( bufHash[0], 0, fcuda.szHash ) );
hashParticles<<< fcuda.numBlocks, fcuda.numThreads>>> ( bufPnts, (uint2*) bufHash[0], fcuda.pnts );
BT_GPU_CHECK_ERROR( "Kernel execution failed");
cudaThreadSynchronize ();
//int buf[20000];
/*printf ( "HASH: %d (%d)\n", fcuda.pnts, fcuda.numBlocks*fcuda.numThreads );
BT_GPU_SAFE_CALL( cudaMemcpy ( buf, bufHash[0], fcuda.pnts * 2*sizeof(uint), cudaMemcpyDeviceToHost ) );
//for (int n=0; n < fcuda.numBlocks*fcuda.numThreads; n++) {
for (int n=0; n < 100; n++) {
printf ( "%d: <%d,%d>\n", n, buf[n*2], buf[n*2+1] );
}*/
RadixSort( (KeyValuePair *) bufHash[0], (KeyValuePair *) bufHash[1], fcuda.pnts, 32);
BT_GPU_CHECK_ERROR( "Kernel execution failed");
cudaThreadSynchronize ();
/*printf ( "HASH: %d (%d)\n", fcuda.pnts, fcuda.numBlocks*fcuda.numThreads );
BT_GPU_SAFE_CALL( cudaMemcpy ( buf, bufHash[0], fcuda.pnts * 2*sizeof(uint), cudaMemcpyDeviceToHost ) );
//for (int n=0; n < fcuda.numBlocks*fcuda.numThreads; n++) {
for (int n=0; n < 100; n++) {
printf ( "%d: <%d,%d>\n", n, buf[n*2], buf[n*2+1] );
}*/
// insertParticles<<< fcuda.gridBlocks, fcuda.gridThreads>>> ( bufPnts, (uint2*) bufHash[0], bufGrid, fcuda.pnts, fcuda.cells );
BT_GPU_SAFE_CALL( cudaMemset ( bufGrid, NULL_HASH, fcuda.cells * sizeof(uint) ) );
insertParticlesRadix<<< fcuda.numBlocks, fcuda.numThreads>>> ( bufPnts, (uint2*) bufHash[0], bufGrid, bufPntSort, fcuda.pnts, fcuda.cells );
BT_GPU_CHECK_ERROR( "Kernel execution failed");
cudaThreadSynchronize ();
/*printf ( "GRID: %d\n", fcuda.cells );
BT_GPU_SAFE_CALL( cudaMemcpy ( buf, bufGrid, fcuda.cells * sizeof(uint), cudaMemcpyDeviceToHost ) );
*for (int n=0; n < 100; n++) {
printf ( "%d: %d\n", n, buf[n]);
}*/
}
void SPH_ComputePressureCUDA ()
{
computePressure<<< fcuda.numBlocks, fcuda.numThreads>>> ( bufPntSort, bufGrid, (uint2*) bufHash[0], fcuda.pnts );
BT_GPU_CHECK_ERROR( "Kernel execution failed");
cudaThreadSynchronize ();
}
void SPH_ComputeForceCUDA ()
{
//-- standard force
//computeForce<<< fcuda.numBlocks, fcuda.numThreads>>> ( bufPntSort, bufGrid, (uint2*) bufHash[0], fcuda.pnts );
// Force using neighbor table
computeForceNbr<<< fcuda.numBlocks, fcuda.numThreads>>> ( bufPntSort, fcuda.pnts );
BT_GPU_CHECK_ERROR( "Kernel execution failed");
cudaThreadSynchronize ();
}
void SPH_AdvanceCUDA ( float dt, float ss )
{
advanceParticles<<< fcuda.numBlocks, fcuda.numThreads>>> ( bufPntSort, fcuda.pnts, dt, ss );
BT_GPU_CHECK_ERROR( "Kernel execution failed");
cudaThreadSynchronize ();
}
} // extern C
//----------- Per frame: Malloc/Free, Host<->Device
// transfer point data to device
/*char* pntData;
int size = (fcuda.numBlocks*fcuda.numThreads) * stride;
cudaMalloc( (void**) &pntData, size);
cudaMemcpy( pntData, data, numPoints*stride, cudaMemcpyHostToDevice);
insertParticles<<< fcuda.numBlocks, fcuda.numThreads >>> ( pntData, stride, numPoints );
cudaMemcpy( data, pntData, numPoints*stride, cudaMemcpyDeviceToHost);
cudaFree( pntData );*/
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2008. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
//#include "C:\CUDA\common\inc\cutil.h" // cutil32.lib
#include <string.h>
#include "../CUDA/btCudaDefines.h"
#if defined(__APPLE__) || defined(MACOSX)
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <cuda_gl_interop.h>
#include "radixsort.cu"
#include "fluid_system_kern.cu" // build kernel
FluidParams fcuda;
__device__ char* bufPnts; // point data (array of Fluid structs)
__device__ char* bufPntSort; // point data (array of Fluid structs)
__device__ uint* bufHash[2]; // point grid hash
__device__ int* bufGrid;
extern "C"
{
// Initialize CUDA
void cudaInit(int argc, char **argv)
{
//CUT_DEVICE_INIT(argc, argv);
cudaDeviceProp p;
cudaGetDeviceProperties ( &p, 0);
printf ( "-- CUDA --\n" );
printf ( "Name: %s\n", p.name );
printf ( "Revision: %d.%d\n", p.major, p.minor );
printf ( "Global Mem: %d\n", p.totalGlobalMem );
printf ( "Shared/Blk: %d\n", p.sharedMemPerBlock );
printf ( "Regs/Blk: %d\n", p.regsPerBlock );
printf ( "Warp Size: %d\n", p.warpSize );
printf ( "Mem Pitch: %d\n", p.memPitch );
printf ( "Thrds/Blk: %d\n", p.maxThreadsPerBlock );
printf ( "Const Mem: %d\n", p.totalConstMem );
printf ( "Clock Rate: %d\n", p.clockRate );
BT_GPU_SAFE_CALL ( cudaMalloc ( (void**) &bufPnts, 10 ) );
BT_GPU_SAFE_CALL ( cudaMalloc ( (void**) &bufPntSort, 10 ) );
BT_GPU_SAFE_CALL ( cudaMalloc ( (void**) &bufHash, 10 ) );
BT_GPU_SAFE_CALL ( cudaMalloc ( (void**) &bufGrid, 10 ) );
};
// Compute number of blocks to create
int iDivUp (int a, int b) {
return (a % b != 0) ? (a / b + 1) : (a / b);
}
void computeNumBlocks (int numPnts, int maxThreads, int &numBlocks, int &numThreads)
{
numThreads = min( maxThreads, numPnts );
numBlocks = iDivUp ( numPnts, numThreads );
}
void FluidClearCUDA ()
{
BT_GPU_SAFE_CALL ( cudaFree ( bufPnts ) );
BT_GPU_SAFE_CALL ( cudaFree ( bufPntSort ) );
BT_GPU_SAFE_CALL ( cudaFree ( bufHash[0] ) );
BT_GPU_SAFE_CALL ( cudaFree ( bufHash[1] ) );
BT_GPU_SAFE_CALL ( cudaFree ( bufGrid ) );
}
void FluidSetupCUDA ( int num, int stride, float3 min, float3 max, float3 res, float3 size, int chk )
{
fcuda.min = make_float3(min.x, min.y, min.z);
fcuda.max = make_float3(max.x, max.y, max.z);
fcuda.res = make_float3(res.x, res.y, res.z);
fcuda.size = make_float3(size.x, size.y, size.z);
fcuda.pnts = num;
fcuda.delta.x = res.x / size.x;
fcuda.delta.y = res.y / size.y;
fcuda.delta.z = res.z / size.z;
fcuda.cells = res.x*res.y*res.z;
fcuda.chk = chk;
computeNumBlocks ( fcuda.pnts, 256, fcuda.numBlocks, fcuda.numThreads); // particles
computeNumBlocks ( fcuda.cells, 256, fcuda.gridBlocks, fcuda.gridThreads); // grid cell
fcuda.szPnts = (fcuda.numBlocks * fcuda.numThreads) * stride;
fcuda.szHash = (fcuda.numBlocks * fcuda.numThreads) * sizeof(uint2); // <cell, particle> pairs
fcuda.szGrid = (fcuda.gridBlocks * fcuda.gridThreads) * sizeof(uint);
fcuda.stride = stride;
printf ( "pnts: %d, t:%dx%d=%d, bufPnts:%d, bufHash:%d\n", fcuda.pnts, fcuda.numBlocks, fcuda.numThreads, fcuda.numBlocks*fcuda.numThreads, fcuda.szPnts, fcuda.szHash );
printf ( "grds: %d, t:%dx%d=%d, bufGrid:%d, Res: %dx%dx%d\n", fcuda.cells, fcuda.gridBlocks, fcuda.gridThreads, fcuda.gridBlocks*fcuda.gridThreads, fcuda.szGrid, (int) fcuda.res.x, (int) fcuda.res.y, (int) fcuda.res.z );
BT_GPU_SAFE_CALL ( cudaMalloc ( (void**) &bufPnts, fcuda.szPnts ) );
BT_GPU_SAFE_CALL ( cudaMalloc ( (void**) &bufPntSort, fcuda.szPnts ) );
BT_GPU_SAFE_CALL ( cudaMalloc ( (void**) &bufHash[0], fcuda.szHash ) );
BT_GPU_SAFE_CALL ( cudaMalloc ( (void**) &bufHash[1], fcuda.szHash ) );
BT_GPU_SAFE_CALL ( cudaMalloc ( (void**) &bufGrid, fcuda.szGrid ) );
printf ( "POINTERS\n");
printf ( "bufPnts: %p\n", bufPnts );
printf ( "bufPntSort: %p\n", bufPntSort );
printf ( "bufHash0: %p\n", bufHash[0] );
printf ( "bufHash1: %p\n", bufHash[1] );
printf ( "bufGrid: %p\n", bufGrid );
BT_GPU_SAFE_CALL ( cudaMemcpyToSymbol ( simData, &fcuda, sizeof(FluidParams) ) );
cudaThreadSynchronize ();
}
void FluidParamCUDA ( float sim_scale, float smooth_rad, float mass, float rest, float stiff, float visc )
{
fcuda.sim_scale = sim_scale;
fcuda.smooth_rad = smooth_rad;
fcuda.r2 = smooth_rad * smooth_rad;
fcuda.pmass = mass;
fcuda.rest_dens = rest;
fcuda.stiffness = stiff;
fcuda.visc = visc;
fcuda.pdist = pow ( fcuda.pmass / fcuda.rest_dens, 1/3.0f );
fcuda.poly6kern = 315.0f / (64.0f * 3.141592 * pow( smooth_rad, 9.0f) );
fcuda.spikykern = -45.0f / (3.141592 * pow( smooth_rad, 6.0f) );
fcuda.lapkern = 45.0f / (3.141592 * pow( smooth_rad, 6.0f) );
BT_GPU_SAFE_CALL( cudaMemcpyToSymbol ( simData, &fcuda, sizeof(FluidParams) ) );
cudaThreadSynchronize ();
}
void TransferToCUDA ( char* data, int* grid, int numPoints )
{
BT_GPU_SAFE_CALL( cudaMemcpy ( bufPnts, data, numPoints * fcuda.stride, cudaMemcpyHostToDevice ) );
cudaThreadSynchronize ();
}
void TransferFromCUDA ( char* data, int* grid, int numPoints )
{
BT_GPU_SAFE_CALL( cudaMemcpy ( data, bufPntSort, numPoints * fcuda.stride, cudaMemcpyDeviceToHost ) );
cudaThreadSynchronize ();
BT_GPU_SAFE_CALL( cudaMemcpy ( grid, bufGrid, fcuda.cells * sizeof(uint), cudaMemcpyDeviceToHost ) );
}
void Grid_InsertParticlesCUDA ()
{
BT_GPU_SAFE_CALL( cudaMemset ( bufHash[0], 0, fcuda.szHash ) );
hashParticles<<< fcuda.numBlocks, fcuda.numThreads>>> ( bufPnts, (uint2*) bufHash[0], fcuda.pnts );
BT_GPU_CHECK_ERROR( "Kernel execution failed");
cudaThreadSynchronize ();
//int buf[20000];
/*printf ( "HASH: %d (%d)\n", fcuda.pnts, fcuda.numBlocks*fcuda.numThreads );
BT_GPU_SAFE_CALL( cudaMemcpy ( buf, bufHash[0], fcuda.pnts * 2*sizeof(uint), cudaMemcpyDeviceToHost ) );
//for (int n=0; n < fcuda.numBlocks*fcuda.numThreads; n++) {
for (int n=0; n < 100; n++) {
printf ( "%d: <%d,%d>\n", n, buf[n*2], buf[n*2+1] );
}*/
RadixSort( (KeyValuePair *) bufHash[0], (KeyValuePair *) bufHash[1], fcuda.pnts, 32);
BT_GPU_CHECK_ERROR( "Kernel execution failed");
cudaThreadSynchronize ();
/*printf ( "HASH: %d (%d)\n", fcuda.pnts, fcuda.numBlocks*fcuda.numThreads );
BT_GPU_SAFE_CALL( cudaMemcpy ( buf, bufHash[0], fcuda.pnts * 2*sizeof(uint), cudaMemcpyDeviceToHost ) );
//for (int n=0; n < fcuda.numBlocks*fcuda.numThreads; n++) {
for (int n=0; n < 100; n++) {
printf ( "%d: <%d,%d>\n", n, buf[n*2], buf[n*2+1] );
}*/
// insertParticles<<< fcuda.gridBlocks, fcuda.gridThreads>>> ( bufPnts, (uint2*) bufHash[0], bufGrid, fcuda.pnts, fcuda.cells );
BT_GPU_SAFE_CALL( cudaMemset ( bufGrid, NULL_HASH, fcuda.cells * sizeof(uint) ) );
insertParticlesRadix<<< fcuda.numBlocks, fcuda.numThreads>>> ( bufPnts, (uint2*) bufHash[0], bufGrid, bufPntSort, fcuda.pnts, fcuda.cells );
BT_GPU_CHECK_ERROR( "Kernel execution failed");
cudaThreadSynchronize ();
/*printf ( "GRID: %d\n", fcuda.cells );
BT_GPU_SAFE_CALL( cudaMemcpy ( buf, bufGrid, fcuda.cells * sizeof(uint), cudaMemcpyDeviceToHost ) );
*for (int n=0; n < 100; n++) {
printf ( "%d: %d\n", n, buf[n]);
}*/
}
void SPH_ComputePressureCUDA ()
{
computePressure<<< fcuda.numBlocks, fcuda.numThreads>>> ( bufPntSort, bufGrid, (uint2*) bufHash[0], fcuda.pnts );
BT_GPU_CHECK_ERROR( "Kernel execution failed");
cudaThreadSynchronize ();
}
void SPH_ComputeForceCUDA ()
{
//-- standard force
//computeForce<<< fcuda.numBlocks, fcuda.numThreads>>> ( bufPntSort, bufGrid, (uint2*) bufHash[0], fcuda.pnts );
// Force using neighbor table
computeForceNbr<<< fcuda.numBlocks, fcuda.numThreads>>> ( bufPntSort, fcuda.pnts );
BT_GPU_CHECK_ERROR( "Kernel execution failed");
cudaThreadSynchronize ();
}
void SPH_AdvanceCUDA ( float dt, float ss )
{
advanceParticles<<< fcuda.numBlocks, fcuda.numThreads>>> ( bufPntSort, fcuda.pnts, dt, ss );
BT_GPU_CHECK_ERROR( "Kernel execution failed");
cudaThreadSynchronize ();
}
} // extern C
//----------- Per frame: Malloc/Free, Host<->Device
// transfer point data to device
/*char* pntData;
int size = (fcuda.numBlocks*fcuda.numThreads) * stride;
cudaMalloc( (void**) &pntData, size);
cudaMemcpy( pntData, data, numPoints*stride, cudaMemcpyHostToDevice);
insertParticles<<< fcuda.numBlocks, fcuda.numThreads >>> ( pntData, stride, numPoints );
cudaMemcpy( data, pntData, numPoints*stride, cudaMemcpyDeviceToHost);
cudaFree( pntData );*/

View File

@@ -1,63 +1,63 @@
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2008. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include <vector_types.h>
#include <driver_types.h> // for cudaStream_t
typedef unsigned int uint; // should be 4-bytes on CUDA
typedef unsigned char uchar; // should be 1-bytes on CUDA
struct FluidParams {
int numThreads, numBlocks;
int gridThreads, gridBlocks;
int szPnts, szHash, szGrid;
int stride, pnts, cells;
int chk;
float smooth_rad, r2, sim_scale, visc;
float3 min, max, res, size, delta;
float pdist, pmass, rest_dens, stiffness;
float poly6kern, spikykern, lapkern;
};
extern "C"
{
void cudaInit(int argc, char **argv);
void FluidClearCUDA ();
void FluidSetupCUDA ( int num, int stride, float3 min, float3 max, float3 res, float3 size, int chk );
void FluidParamCUDA ( float sim_scale, float smooth_rad, float mass, float rest, float stiff, float visc );
void TransferToCUDA ( char* data, int* grid, int numPoints );
void TransferFromCUDA ( char* data, int* grid, int numPoints );
void Grid_InsertParticlesCUDA ();
void SPH_ComputePressureCUDA ();
void SPH_ComputeForceCUDA ();
void SPH_AdvanceCUDA ( float dt, float ss );
}
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2008. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include <vector_types.h>
#include <driver_types.h> // for cudaStream_t
typedef unsigned int uint; // should be 4-bytes on CUDA
typedef unsigned char uchar; // should be 1-bytes on CUDA
struct FluidParams {
int numThreads, numBlocks;
int gridThreads, gridBlocks;
int szPnts, szHash, szGrid;
int stride, pnts, cells;
int chk;
float smooth_rad, r2, sim_scale, visc;
float3 min, max, res, size, delta;
float pdist, pmass, rest_dens, stiffness;
float poly6kern, spikykern, lapkern;
};
extern "C"
{
void cudaInit(int argc, char **argv);
void FluidClearCUDA ();
void FluidSetupCUDA ( int num, int stride, float3 min, float3 max, float3 res, float3 size, int chk );
void FluidParamCUDA ( float sim_scale, float smooth_rad, float mass, float rest, float stiff, float visc );
void TransferToCUDA ( char* data, int* grid, int numPoints );
void TransferFromCUDA ( char* data, int* grid, int numPoints );
void Grid_InsertParticlesCUDA ();
void SPH_ComputePressureCUDA ();
void SPH_ComputeForceCUDA ();
void SPH_AdvanceCUDA ( float dt, float ss );
}

View File

@@ -1,402 +1,402 @@
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2008. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _PARTICLES_KERNEL_H_
#define _PARTICLES_KERNEL_H_
#include <stdio.h>
#include <math.h>
#include "fluid_system_host.cuh"
#define TOTAL_THREADS 65536
#define BLOCK_THREADS 256
#define MAX_NBR 80
__constant__ FluidParams simData; // simulation data (on device)
__device__ int bufNeighbor[ TOTAL_THREADS*MAX_NBR ];
__device__ float bufNdist[ TOTAL_THREADS*MAX_NBR ];
#define COLOR(r,g,b) ( (uint((r)*255.0f)<<24) | (uint((g)*255.0f)<<16) | (uint((b)*255.0f)<<8) )
#define COLORA(r,g,b,a) ( (uint((r)*255.0f)<<24) | (uint((g)*255.0f)<<16) | (uint((b)*255.0f)<<8) | uint((a)*255.0f) )
#define NULL_HASH 333333
#define OFFSET_CLR 12
#define OFFSET_NEXT 16
#define OFFSET_VEL 20
#define OFFSET_VEVAL 32
#define OFFSET_PRESS 48
#define OFFSET_DENS 52
#define OFFSET_FORCE 56
__global__ void hashParticles ( char* bufPnts, uint2* bufHash, int numPnt )
{
uint ndx = __mul24(blockIdx.x, blockDim.x) + threadIdx.x; // particle index
float3* pos = (float3*) (bufPnts + __mul24(ndx, simData.stride) );
int gz = (pos->z - simData.min.z) * simData.delta.z ;
int gy = (pos->y - simData.min.y) * simData.delta.y ;
int gx = (pos->x - simData.min.x) * simData.delta.x ;
if ( ndx >= numPnt || gx < 0 || gz > simData.res.x-1 || gy < 0 || gy > simData.res.y-1 || gz < 0 || gz > simData.res.z-1 )
bufHash[ndx] = make_uint2( NULL_HASH, ndx );
else
bufHash[ndx] = make_uint2( __mul24(__mul24(gz, (int) simData.res.y)+gy, (int) simData.res.x) + gx, ndx );
__syncthreads ();
}
__global__ void insertParticles ( char* bufPnts, uint2* bufHash, int* bufGrid, int numPnt, int numGrid )
{
uint grid_ndx = __mul24(blockIdx.x, blockDim.x) + threadIdx.x; // grid cell index
bufPnts += OFFSET_NEXT;
bufGrid[grid_ndx] = -1;
for (int n=0; n < numPnt; n++) {
if ( bufHash[n].x == grid_ndx ) {
*(int*) (bufPnts + __mul24(bufHash[n].y, simData.stride)) = bufGrid[grid_ndx];
bufGrid[grid_ndx] = bufHash[n].y;
}
}
__syncthreads ();
}
__global__ void insertParticlesRadix ( char* bufPnts, uint2* bufHash, int* bufGrid, char* bufPntSort, int numPnt, int numGrid )
{
uint ndx = __mul24(blockIdx.x, blockDim.x) + threadIdx.x; // particle index
uint2 bufHashSort = bufHash[ndx];
__shared__ uint sharedHash[257];
sharedHash[threadIdx.x+1] = bufHashSort.x;
if ( ndx > 0 && threadIdx.x == 0 ) {
volatile uint2 prevData = bufHash[ndx-1];
sharedHash[0] = prevData.x;
}
__syncthreads ();
if ( (ndx == 0 || bufHashSort.x != sharedHash[threadIdx.x]) && bufHashSort.x != NULL_HASH ) {
bufGrid [ bufHashSort.x ] = ndx;
}
if ( ndx < numPnt ) {
char* src = bufPnts + __mul24( bufHashSort.y, simData.stride );
char* dest = bufPntSort + __mul24( ndx, simData.stride );
*(float3*)(dest) = *(float3*)(src);
*(uint*) (dest + OFFSET_CLR) = *(uint*) (src + OFFSET_CLR);
*(float3*)(dest + OFFSET_VEL) = *(float3*)(src + OFFSET_VEL);
*(float3*)(dest + OFFSET_VEVAL) = *(float3*)(src + OFFSET_VEVAL);
*(float*) (dest + OFFSET_DENS) = 0.0;
*(float*) (dest + OFFSET_PRESS) = 0.0;
*(float3*) (dest + OFFSET_FORCE)= make_float3(0,0,0);
*(int*) (dest + OFFSET_NEXT) = bufHashSort.x;
}
__syncthreads ();
}
//__shared__ int ncount [ BLOCK_THREADS ];
__device__ float contributePressure ( int pndx, float3* p, int qndx, int grid_ndx, char* bufPnts, uint2* bufHash )
{
float3* qpos;
float3 dist;
float dsq, c, sum;
float d = simData.sim_scale;
int nbr = __mul24(pndx, MAX_NBR);
sum = 0.0;
for ( ; qndx < simData.pnts; qndx++ ) {
if ( bufHash[qndx].x != grid_ndx || qndx == NULL_HASH) break;
if ( qndx != pndx ) {
qpos = (float3*) ( bufPnts + __mul24(qndx, simData.stride ));
dist.x = ( p->x - qpos->x )*d; // dist in cm
dist.y = ( p->y - qpos->y )*d;
dist.z = ( p->z - qpos->z )*d;
dsq = (dist.x*dist.x + dist.y*dist.y + dist.z*dist.z);
if ( dsq < simData.r2 ) {
c = simData.r2 - dsq;
sum += c * c * c;
if ( bufNeighbor[nbr] < MAX_NBR ) {
bufNeighbor[ nbr+bufNeighbor[nbr] ] = qndx;
bufNdist[ nbr+bufNeighbor[nbr] ] = sqrt(dsq);
bufNeighbor[nbr]++;
}
}
}
//curr = *(int*) (bufPnts + __mul24(curr, simData.stride) + OFFSET_NEXT);
}
return sum;
}
/*if ( ncount[threadIdx.x] < MAX_NBR ) {
bufNeighbor [ nbr + ncount[threadIdx.x] ] = curr;
bufNdist [ nbr + ncount[threadIdx.x] ] = sqrt(dsq);
ncount[threadIdx.x]++;
}*/
__global__ void computePressure ( char* bufPntSort, int* bufGrid, uint2* bufHash, int numPnt )
{
uint ndx = __mul24(blockIdx.x, blockDim.x) + threadIdx.x; // particle index
//if ( ndx < 1024 ) {
float3* pos = (float3*) (bufPntSort + __mul24(ndx, simData.stride));
// Find 2x2x2 grid cells
// - Use registers only, no arrays (local-memory too slow)
int3 cell;
int gc0, gc1, gc2, gc3, gc4, gc5, gc6, gc7;
float gs = simData.smooth_rad / simData.sim_scale;
cell.x = max(0, (int)((-gs + pos->x - simData.min.x) * simData.delta.x));
cell.y = max(0, (int)((-gs + pos->y - simData.min.y) * simData.delta.y));
cell.z = max(0, (int)((-gs + pos->z - simData.min.z) * simData.delta.z));
gc0 = __mul24(__mul24(cell.z, simData.res.y) + cell.y, simData.res.x) + cell.x;
gc1 = gc0 + 1;
gc2 = gc0 + simData.res.x;
gc3 = gc2 + 1;
if ( cell.z+1 < simData.res.z ) {
gc4 = gc0 + __mul24(simData.res.x, simData.res.y);
gc5 = gc4 + 1;
gc6 = gc4 + simData.res.x;
gc7 = gc6 + 1;
}
if ( cell.x+1 >= simData.res.x ) {
gc1 = -1; gc3 = -1;
gc5 = -1; gc7 = -1;
}
if ( cell.y+1 >= simData.res.y ) {
gc2 = -1; gc3 = -1;
gc6 = -1; gc7 = -1;
}
// Sum Pressure
float sum = 0.0;
bufNeighbor[ __mul24(ndx, MAX_NBR) ] = 1;
if (gc0 != -1 ) sum += contributePressure ( ndx, pos, bufGrid[gc0], gc0, bufPntSort, bufHash );
if (gc1 != -1 ) sum += contributePressure ( ndx, pos, bufGrid[gc1], gc1, bufPntSort, bufHash );
if (gc2 != -1 ) sum += contributePressure ( ndx, pos, bufGrid[gc2], gc2, bufPntSort, bufHash );
if (gc3 != -1 ) sum += contributePressure ( ndx, pos, bufGrid[gc3], gc3, bufPntSort, bufHash );
if (gc4 != -1 ) sum += contributePressure ( ndx, pos, bufGrid[gc4], gc4, bufPntSort, bufHash );
if (gc5 != -1 ) sum += contributePressure ( ndx, pos, bufGrid[gc5], gc5, bufPntSort, bufHash );
if (gc6 != -1 ) sum += contributePressure ( ndx, pos, bufGrid[gc6], gc6, bufPntSort, bufHash );
if (gc7 != -1 ) sum += contributePressure ( ndx, pos, bufGrid[gc7], gc7, bufPntSort, bufHash );
// Compute Density & Pressure
sum = sum * simData.pmass * simData.poly6kern;
if ( sum == 0.0 ) sum = 1.0;
*(float*) ((char*)pos + OFFSET_PRESS) = ( sum - simData.rest_dens ) * simData.stiffness;
*(float*) ((char*)pos + OFFSET_DENS) = 1.0f / sum;
//}
//__syncthreads ();
}
__device__ void contributeForce ( float3& force, int pndx, float3* p, int qndx, int grid_ndx, char* bufPnts, uint2* bufHash )
{
float press = *(float*) ((char*)p + OFFSET_PRESS);
float dens = *(float*) ((char*)p + OFFSET_DENS);
float3 veval = *(float3*) ((char*)p + OFFSET_VEVAL );
float3 qeval, dist;
float c, ndistj, dsq;
float pterm, dterm, vterm;
float3* qpos;
float d = simData.sim_scale;
vterm = simData.lapkern * simData.visc;
for ( ; qndx < simData.pnts; qndx++ ) {
if ( bufHash[qndx].x != grid_ndx || qndx == NULL_HASH) break;
if ( qndx != pndx ) {
qpos = (float3*) ( bufPnts + __mul24(qndx, simData.stride ));
dist.x = ( p->x - qpos->x )*d; // dist in cm
dist.y = ( p->y - qpos->y )*d;
dist.z = ( p->z - qpos->z )*d;
dsq = (dist.x*dist.x + dist.y*dist.y + dist.z*dist.z);
if ( dsq < simData.r2 ) {
ndistj = sqrt(dsq);
c = ( simData.smooth_rad - ndistj );
dist.x = ( p->x - qpos->x )*d; // dist in cm
dist.y = ( p->y - qpos->y )*d;
dist.z = ( p->z - qpos->z )*d;
pterm = -0.5f * c * simData.spikykern * ( press + *(float*)((char*)qpos+OFFSET_PRESS) ) / ndistj;
dterm = c * dens * *(float*)((char*)qpos+OFFSET_DENS);
qeval = *(float3*)((char*)qpos+OFFSET_VEVAL);
force.x += ( pterm * dist.x + vterm * ( qeval.x - veval.x )) * dterm;
force.y += ( pterm * dist.y + vterm * ( qeval.y - veval.y )) * dterm;
force.z += ( pterm * dist.z + vterm * ( qeval.z - veval.z )) * dterm;
}
}
}
}
__global__ void computeForce ( char* bufPntSort, int* bufGrid, uint2* bufHash, int numPnt )
{
uint ndx = __mul24(blockIdx.x, blockDim.x) + threadIdx.x; // particle index
//if ( ndx < numPnt ) {
float3* pos = (float3*) (bufPntSort + __mul24(ndx, simData.stride));
// Find 2x2x2 grid cells
// - Use registers only, no arrays (local-memory too slow)
int3 cell;
int gc0, gc1, gc2, gc3, gc4, gc5, gc6, gc7;
float gs = simData.smooth_rad / simData.sim_scale;
cell.x = max(0, (int)((-gs + pos->x - simData.min.x) * simData.delta.x));
cell.y = max(0, (int)((-gs + pos->y - simData.min.y) * simData.delta.y));
cell.z = max(0, (int)((-gs + pos->z - simData.min.z) * simData.delta.z));
gc0 = __mul24(__mul24(cell.z, simData.res.y) + cell.y, simData.res.x) + cell.x;
gc1 = gc0 + 1;
gc2 = gc0 + simData.res.x;
gc3 = gc2 + 1;
if ( cell.z+1 < simData.res.z ) {
gc4 = gc0 + __mul24(simData.res.x, simData.res.y);
gc5 = gc4 + 1;
gc6 = gc4 + simData.res.x;
gc7 = gc6 + 1;
}
if ( cell.x+1 >= simData.res.x ) {
gc1 = -1; gc3 = -1;
gc5 = -1; gc7 = -1;
}
if ( cell.y+1 >= simData.res.y ) {
gc2 = -1; gc3 = -1;
gc6 = -1; gc7 = -1;
}
// Sum Pressure
float3 force = make_float3(0,0,0);
if (gc0 != -1 ) contributeForce ( force, ndx, pos, bufGrid[gc0], gc0, bufPntSort, bufHash );
if (gc1 != -1 ) contributeForce ( force, ndx, pos, bufGrid[gc1], gc1, bufPntSort, bufHash );
if (gc2 != -1 ) contributeForce ( force, ndx, pos, bufGrid[gc2], gc2, bufPntSort, bufHash );
if (gc3 != -1 ) contributeForce ( force, ndx, pos, bufGrid[gc3], gc3, bufPntSort, bufHash );
if (gc4 != -1 ) contributeForce ( force, ndx, pos, bufGrid[gc4], gc4, bufPntSort, bufHash );
if (gc5 != -1 ) contributeForce ( force, ndx, pos, bufGrid[gc5], gc5, bufPntSort, bufHash );
if (gc6 != -1 ) contributeForce ( force, ndx, pos, bufGrid[gc6], gc6, bufPntSort, bufHash );
if (gc7 != -1 ) contributeForce ( force, ndx, pos, bufGrid[gc7], gc7, bufPntSort, bufHash );
// Update Force
*(float3*) ((char*)pos + OFFSET_FORCE ) = force;
//}
//__syncthreads ();
}
__global__ void computeForceNbr ( char* bufPntSort, int numPnt )
{
uint ndx = __mul24(blockIdx.x, blockDim.x) + threadIdx.x; // particle index
if ( ndx < numPnt ) {
float3* pos = (float3*) (bufPntSort + __mul24(ndx, simData.stride));
float3* qpos;
float press = *(float*) ((char*)pos + OFFSET_PRESS);
float dens = *(float*) ((char*)pos + OFFSET_DENS);
float3 veval = *(float3*) ((char*)pos + OFFSET_VEVAL );
float3 qeval, dist, force;
float d = simData.sim_scale;
float c, ndistj;
float pterm, dterm, vterm;
vterm = simData.lapkern * simData.visc;
int nbr = __mul24(ndx, MAX_NBR);
int ncnt = bufNeighbor[ nbr ];
force = make_float3(0,0,0);
for (int j=1; j < ncnt; j++) { // base 1, n[0] = count
ndistj = bufNdist[ nbr+j ];
qpos = (float3*) (bufPntSort + __mul24( bufNeighbor[ nbr+j ], simData.stride) );
c = ( simData.smooth_rad - ndistj );
dist.x = ( pos->x - qpos->x )*d; // dist in cm
dist.y = ( pos->y - qpos->y )*d;
dist.z = ( pos->z - qpos->z )*d;
pterm = -0.5f * c * simData.spikykern * ( press + *(float*)((char*)qpos+OFFSET_PRESS) ) / ndistj;
dterm = c * dens * *(float*)((char*)qpos+OFFSET_DENS);
qeval = *(float3*)((char*)qpos+OFFSET_VEVAL);
force.x += ( pterm * dist.x + vterm * ( qeval.x - veval.x )) * dterm;
force.y += ( pterm * dist.y + vterm * ( qeval.y - veval.y )) * dterm;
force.z += ( pterm * dist.z + vterm * ( qeval.z - veval.z )) * dterm;
}
*(float3*) ((char*)pos + OFFSET_FORCE ) = force;
}
}
__global__ void advanceParticles ( char* bufPntSort, int numPnt, float dt, float ss )
{
uint ndx = __mul24(blockIdx.x, blockDim.x) + threadIdx.x; // particle index
if ( ndx < numPnt ) {
// Get particle vars
float3* pos = (float3*) (bufPntSort + __mul24(ndx, simData.stride));
float3* vel = (float3*) ((char*)pos + OFFSET_VEL );
float3* vel_eval = (float3*) ((char*)pos + OFFSET_VEVAL );
float3 accel = *(float3*) ((char*)pos + OFFSET_FORCE );
float3 vcurr, vnext;
// Leapfrog integration
accel.x *= 0.00020543; // NOTE - To do: SPH_PMASS should be passed in
accel.y *= 0.00020543;
accel.z *= 0.00020543;
accel.z -= 9.8;
vcurr = *vel;
vnext.x = accel.x*dt + vcurr.x;
vnext.y = accel.y*dt + vcurr.y;
vnext.z = accel.z*dt + vcurr.z; // v(t+1/2) = v(t-1/2) + a(t) dt
accel.x = (vcurr.x + vnext.x) * 0.5; // v(t+1) = [v(t-1/2) + v(t+1/2)] * 0.5 used to compute forces later
accel.y = (vcurr.y + vnext.y) * 0.5; // v(t+1) = [v(t-1/2) + v(t+1/2)] * 0.5 used to compute forces later
accel.z = (vcurr.z + vnext.z) * 0.5; // v(t+1) = [v(t-1/2) + v(t+1/2)] * 0.5 used to compute forces later
*vel_eval = accel;
*vel = vnext;
dt /= simData.sim_scale;
vnext.x = pos->x + vnext.x*dt;
vnext.y = pos->y + vnext.y*dt;
vnext.z = pos->z + vnext.z*dt;
*pos = vnext; // p(t+1) = p(t) + v(t+1/2) dt
}
__syncthreads ();
}
#endif
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2008. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _PARTICLES_KERNEL_H_
#define _PARTICLES_KERNEL_H_
#include <stdio.h>
#include <math.h>
#include "fluid_system_host.cuh"
#define TOTAL_THREADS 65536
#define BLOCK_THREADS 256
#define MAX_NBR 80
__constant__ FluidParams simData; // simulation data (on device)
__device__ int bufNeighbor[ TOTAL_THREADS*MAX_NBR ];
__device__ float bufNdist[ TOTAL_THREADS*MAX_NBR ];
#define COLOR(r,g,b) ( (uint((r)*255.0f)<<24) | (uint((g)*255.0f)<<16) | (uint((b)*255.0f)<<8) )
#define COLORA(r,g,b,a) ( (uint((r)*255.0f)<<24) | (uint((g)*255.0f)<<16) | (uint((b)*255.0f)<<8) | uint((a)*255.0f) )
#define NULL_HASH 333333
#define OFFSET_CLR 12
#define OFFSET_NEXT 16
#define OFFSET_VEL 20
#define OFFSET_VEVAL 32
#define OFFSET_PRESS 48
#define OFFSET_DENS 52
#define OFFSET_FORCE 56
__global__ void hashParticles ( char* bufPnts, uint2* bufHash, int numPnt )
{
uint ndx = __mul24(blockIdx.x, blockDim.x) + threadIdx.x; // particle index
float3* pos = (float3*) (bufPnts + __mul24(ndx, simData.stride) );
int gz = (pos->z - simData.min.z) * simData.delta.z ;
int gy = (pos->y - simData.min.y) * simData.delta.y ;
int gx = (pos->x - simData.min.x) * simData.delta.x ;
if ( ndx >= numPnt || gx < 0 || gz > simData.res.x-1 || gy < 0 || gy > simData.res.y-1 || gz < 0 || gz > simData.res.z-1 )
bufHash[ndx] = make_uint2( NULL_HASH, ndx );
else
bufHash[ndx] = make_uint2( __mul24(__mul24(gz, (int) simData.res.y)+gy, (int) simData.res.x) + gx, ndx );
__syncthreads ();
}
__global__ void insertParticles ( char* bufPnts, uint2* bufHash, int* bufGrid, int numPnt, int numGrid )
{
uint grid_ndx = __mul24(blockIdx.x, blockDim.x) + threadIdx.x; // grid cell index
bufPnts += OFFSET_NEXT;
bufGrid[grid_ndx] = -1;
for (int n=0; n < numPnt; n++) {
if ( bufHash[n].x == grid_ndx ) {
*(int*) (bufPnts + __mul24(bufHash[n].y, simData.stride)) = bufGrid[grid_ndx];
bufGrid[grid_ndx] = bufHash[n].y;
}
}
__syncthreads ();
}
__global__ void insertParticlesRadix ( char* bufPnts, uint2* bufHash, int* bufGrid, char* bufPntSort, int numPnt, int numGrid )
{
uint ndx = __mul24(blockIdx.x, blockDim.x) + threadIdx.x; // particle index
uint2 bufHashSort = bufHash[ndx];
__shared__ uint sharedHash[257];
sharedHash[threadIdx.x+1] = bufHashSort.x;
if ( ndx > 0 && threadIdx.x == 0 ) {
volatile uint2 prevData = bufHash[ndx-1];
sharedHash[0] = prevData.x;
}
__syncthreads ();
if ( (ndx == 0 || bufHashSort.x != sharedHash[threadIdx.x]) && bufHashSort.x != NULL_HASH ) {
bufGrid [ bufHashSort.x ] = ndx;
}
if ( ndx < numPnt ) {
char* src = bufPnts + __mul24( bufHashSort.y, simData.stride );
char* dest = bufPntSort + __mul24( ndx, simData.stride );
*(float3*)(dest) = *(float3*)(src);
*(uint*) (dest + OFFSET_CLR) = *(uint*) (src + OFFSET_CLR);
*(float3*)(dest + OFFSET_VEL) = *(float3*)(src + OFFSET_VEL);
*(float3*)(dest + OFFSET_VEVAL) = *(float3*)(src + OFFSET_VEVAL);
*(float*) (dest + OFFSET_DENS) = 0.0;
*(float*) (dest + OFFSET_PRESS) = 0.0;
*(float3*) (dest + OFFSET_FORCE)= make_float3(0,0,0);
*(int*) (dest + OFFSET_NEXT) = bufHashSort.x;
}
__syncthreads ();
}
//__shared__ int ncount [ BLOCK_THREADS ];
__device__ float contributePressure ( int pndx, float3* p, int qndx, int grid_ndx, char* bufPnts, uint2* bufHash )
{
float3* qpos;
float3 dist;
float dsq, c, sum;
float d = simData.sim_scale;
int nbr = __mul24(pndx, MAX_NBR);
sum = 0.0;
for ( ; qndx < simData.pnts; qndx++ ) {
if ( bufHash[qndx].x != grid_ndx || qndx == NULL_HASH) break;
if ( qndx != pndx ) {
qpos = (float3*) ( bufPnts + __mul24(qndx, simData.stride ));
dist.x = ( p->x - qpos->x )*d; // dist in cm
dist.y = ( p->y - qpos->y )*d;
dist.z = ( p->z - qpos->z )*d;
dsq = (dist.x*dist.x + dist.y*dist.y + dist.z*dist.z);
if ( dsq < simData.r2 ) {
c = simData.r2 - dsq;
sum += c * c * c;
if ( bufNeighbor[nbr] < MAX_NBR ) {
bufNeighbor[ nbr+bufNeighbor[nbr] ] = qndx;
bufNdist[ nbr+bufNeighbor[nbr] ] = sqrt(dsq);
bufNeighbor[nbr]++;
}
}
}
//curr = *(int*) (bufPnts + __mul24(curr, simData.stride) + OFFSET_NEXT);
}
return sum;
}
/*if ( ncount[threadIdx.x] < MAX_NBR ) {
bufNeighbor [ nbr + ncount[threadIdx.x] ] = curr;
bufNdist [ nbr + ncount[threadIdx.x] ] = sqrt(dsq);
ncount[threadIdx.x]++;
}*/
__global__ void computePressure ( char* bufPntSort, int* bufGrid, uint2* bufHash, int numPnt )
{
uint ndx = __mul24(blockIdx.x, blockDim.x) + threadIdx.x; // particle index
//if ( ndx < 1024 ) {
float3* pos = (float3*) (bufPntSort + __mul24(ndx, simData.stride));
// Find 2x2x2 grid cells
// - Use registers only, no arrays (local-memory too slow)
int3 cell;
int gc0, gc1, gc2, gc3, gc4, gc5, gc6, gc7;
float gs = simData.smooth_rad / simData.sim_scale;
cell.x = max(0, (int)((-gs + pos->x - simData.min.x) * simData.delta.x));
cell.y = max(0, (int)((-gs + pos->y - simData.min.y) * simData.delta.y));
cell.z = max(0, (int)((-gs + pos->z - simData.min.z) * simData.delta.z));
gc0 = __mul24(__mul24(cell.z, simData.res.y) + cell.y, simData.res.x) + cell.x;
gc1 = gc0 + 1;
gc2 = gc0 + simData.res.x;
gc3 = gc2 + 1;
if ( cell.z+1 < simData.res.z ) {
gc4 = gc0 + __mul24(simData.res.x, simData.res.y);
gc5 = gc4 + 1;
gc6 = gc4 + simData.res.x;
gc7 = gc6 + 1;
}
if ( cell.x+1 >= simData.res.x ) {
gc1 = -1; gc3 = -1;
gc5 = -1; gc7 = -1;
}
if ( cell.y+1 >= simData.res.y ) {
gc2 = -1; gc3 = -1;
gc6 = -1; gc7 = -1;
}
// Sum Pressure
float sum = 0.0;
bufNeighbor[ __mul24(ndx, MAX_NBR) ] = 1;
if (gc0 != -1 ) sum += contributePressure ( ndx, pos, bufGrid[gc0], gc0, bufPntSort, bufHash );
if (gc1 != -1 ) sum += contributePressure ( ndx, pos, bufGrid[gc1], gc1, bufPntSort, bufHash );
if (gc2 != -1 ) sum += contributePressure ( ndx, pos, bufGrid[gc2], gc2, bufPntSort, bufHash );
if (gc3 != -1 ) sum += contributePressure ( ndx, pos, bufGrid[gc3], gc3, bufPntSort, bufHash );
if (gc4 != -1 ) sum += contributePressure ( ndx, pos, bufGrid[gc4], gc4, bufPntSort, bufHash );
if (gc5 != -1 ) sum += contributePressure ( ndx, pos, bufGrid[gc5], gc5, bufPntSort, bufHash );
if (gc6 != -1 ) sum += contributePressure ( ndx, pos, bufGrid[gc6], gc6, bufPntSort, bufHash );
if (gc7 != -1 ) sum += contributePressure ( ndx, pos, bufGrid[gc7], gc7, bufPntSort, bufHash );
// Compute Density & Pressure
sum = sum * simData.pmass * simData.poly6kern;
if ( sum == 0.0 ) sum = 1.0;
*(float*) ((char*)pos + OFFSET_PRESS) = ( sum - simData.rest_dens ) * simData.stiffness;
*(float*) ((char*)pos + OFFSET_DENS) = 1.0f / sum;
//}
//__syncthreads ();
}
__device__ void contributeForce ( float3& force, int pndx, float3* p, int qndx, int grid_ndx, char* bufPnts, uint2* bufHash )
{
float press = *(float*) ((char*)p + OFFSET_PRESS);
float dens = *(float*) ((char*)p + OFFSET_DENS);
float3 veval = *(float3*) ((char*)p + OFFSET_VEVAL );
float3 qeval, dist;
float c, ndistj, dsq;
float pterm, dterm, vterm;
float3* qpos;
float d = simData.sim_scale;
vterm = simData.lapkern * simData.visc;
for ( ; qndx < simData.pnts; qndx++ ) {
if ( bufHash[qndx].x != grid_ndx || qndx == NULL_HASH) break;
if ( qndx != pndx ) {
qpos = (float3*) ( bufPnts + __mul24(qndx, simData.stride ));
dist.x = ( p->x - qpos->x )*d; // dist in cm
dist.y = ( p->y - qpos->y )*d;
dist.z = ( p->z - qpos->z )*d;
dsq = (dist.x*dist.x + dist.y*dist.y + dist.z*dist.z);
if ( dsq < simData.r2 ) {
ndistj = sqrt(dsq);
c = ( simData.smooth_rad - ndistj );
dist.x = ( p->x - qpos->x )*d; // dist in cm
dist.y = ( p->y - qpos->y )*d;
dist.z = ( p->z - qpos->z )*d;
pterm = -0.5f * c * simData.spikykern * ( press + *(float*)((char*)qpos+OFFSET_PRESS) ) / ndistj;
dterm = c * dens * *(float*)((char*)qpos+OFFSET_DENS);
qeval = *(float3*)((char*)qpos+OFFSET_VEVAL);
force.x += ( pterm * dist.x + vterm * ( qeval.x - veval.x )) * dterm;
force.y += ( pterm * dist.y + vterm * ( qeval.y - veval.y )) * dterm;
force.z += ( pterm * dist.z + vterm * ( qeval.z - veval.z )) * dterm;
}
}
}
}
__global__ void computeForce ( char* bufPntSort, int* bufGrid, uint2* bufHash, int numPnt )
{
uint ndx = __mul24(blockIdx.x, blockDim.x) + threadIdx.x; // particle index
//if ( ndx < numPnt ) {
float3* pos = (float3*) (bufPntSort + __mul24(ndx, simData.stride));
// Find 2x2x2 grid cells
// - Use registers only, no arrays (local-memory too slow)
int3 cell;
int gc0, gc1, gc2, gc3, gc4, gc5, gc6, gc7;
float gs = simData.smooth_rad / simData.sim_scale;
cell.x = max(0, (int)((-gs + pos->x - simData.min.x) * simData.delta.x));
cell.y = max(0, (int)((-gs + pos->y - simData.min.y) * simData.delta.y));
cell.z = max(0, (int)((-gs + pos->z - simData.min.z) * simData.delta.z));
gc0 = __mul24(__mul24(cell.z, simData.res.y) + cell.y, simData.res.x) + cell.x;
gc1 = gc0 + 1;
gc2 = gc0 + simData.res.x;
gc3 = gc2 + 1;
if ( cell.z+1 < simData.res.z ) {
gc4 = gc0 + __mul24(simData.res.x, simData.res.y);
gc5 = gc4 + 1;
gc6 = gc4 + simData.res.x;
gc7 = gc6 + 1;
}
if ( cell.x+1 >= simData.res.x ) {
gc1 = -1; gc3 = -1;
gc5 = -1; gc7 = -1;
}
if ( cell.y+1 >= simData.res.y ) {
gc2 = -1; gc3 = -1;
gc6 = -1; gc7 = -1;
}
// Sum Pressure
float3 force = make_float3(0,0,0);
if (gc0 != -1 ) contributeForce ( force, ndx, pos, bufGrid[gc0], gc0, bufPntSort, bufHash );
if (gc1 != -1 ) contributeForce ( force, ndx, pos, bufGrid[gc1], gc1, bufPntSort, bufHash );
if (gc2 != -1 ) contributeForce ( force, ndx, pos, bufGrid[gc2], gc2, bufPntSort, bufHash );
if (gc3 != -1 ) contributeForce ( force, ndx, pos, bufGrid[gc3], gc3, bufPntSort, bufHash );
if (gc4 != -1 ) contributeForce ( force, ndx, pos, bufGrid[gc4], gc4, bufPntSort, bufHash );
if (gc5 != -1 ) contributeForce ( force, ndx, pos, bufGrid[gc5], gc5, bufPntSort, bufHash );
if (gc6 != -1 ) contributeForce ( force, ndx, pos, bufGrid[gc6], gc6, bufPntSort, bufHash );
if (gc7 != -1 ) contributeForce ( force, ndx, pos, bufGrid[gc7], gc7, bufPntSort, bufHash );
// Update Force
*(float3*) ((char*)pos + OFFSET_FORCE ) = force;
//}
//__syncthreads ();
}
__global__ void computeForceNbr ( char* bufPntSort, int numPnt )
{
uint ndx = __mul24(blockIdx.x, blockDim.x) + threadIdx.x; // particle index
if ( ndx < numPnt ) {
float3* pos = (float3*) (bufPntSort + __mul24(ndx, simData.stride));
float3* qpos;
float press = *(float*) ((char*)pos + OFFSET_PRESS);
float dens = *(float*) ((char*)pos + OFFSET_DENS);
float3 veval = *(float3*) ((char*)pos + OFFSET_VEVAL );
float3 qeval, dist, force;
float d = simData.sim_scale;
float c, ndistj;
float pterm, dterm, vterm;
vterm = simData.lapkern * simData.visc;
int nbr = __mul24(ndx, MAX_NBR);
int ncnt = bufNeighbor[ nbr ];
force = make_float3(0,0,0);
for (int j=1; j < ncnt; j++) { // base 1, n[0] = count
ndistj = bufNdist[ nbr+j ];
qpos = (float3*) (bufPntSort + __mul24( bufNeighbor[ nbr+j ], simData.stride) );
c = ( simData.smooth_rad - ndistj );
dist.x = ( pos->x - qpos->x )*d; // dist in cm
dist.y = ( pos->y - qpos->y )*d;
dist.z = ( pos->z - qpos->z )*d;
pterm = -0.5f * c * simData.spikykern * ( press + *(float*)((char*)qpos+OFFSET_PRESS) ) / ndistj;
dterm = c * dens * *(float*)((char*)qpos+OFFSET_DENS);
qeval = *(float3*)((char*)qpos+OFFSET_VEVAL);
force.x += ( pterm * dist.x + vterm * ( qeval.x - veval.x )) * dterm;
force.y += ( pterm * dist.y + vterm * ( qeval.y - veval.y )) * dterm;
force.z += ( pterm * dist.z + vterm * ( qeval.z - veval.z )) * dterm;
}
*(float3*) ((char*)pos + OFFSET_FORCE ) = force;
}
}
__global__ void advanceParticles ( char* bufPntSort, int numPnt, float dt, float ss )
{
uint ndx = __mul24(blockIdx.x, blockDim.x) + threadIdx.x; // particle index
if ( ndx < numPnt ) {
// Get particle vars
float3* pos = (float3*) (bufPntSort + __mul24(ndx, simData.stride));
float3* vel = (float3*) ((char*)pos + OFFSET_VEL );
float3* vel_eval = (float3*) ((char*)pos + OFFSET_VEVAL );
float3 accel = *(float3*) ((char*)pos + OFFSET_FORCE );
float3 vcurr, vnext;
// Leapfrog integration
accel.x *= 0.00020543; // NOTE - To do: SPH_PMASS should be passed in
accel.y *= 0.00020543;
accel.z *= 0.00020543;
accel.z -= 9.8;
vcurr = *vel;
vnext.x = accel.x*dt + vcurr.x;
vnext.y = accel.y*dt + vcurr.y;
vnext.z = accel.z*dt + vcurr.z; // v(t+1/2) = v(t-1/2) + a(t) dt
accel.x = (vcurr.x + vnext.x) * 0.5; // v(t+1) = [v(t-1/2) + v(t+1/2)] * 0.5 used to compute forces later
accel.y = (vcurr.y + vnext.y) * 0.5; // v(t+1) = [v(t-1/2) + v(t+1/2)] * 0.5 used to compute forces later
accel.z = (vcurr.z + vnext.z) * 0.5; // v(t+1) = [v(t-1/2) + v(t+1/2)] * 0.5 used to compute forces later
*vel_eval = accel;
*vel = vnext;
dt /= simData.sim_scale;
vnext.x = pos->x + vnext.x*dt;
vnext.y = pos->y + vnext.y*dt;
vnext.z = pos->z + vnext.z*dt;
*pos = vnext; // p(t+1) = p(t) + v(t+1/2) dt
}
__syncthreads ();
}
#endif

View File

@@ -1,45 +1,45 @@
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _PARTICLES_KERNEL_H_
#define _PARTICLES_KERNEL_H_
#include <stdio.h>
#include <math.h>
#include "cutil_math.h"
#include "math_constants.h"
// Insert particles in grid
__global__ void insertParticles ( char* pntData, uint pntStride )
{
int index = __mul24(blockIdx.x,blockDim.x) + threadIdx.x;
float4 p = *(float4*) (pntData + index*pntStride);
// get address in grid
int3 gridPos = calcGridPos(p);
addParticleToCell(gridPos, index, gridCounters, gridCells);
}
#endif
/*
FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
Copyright (C) 2009. Rama Hoetzlein, http://www.rchoetzlein.com
ZLib license
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _PARTICLES_KERNEL_H_
#define _PARTICLES_KERNEL_H_
#include <stdio.h>
#include <math.h>
#include "cutil_math.h"
#include "math_constants.h"
// Insert particles in grid
__global__ void insertParticles ( char* pntData, uint pntStride )
{
int index = __mul24(blockIdx.x,blockDim.x) + threadIdx.x;
float4 p = *(float4*) (pntData + index*pntStride);
// get address in grid
int3 gridPos = calcGridPos(p);
addParticleToCell(gridPos, index, gridCounters, gridCells);
}
#endif

View File

@@ -1,79 +1,79 @@
/*
* Copyright 1993-2006 NVIDIA Corporation. All rights reserved.
*
* NOTICE TO USER:
*
* This source code is subject to NVIDIA ownership rights under U.S. and
* international Copyright laws.
*
* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE
* CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR
* IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
* OR PERFORMANCE OF THIS SOURCE CODE.
*
* U.S. Government End Users. This source code is a "commercial item" as
* that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of
* "commercial computer software" and "commercial computer software
* documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995)
* and is provided to the U.S. Government only as a commercial end item.
* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through
* 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the
* source code with only those rights set forth herein.
*/
/* Radixsort project with key/value and arbitrary datset size support
* which demonstrates the use of CUDA in a multi phase sorting
* computation.
* Host code.
*/
#include "radixsort.cuh"
#include "radixsort_kernel.cu"
extern "C"
{
////////////////////////////////////////////////////////////////////////////////
//! Perform a radix sort
//! Sorting performed in place on passed arrays.
//!
//! @param pData0 input and output array - data will be sorted
//! @param pData1 additional array to allow ping pong computation
//! @param elements number of elements to sort
////////////////////////////////////////////////////////////////////////////////
void RadixSort(KeyValuePair *pData0, KeyValuePair *pData1, uint elements, uint bits)
{
// Round element count to total number of threads for efficiency
uint elements_rounded_to_3072;
int modval = elements % 3072;
if( modval == 0 )
elements_rounded_to_3072 = elements;
else
elements_rounded_to_3072 = elements + (3072 - (modval));
// Iterate over n bytes of y bit word, using each byte to sort the list in turn
for (uint shift = 0; shift < bits; shift += RADIX)
{
// Perform one round of radix sorting
// Generate per radix group sums radix counts across a radix group
RadixSum<<<NUM_BLOCKS, NUM_THREADS_PER_BLOCK, GRFSIZE>>>(pData0, elements, elements_rounded_to_3072, shift);
// Prefix sum in radix groups, and then between groups throughout a block
RadixPrefixSum<<<PREFIX_NUM_BLOCKS, PREFIX_NUM_THREADS_PER_BLOCK, PREFIX_GRFSIZE>>>();
// Sum the block offsets and then shuffle data into bins
RadixAddOffsetsAndShuffle<<<NUM_BLOCKS, NUM_THREADS_PER_BLOCK, SHUFFLE_GRFSIZE>>>(pData0, pData1, elements, elements_rounded_to_3072, shift);
// Exchange data pointers
KeyValuePair* pTemp = pData0;
pData0 = pData1;
pData1 = pTemp;
}
}
}
/*
* Copyright 1993-2006 NVIDIA Corporation. All rights reserved.
*
* NOTICE TO USER:
*
* This source code is subject to NVIDIA ownership rights under U.S. and
* international Copyright laws.
*
* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE
* CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR
* IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
* OR PERFORMANCE OF THIS SOURCE CODE.
*
* U.S. Government End Users. This source code is a "commercial item" as
* that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of
* "commercial computer software" and "commercial computer software
* documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995)
* and is provided to the U.S. Government only as a commercial end item.
* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through
* 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the
* source code with only those rights set forth herein.
*/
/* Radixsort project with key/value and arbitrary datset size support
* which demonstrates the use of CUDA in a multi phase sorting
* computation.
* Host code.
*/
#include "radixsort.cuh"
#include "radixsort_kernel.cu"
extern "C"
{
////////////////////////////////////////////////////////////////////////////////
//! Perform a radix sort
//! Sorting performed in place on passed arrays.
//!
//! @param pData0 input and output array - data will be sorted
//! @param pData1 additional array to allow ping pong computation
//! @param elements number of elements to sort
////////////////////////////////////////////////////////////////////////////////
void RadixSort(KeyValuePair *pData0, KeyValuePair *pData1, uint elements, uint bits)
{
// Round element count to total number of threads for efficiency
uint elements_rounded_to_3072;
int modval = elements % 3072;
if( modval == 0 )
elements_rounded_to_3072 = elements;
else
elements_rounded_to_3072 = elements + (3072 - (modval));
// Iterate over n bytes of y bit word, using each byte to sort the list in turn
for (uint shift = 0; shift < bits; shift += RADIX)
{
// Perform one round of radix sorting
// Generate per radix group sums radix counts across a radix group
RadixSum<<<NUM_BLOCKS, NUM_THREADS_PER_BLOCK, GRFSIZE>>>(pData0, elements, elements_rounded_to_3072, shift);
// Prefix sum in radix groups, and then between groups throughout a block
RadixPrefixSum<<<PREFIX_NUM_BLOCKS, PREFIX_NUM_THREADS_PER_BLOCK, PREFIX_GRFSIZE>>>();
// Sum the block offsets and then shuffle data into bins
RadixAddOffsetsAndShuffle<<<NUM_BLOCKS, NUM_THREADS_PER_BLOCK, SHUFFLE_GRFSIZE>>>(pData0, pData1, elements, elements_rounded_to_3072, shift);
// Exchange data pointers
KeyValuePair* pTemp = pData0;
pData0 = pData1;
pData1 = pTemp;
}
}
}

View File

@@ -1,63 +1,63 @@
/*
* Copyright 1993-2006 NVIDIA Corporation. All rights reserved.
*
* NOTICE TO USER:
*
* This source code is subject to NVIDIA ownership rights under U.S. and
* international Copyright laws.
*
* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE
* CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR
* IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
* OR PERFORMANCE OF THIS SOURCE CODE.
*
* U.S. Government End Users. This source code is a "commercial item" as
* that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of
* "commercial computer software" and "commercial computer software
* documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995)
* and is provided to the U.S. Government only as a commercial end item.
* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through
* 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the
* source code with only those rights set forth herein.
*/
/* Radixsort project which demonstrates the use of CUDA in a multi phase
* sorting computation.
* Type definitions.
*/
#ifndef _RADIXSORT_H_
#define _RADIXSORT_H_
#include <host_defines.h>
#define SYNCIT __syncthreads()
// Use 16 bit keys/values
#define SIXTEEN 0
typedef unsigned int uint;
typedef unsigned short ushort;
#if SIXTEEN
typedef struct __align__(4) {
ushort key;
ushort value;
#else
typedef struct __align__(8) {
uint key;
uint value;
#endif
} KeyValuePair;
extern "C" {
void RadixSort(KeyValuePair *pData0, KeyValuePair *pData1, uint elements, uint bits);
}
#endif // #ifndef _RADIXSORT_H_
/*
* Copyright 1993-2006 NVIDIA Corporation. All rights reserved.
*
* NOTICE TO USER:
*
* This source code is subject to NVIDIA ownership rights under U.S. and
* international Copyright laws.
*
* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE
* CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR
* IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
* OR PERFORMANCE OF THIS SOURCE CODE.
*
* U.S. Government End Users. This source code is a "commercial item" as
* that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of
* "commercial computer software" and "commercial computer software
* documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995)
* and is provided to the U.S. Government only as a commercial end item.
* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through
* 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the
* source code with only those rights set forth herein.
*/
/* Radixsort project which demonstrates the use of CUDA in a multi phase
* sorting computation.
* Type definitions.
*/
#ifndef _RADIXSORT_H_
#define _RADIXSORT_H_
#include <host_defines.h>
#define SYNCIT __syncthreads()
// Use 16 bit keys/values
#define SIXTEEN 0
typedef unsigned int uint;
typedef unsigned short ushort;
#if SIXTEEN
typedef struct __align__(4) {
ushort key;
ushort value;
#else
typedef struct __align__(8) {
uint key;
uint value;
#endif
} KeyValuePair;
extern "C" {
void RadixSort(KeyValuePair *pData0, KeyValuePair *pData1, uint elements, uint bits);
}
#endif // #ifndef _RADIXSORT_H_

File diff suppressed because it is too large Load Diff

View File

@@ -1,23 +1,23 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fluids_2005", "fluids_2005.vcproj", "{644E4AC1-416D-4567-A68B-D66CA9FCFD9C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
EmuDebug|Win32 = EmuDebug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{644E4AC1-416D-4567-A68B-D66CA9FCFD9C}.Debug|Win32.ActiveCfg = Debug|Win32
{644E4AC1-416D-4567-A68B-D66CA9FCFD9C}.Debug|Win32.Build.0 = Debug|Win32
{644E4AC1-416D-4567-A68B-D66CA9FCFD9C}.EmuDebug|Win32.ActiveCfg = EmuDebug|Win32
{644E4AC1-416D-4567-A68B-D66CA9FCFD9C}.EmuDebug|Win32.Build.0 = EmuDebug|Win32
{644E4AC1-416D-4567-A68B-D66CA9FCFD9C}.Release|Win32.ActiveCfg = Release|Win32
{644E4AC1-416D-4567-A68B-D66CA9FCFD9C}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fluids_2005", "fluids_2005.vcproj", "{644E4AC1-416D-4567-A68B-D66CA9FCFD9C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
EmuDebug|Win32 = EmuDebug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{644E4AC1-416D-4567-A68B-D66CA9FCFD9C}.Debug|Win32.ActiveCfg = Debug|Win32
{644E4AC1-416D-4567-A68B-D66CA9FCFD9C}.Debug|Win32.Build.0 = Debug|Win32
{644E4AC1-416D-4567-A68B-D66CA9FCFD9C}.EmuDebug|Win32.ActiveCfg = EmuDebug|Win32
{644E4AC1-416D-4567-A68B-D66CA9FCFD9C}.EmuDebug|Win32.Build.0 = EmuDebug|Win32
{644E4AC1-416D-4567-A68B-D66CA9FCFD9C}.Release|Win32.ActiveCfg = Release|Win32
{644E4AC1-416D-4567-A68B-D66CA9FCFD9C}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -1,447 +1,447 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="fluids_2005"
ProjectGUID="{644E4AC1-416D-4567-A68B-D66CA9FCFD9C}"
RootNamespace="fluids_2005"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="fluids;common;marching;marching_tris;&quot;$(CUDA_INC_PATH)&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="cudart.lib"
LinkIncremental="2"
IgnoreDefaultLibraryNames="libcmt.lib"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="C:\CUDA\common\inc;fluids;common;marching;marching_tris"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="cudart.lib "
LinkIncremental="1"
AdditionalLibraryDirectories="C:\CUDA\common\lib;."
IgnoreDefaultLibraryNames="libcmtd.lib"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="EmuDebug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="fluids;common;marching"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="cg.lib cgGL.lib cudart.lib "
LinkIncremental="1"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(OutDir)/fluids_2005.pdb"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="common"
>
<File
RelativePath=".\common\common_defs.h"
>
</File>
<File
RelativePath=".\common\geomx.cpp"
>
</File>
<File
RelativePath=".\common\geomx.h"
>
</File>
<File
RelativePath=".\common\gl_helper.cpp"
>
</File>
<File
RelativePath=".\common\gl_helper.h"
>
</File>
<File
RelativePath=".\common\image.cpp"
>
</File>
<File
RelativePath=".\common\image.h"
>
</File>
<File
RelativePath=".\common\matrix-inline.h"
>
</File>
<File
RelativePath=".\common\matrix.cpp"
>
</File>
<File
RelativePath=".\common\matrix.h"
>
</File>
<File
RelativePath=".\common\mdebug.cpp"
>
</File>
<File
RelativePath=".\common\mdebug.h"
>
</File>
<File
RelativePath=".\common\mesh.cpp"
>
</File>
<File
RelativePath=".\common\mesh.h"
>
</File>
<File
RelativePath=".\common\mesh_info.h"
>
</File>
<File
RelativePath=".\common\mtime.cpp"
>
</File>
<File
RelativePath=".\common\mtime.h"
>
</File>
<File
RelativePath=".\common\particle.cpp"
>
</File>
<File
RelativePath=".\common\particle.h"
>
</File>
<File
RelativePath=".\common\point_set.cpp"
>
</File>
<File
RelativePath=".\common\point_set.h"
>
</File>
<File
RelativePath=".\common\vector-inline.h"
>
</File>
<File
RelativePath=".\common\vector.cpp"
>
</File>
<File
RelativePath=".\common\vector.h"
>
</File>
</Filter>
<Filter
Name="fluids"
>
<File
RelativePath=".\fluids\fluid.cpp"
>
</File>
<File
RelativePath=".\fluids\fluid.h"
>
</File>
<File
RelativePath=".\fluids\fluid_system.cpp"
>
</File>
<File
RelativePath=".\fluids\fluid_system.h"
>
</File>
<File
RelativePath=".\fluids\fluid_system_host.cu"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="&quot;$(CUDA_BIN_PATH)\nvcc.exe&quot; -arch=sm_10 -ccbin &quot;$(VCInstallDir)\bin&quot; -c -D_DEBUG -DWIN32 -D_CONSOLE -D_MBCS -Xcompiler /EHsc,/W3,/nologo,/Wp64,/Od,/Zi,/RTC1,/MTd -I &quot;$(CUDA_INC_PATH)&quot;; -I./ -o $(ConfigurationName)\fluid_system_cu.obj fluids\fluid_system_host.cu&#x0D;&#x0A;"
AdditionalDependencies="fluid_system_host.cuh; fluid_system_kern.cu;"
Outputs="$(ConfigurationName)\fluid_system_cu.obj"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="&quot;$(CUDA_BIN_PATH)\nvcc.exe&quot; -arch=sm_10 -use_fast_math -ccbin &quot;$(VCInstallDir)\bin&quot; -c -I &quot;$(CUDA_INC_PATH)&quot;; -I./ -I../../common/inc -o $(ConfigurationName)\fluid_system_cu.obj fluids\fluid_system_host.cu&#x0D;&#x0A;"
AdditionalDependencies="fluid_system_host.cuh; fluid_system_kern.cu; radixsort.cu"
Outputs="$(ConfigurationName)\fluid_system_cu.obj"
/>
</FileConfiguration>
<FileConfiguration
Name="EmuDebug|Win32"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="&quot;$(CUDA_BIN_PATH)\nvcc.exe&quot; -arch=sm_10 -ccbin &quot;$(VCInstallDir)\bin&quot; -deviceemu -c -D_DEBUG -DWIN32 -D_CONSOLE -D_MBCS -Xcompiler /EHsc,/W3,/nologo,/Wp64,/Od,/Zi,/RTC1,/MTd -I &quot;$(CUDA_INC_PATH)&quot;; -I./ -o $(ConfigurationName)\fluid_system_cu.obj fluids\fluid_system_host.cu&#x0D;&#x0A;"
AdditionalDependencies="fluid_system_host.cuh; fluid_system_kern.cu;"
Outputs="$(ConfigurationName)\fluid_system_cu.obj"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\fluids\fluid_system_host.cuh"
>
</File>
<File
RelativePath=".\fluids\fluid_system_kern.cu"
>
</File>
</Filter>
<Filter
Name="radix_sort"
>
<File
RelativePath=".\radixsort.cu"
>
</File>
<File
RelativePath=".\radixsort.cuh"
>
</File>
<File
RelativePath=".\radixsort_kernel.cu"
>
</File>
</Filter>
<File
RelativePath=".\common\GLee.c"
>
</File>
<File
RelativePath=".\common\GLee.h"
>
</File>
<File
RelativePath=".\main.cpp"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="fluids_2005"
ProjectGUID="{644E4AC1-416D-4567-A68B-D66CA9FCFD9C}"
RootNamespace="fluids_2005"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="fluids;common;marching;marching_tris;&quot;$(CUDA_INC_PATH)&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="cudart.lib"
LinkIncremental="2"
IgnoreDefaultLibraryNames="libcmt.lib"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="C:\CUDA\common\inc;fluids;common;marching;marching_tris"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="cudart.lib "
LinkIncremental="1"
AdditionalLibraryDirectories="C:\CUDA\common\lib;."
IgnoreDefaultLibraryNames="libcmtd.lib"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="EmuDebug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="fluids;common;marching"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="cg.lib cgGL.lib cudart.lib "
LinkIncremental="1"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(OutDir)/fluids_2005.pdb"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="common"
>
<File
RelativePath=".\common\common_defs.h"
>
</File>
<File
RelativePath=".\common\geomx.cpp"
>
</File>
<File
RelativePath=".\common\geomx.h"
>
</File>
<File
RelativePath=".\common\gl_helper.cpp"
>
</File>
<File
RelativePath=".\common\gl_helper.h"
>
</File>
<File
RelativePath=".\common\image.cpp"
>
</File>
<File
RelativePath=".\common\image.h"
>
</File>
<File
RelativePath=".\common\matrix-inline.h"
>
</File>
<File
RelativePath=".\common\matrix.cpp"
>
</File>
<File
RelativePath=".\common\matrix.h"
>
</File>
<File
RelativePath=".\common\mdebug.cpp"
>
</File>
<File
RelativePath=".\common\mdebug.h"
>
</File>
<File
RelativePath=".\common\mesh.cpp"
>
</File>
<File
RelativePath=".\common\mesh.h"
>
</File>
<File
RelativePath=".\common\mesh_info.h"
>
</File>
<File
RelativePath=".\common\mtime.cpp"
>
</File>
<File
RelativePath=".\common\mtime.h"
>
</File>
<File
RelativePath=".\common\particle.cpp"
>
</File>
<File
RelativePath=".\common\particle.h"
>
</File>
<File
RelativePath=".\common\point_set.cpp"
>
</File>
<File
RelativePath=".\common\point_set.h"
>
</File>
<File
RelativePath=".\common\vector-inline.h"
>
</File>
<File
RelativePath=".\common\vector.cpp"
>
</File>
<File
RelativePath=".\common\vector.h"
>
</File>
</Filter>
<Filter
Name="fluids"
>
<File
RelativePath=".\fluids\fluid.cpp"
>
</File>
<File
RelativePath=".\fluids\fluid.h"
>
</File>
<File
RelativePath=".\fluids\fluid_system.cpp"
>
</File>
<File
RelativePath=".\fluids\fluid_system.h"
>
</File>
<File
RelativePath=".\fluids\fluid_system_host.cu"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="&quot;$(CUDA_BIN_PATH)\nvcc.exe&quot; -arch=sm_10 -ccbin &quot;$(VCInstallDir)\bin&quot; -c -D_DEBUG -DWIN32 -D_CONSOLE -D_MBCS -Xcompiler /EHsc,/W3,/nologo,/Wp64,/Od,/Zi,/RTC1,/MTd -I &quot;$(CUDA_INC_PATH)&quot;; -I./ -o $(ConfigurationName)\fluid_system_cu.obj fluids\fluid_system_host.cu&#x0D;&#x0A;"
AdditionalDependencies="fluid_system_host.cuh; fluid_system_kern.cu;"
Outputs="$(ConfigurationName)\fluid_system_cu.obj"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="&quot;$(CUDA_BIN_PATH)\nvcc.exe&quot; -arch=sm_10 -use_fast_math -ccbin &quot;$(VCInstallDir)\bin&quot; -c -I &quot;$(CUDA_INC_PATH)&quot;; -I./ -I../../common/inc -o $(ConfigurationName)\fluid_system_cu.obj fluids\fluid_system_host.cu&#x0D;&#x0A;"
AdditionalDependencies="fluid_system_host.cuh; fluid_system_kern.cu; radixsort.cu"
Outputs="$(ConfigurationName)\fluid_system_cu.obj"
/>
</FileConfiguration>
<FileConfiguration
Name="EmuDebug|Win32"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="&quot;$(CUDA_BIN_PATH)\nvcc.exe&quot; -arch=sm_10 -ccbin &quot;$(VCInstallDir)\bin&quot; -deviceemu -c -D_DEBUG -DWIN32 -D_CONSOLE -D_MBCS -Xcompiler /EHsc,/W3,/nologo,/Wp64,/Od,/Zi,/RTC1,/MTd -I &quot;$(CUDA_INC_PATH)&quot;; -I./ -o $(ConfigurationName)\fluid_system_cu.obj fluids\fluid_system_host.cu&#x0D;&#x0A;"
AdditionalDependencies="fluid_system_host.cuh; fluid_system_kern.cu;"
Outputs="$(ConfigurationName)\fluid_system_cu.obj"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\fluids\fluid_system_host.cuh"
>
</File>
<File
RelativePath=".\fluids\fluid_system_kern.cu"
>
</File>
</Filter>
<Filter
Name="radix_sort"
>
<File
RelativePath=".\radixsort.cu"
>
</File>
<File
RelativePath=".\radixsort.cuh"
>
</File>
<File
RelativePath=".\radixsort_kernel.cu"
>
</File>
</Filter>
<File
RelativePath=".\common\GLee.c"
>
</File>
<File
RelativePath=".\common\GLee.h"
>
</File>
<File
RelativePath=".\main.cpp"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

File diff suppressed because it is too large Load Diff