fix: some file didn't have the svn:eol-style native yet
This commit is contained in:
36340
Extras/sph/common/GLee.c
36340
Extras/sph/common/GLee.c
File diff suppressed because it is too large
Load Diff
35294
Extras/sph/common/GLee.h
35294
Extras/sph/common/GLee.h
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -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"
|
||||
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
|
||||
@@ -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
@@ -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
@@ -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
Reference in New Issue
Block a user