trpage_nodes.cpp
来自「最新osg包」· C++ 代码 · 共 944 行 · 第 1/2 页
CPP
944 行
/* ************************ Copyright Terrain Experts Inc. Terrain Experts Inc (TERREX) reserves all rights to this source code unless otherwise specified in writing by the President of TERREX. This copyright may be updated in the future, in which case that version supercedes this one. ------------------- Terrex Experts Inc. 4400 East Broadway #314 Tucson, AZ 85711 info@terrex.com Tel: (520) 323-7990 ************************ */#include <stdlib.h>#include <stdio.h>#include <string.h>/* trpage_nodes.cpp The methods for all the hierarchy nodes (e.g. groups, transforms, etc...) is here. You should only need to modify this if you want to add something to one of these classes.*/#include <trpage_geom.h>#include <trpage_read.h>/* Write Group Basic group.*/// ConstructortrpgGroup::trpgGroup(){ name = 0; Reset();}trpgGroup::~trpgGroup(){ Reset();}// Resetvoid trpgGroup::Reset(){ numChild = 0; id = -1; if ( name ) { delete [] name; name = 0; }}// Set functionsvoid trpgGroup::SetNumChild(int no){ numChild = no;}int trpgGroup::AddChild(){ numChild++; return numChild-1;}void trpgGroup::SetID(int inID){ id = inID;}void trpgGroup::SetName(const char* newname ){ if ( name ) { delete [] name; name = 0; } if (newname) { if ( strlen(newname) ) { name = new char[strlen(newname)+1]; strcpy(name,newname); } }}// Get methodsconst char* trpgGroup::GetName(void) const{ return name;}bool trpgGroup::GetNumChild(int &n) const{ if (!isValid()) return false; n = numChild; return true;}bool trpgGroup::GetID(int &inID) const{ if (!isValid()) return false; inID = id; return true;}// Validity checkbool trpgGroup::isValid() const{ if (numChild <= 0) return false; if (id < 0) return false; return true;}// Write groupbool trpgGroup::Write(trpgWriteBuffer &buf){ if (!isValid()) return false; buf.Begin(TRPG_GROUP); buf.Add(numChild); buf.Add(id); if ( name && strlen(name) ) { buf.Add(name); } buf.End(); return true;}// Read groupbool trpgGroup::Read(trpgReadBuffer &buf){ try { buf.Get(numChild); if (numChild < 0) throw 1; buf.Get(id); if (id < 0) throw 1; if ( !buf.isEmpty() ) { char nm[1024] = {0}; buf.Get(nm,1024); SetName(nm); } } catch (...) { return false; } return isValid();}/* Write Billboard Represents rotational billboarded geometry.*/// ConstructortrpgBillboard::trpgBillboard(){ name = 0; Reset();}trpgBillboard::~trpgBillboard(){ Reset();}// Reset functionvoid trpgBillboard::Reset(){ id = -1; mode = Axial; type = Group; axis = trpg3dPoint(0,0,1); center = trpg3dPoint(0,0,0); numChild = 0; if ( name ) { delete [] name; name = 0; }}// Set functionsvoid trpgBillboard::SetCenter(const trpg3dPoint &pt){ center = pt; valid = true;}void trpgBillboard::SetMode(int m){ mode = m;}void trpgBillboard::SetAxis(const trpg3dPoint &pt){ axis = pt;}void trpgBillboard::SetType(int t){ type = t;}// Get methodsbool trpgBillboard::GetCenter(trpg3dPoint &pt) const{ if (!isValid()) return false; pt = center; return true;}bool trpgBillboard::GetMode(int &m) const{ if (!isValid()) return false; m = mode; return true;}bool trpgBillboard::GetAxis(trpg3dPoint &pt) const{ if (!isValid()) return false; pt = axis; return true;}bool trpgBillboard::GetType(int &t) const{ if (!isValid()) return false; t = type; return true;}// Write billboardbool trpgBillboard::Write(trpgWriteBuffer &buf){ if (!isValid()) return false; buf.Begin(TRPG_BILLBOARD); buf.Add(numChild); buf.Add(id); buf.Add((uint8)type); buf.Add((uint8)mode); buf.Add(center); buf.Add(axis); if ( name && strlen(name) ) { buf.Add(name); } buf.End(); return true;}// Read billboardbool trpgBillboard::Read(trpgReadBuffer &buf){ uint8 uChar; try { buf.Get(numChild); buf.Get(id); buf.Get(uChar); type = uChar; buf.Get(uChar); mode = uChar; buf.Get(center); buf.Get(axis); if ( !buf.isEmpty() ) { char nm[1024] = {0}; buf.Get(nm,1024); SetName(nm); } } catch (...) { return false; } return isValid();}/* Write Level of Detail Represents LOD information.*/// ConstructortrpgLod::trpgLod(){ name = 0; Reset();}trpgLod::~trpgLod(){ Reset();}// Reset functionvoid trpgLod::Reset(){ id = -1; numRange = 0; center = trpg3dPoint(0,0,0); switchIn = switchOut = width = 0; rangeIndex = -1; valid = true; if ( name ) { delete [] name; name = 0; }}// Set functionsvoid trpgLod::SetCenter(const trpg3dPoint &pt){ center = pt; valid = true;}void trpgLod::SetNumChild(int no){ if (no < 0) return; numRange = no;}void trpgLod::SetLOD(double in,double out,double wid){ switchIn = in; switchOut = out; width = wid;}void trpgLod::SetID(int inID){ id = inID;}void trpgLod::SetName(const char* newname ){ if ( name ) { delete [] name; name = 0; } if (newname) { if ( strlen(newname) ) { name = new char[strlen(newname)+1]; strcpy(name,newname); } }}void trpgLod::SetRangeIndex(int ri){ rangeIndex = ri;}// Get methodsconst char* trpgLod::GetName(void) const{ return name;}// Get functionsbool trpgLod::GetCenter(trpg3dPoint &pt) const{ if (!isValid()) return false; pt = center; return true;}bool trpgLod::GetNumChild(int &n) const{ if (!isValid()) return false; n = numRange; return true;}bool trpgLod::GetLOD(double &in,double &out,double &wid) const{ if (!isValid()) return false; in = switchIn; out = switchOut; wid = width; return true;}bool trpgLod::GetID(int &outID) const{ if (!isValid()) return false; outID = id; return true;}bool trpgLod::GetRangeIndex(int &ri) const{ if (!isValid()) return false; ri = rangeIndex; return true;}// Write out LODbool trpgLod::Write(trpgWriteBuffer &buf){ if (!isValid()) return false; buf.Begin(TRPG_LOD); buf.Add(id); buf.Add(numRange); buf.Add(center); buf.Add(switchIn); buf.Add(switchOut); buf.Add(width); if ( name && strlen(name) ) { buf.Add(name); } else buf.Add(""); buf.End(); return true;}// Read in LODbool trpgLod::Read(trpgReadBuffer &buf){ try { buf.Get(id); buf.Get(numRange); if (numRange < 0) throw 1; buf.Get(center); buf.Get(switchIn); buf.Get(switchOut); buf.Get(width); if ( !buf.isEmpty() ) { char nm[1024] = {0}; buf.Get(nm,1024); if (*nm) SetName(nm); // Look for a range index if (!buf.isEmpty()) buf.Get(rangeIndex); } } catch (...) { return false; } return isValid();}/* Write Layer A layer is just a group with a different opcode.*/// ConstructortrpgLayer::trpgLayer(){ name = 0;}trpgLayer::~trpgLayer(){ Reset();}// Write itbool trpgLayer::Write(trpgWriteBuffer &buf){ if (!isValid()) return false; buf.Begin(TRPG_LAYER); buf.Add(numChild); buf.Add(id);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?