• Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

We're also offering banner ads on our site from just \$5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.

# Gammastrahler

Member Since 12 Apr 2001
Offline Last Active Jul 13 2014 03:29 PM

### BSP Tree Question

13 July 2014 - 04:33 AM

Hi,

i want to use a BSP tree for processing boolean operations on solids (CSG).

In theory, i have understood the algorithm, but what actually confuses me is the step when selecting the splitting polygons for the BSP construction process. For example, if i have a cube, do i need a split plane / left and right nodes for each side of the cube?

Any help would be appreciated.

Regards

Gammastrahler

### Portal Rendering Loop

12 November 2011 - 10:00 AM

Hi,

i have read some articles about portal rendering - unfortunately, it seems there are only a few on the web.

From what i have understand i have build some code.

It would be nice if someone could review my main loop for object culling / rendering.

Short description of the code: I render the current sector (the one the viewpos is in), then iterate over each portal, clip them against the current view frustum and build a reduced view frustum from those. Finally, i render the adjacent sector, which should recursively render all sectors until all visible ones are drawn.

Is this procedure correct or are there some flaws in my code?

Gammastrahler

```void ZSector::render(const CVector3 &currPos, CFrustum &viewFrustum)
{
if (_tagged) return;

_tagged = true;

gPolysDrawn++;

// Render the current sector

std::vector<CPolygon*>::iterator pPoly = _polyList.begin();

for ( ; pPoly != _polyList.end(); ++pPoly)
{
(*pPoly)->render(currPos);
}

for (std::vector<ZPortal*>::iterator p = _portalList.begin();
p != _portalList.end(); ++p)
{
CPolygon clippedPortal = (*p)->_poly;

// If the portal is not within the current view frustum, ignore it

if (!viewFrustum.poly_visible(clippedPortal)) continue;

// Clip the portal against each plane of our view frustum

for (int plane = 0; plane < viewFrustum._nPlanes; plane++)
{
CPolygon result[2];

if (SplitPolygon(clippedPortal, viewFrustum._planes[plane], result))
clippedPortal = result[0];
}

// Check for invalid portals

if (clippedPortal._nVerts < 3) continue;

// Remember the near and far plane

CPlane farPlane = viewFrustum._planes[viewFrustum._nPlanes-2];
CPlane nearPlane = viewFrustum._planes[viewFrustum._nPlanes-1];

viewFrustum._nPlanes = 0;

// Build the reduced view frustum from the
// new portal

for (int i = 0; i < clippedPortal._nVerts; i++)
{
CVertex v1 = clippedPortal._verts[i];
CVertex v2 = clippedPortal._verts[i+1];

if (i == clippedPortal._nVerts - 1)
v2 = clippedPortal._verts[0];

CVector3 sideNormal;

sideNormal.Cross(v2, v1);
sideNormal.normalize();

viewFrustum._planes[i]._normal = sideNormal;
viewFrustum._planes[i]._d = 0.0;

viewFrustum._nPlanes++;
}

// Reset the near and far plane

viewFrustum._planes[viewFrustum._nPlanes++] = farPlane;
viewFrustum._planes[viewFrustum._nPlanes++] = nearPlane;

}
}
```

### A problem with strcpy

18 January 2007 - 08:46 AM

Hi, in my project i need to store the memory address of strings, to access them later. for some implementation specific reasons, the code enforces that i have to store that address in a variable of an unsigned int type rather than directly in a pointer. here is an example:
```gStringPtr = new char[..];

// copy something into gStringPtr
strcpy(gStringPtr, "...");

unsigned int addr = (unsigned int)gStringPtr;

strcpy(copy, "Blabla");  // Crashes

```
The call to strcpy crashes, although it points to the correct memory address saved before. Can someone help me with this problem? I have no idea of how to solve my problem. Thanks Gammastrahler

### OOP Design Question (C++)

11 January 2007 - 03:21 AM

Hi, i´m writing a compiler for my scripting language. Currently, i design the symbol table, and i use OOP to implement it:
```class CSymbol
{
const string _name;
size_t dataSize;
CScope* _scope;
&&...
}

class CType : public CSymbol
{
bool _isArray;
bool _isPointer;
&&...
}

class CVar : public CSymbol
{
//...
}

```
The problem with this design is, that it violates the OOP rule that an abstract class should have at least one virtual method. but in my design, i don´t need any virtual methods, i only need the inheritance. Should i use another approach to implement my symbol table? The second pain in the neck is, that if i lookup specific symbols, then i always need to cast to the proper type, consider this: CSymbol *find_symbol(...); CVar* sym = static_cast<CVar*>(find_symbol(...)); it could be also a CType symbol, a CFunction, etc... to solve this problem, i could use templates, like this template <class T> T* find_symbol(...) ... But then it is no longer guaranted, that a client uses CSymbol, he could also write int i = <int>find_symbol(...); Can you give me some suggestions to redesign my classes? What way should i go? Thanks in advance for any ideas, Gammstrahler

### My Own scripting language - design?

08 January 2007 - 11:28 AM

Hi, i want to completely redesign my existing scripting language (not the syntax and functionality), but the way it is coded. I want focus on execution speed, but i think this leads to a more C-like programming style which is not as maintable and flexible (especially if i want to easy add new features), as to use object oriented class programming where i encapsulate everything in a class. what would you suggest? any ideas are welcome thanks gammastrahler

PARTNERS