Created
February 26, 2015 16:49
-
-
Save lukaspj/7be07091665c2282b142 to your computer and use it in GitHub Desktop.
Impact System T3D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add | |
// IPS SpellSystem ------ | |
void SceneContainer::initConeSearch( | |
const Point3F Start, | |
const Point3F End, | |
const F32 Radius, | |
const U32 TypeMask) | |
{ | |
cleanupSearchVectors(); | |
Point3F center = ( End - Start ) / 2; | |
mSearchReferencePoint = center; | |
VectorF direction = End - Start; | |
direction.normalize(); | |
Box3F queryBox; | |
Point3F perp1 = mPerp(direction); | |
Point3F perp2 = mCross(perp1, direction); | |
perp1.normalize(); | |
perp2.normalize(); | |
perp1 *= Radius; | |
perp2 *= Radius; | |
VectorF perp = perp1 + perp2; | |
AssertFatal( mIsZero( mDot( perp1, perp2 ) ), "ConeSearch, failed to generate perpendicular vector perp1 , perp2" ); | |
AssertFatal( mIsZero( mDot( center, perp2 ) ), "ConeSearch, failed to generate perpendicular vector center , perp2" ); | |
AssertFatal( mIsZero( mDot( perp1, center ) ), "ConeSearch, failed to generate perpendicular vector perp1, center" ); | |
Point3F startcorner = Point3F((Start - center).x - perp.x, (Start - center).y - perp.y, (Start - center).z -perp.z); | |
Point3F endcorner = Point3F((End - center).x + perp.x, (End - center).y + perp.y, (End - center).z + perp.z); | |
Point3F minCorner = Point3F(mMax(startcorner.x, endcorner.x) == startcorner.x ? endcorner.x : startcorner.x, | |
mMax(startcorner.y, endcorner.y) == startcorner.y ? endcorner.y : startcorner.y, | |
mMax(startcorner.z, endcorner.z) == startcorner.z ? endcorner.z : startcorner.z); | |
Point3F maxCorner = Point3F(mMax(startcorner.x, endcorner.x), | |
mMax(startcorner.y, endcorner.y), | |
mMax(startcorner.z, endcorner.z)); | |
queryBox.minExtents = minCorner; | |
queryBox.maxExtents = maxCorner; | |
SimpleQueryList queryList; | |
gServerContainer.findObjects(queryBox, TypeMask, SimpleQueryList::insertionCallback, &queryList); | |
Vector<PlaneF> planes; | |
Polyhedron ConePoly; | |
ConePoly.pointList.setSize(9); | |
ConePoly.pointList[0] = Start; | |
ConePoly.planeList.setSize(8); | |
U8 resolution = 8; | |
for(int ix = 0; ix < resolution; ix++) | |
{ | |
Point3F p1,p2; | |
F32 cAngle1 = cos((360/resolution*ix)*M_PI/180); | |
F32 sAngle1 = sin((360/resolution*ix)*M_PI/180); | |
F32 cAngle2 = cos((360/resolution*ix+1)*M_PI/180); | |
F32 sAngle2 = sin((360/resolution*ix+1)*M_PI/180); | |
p1 = End+((perp1 * cAngle1) + (perp2 * sAngle1)); | |
p2 = End+((perp1 * cAngle2) + (perp2 * sAngle2)); | |
ConePoly.pointList[ix+1] = p1; | |
PlaneF plane(Start, p1, p2); | |
ConePoly.planeList[ix] = plane; | |
planes.push_back(plane); | |
/* Debug drawing of the cone | |
* DebugDrawer::get()->drawTri(Start, p1, p2, ColorI(gRandGen.randI() % 256, gRandGen.randI() % 256, gRandGen.randI() % 256)); | |
* DebugDrawer::get()->setLastTTL(5000); | |
*/ | |
} | |
Point3F p1,p2,p3; | |
F32 cAngle1 = cos((360/resolution*1)*M_PI/180); | |
F32 sAngle1 = sin((360/resolution*1)*M_PI/180); | |
F32 cAngle2 = cos((360/resolution*2)*M_PI/180); | |
F32 sAngle2 = sin((360/resolution*2)*M_PI/180); | |
F32 cAngle3 = cos((360/resolution*3)*M_PI/180); | |
F32 sAngle3 = sin((360/resolution*4)*M_PI/180); | |
p1 = End+((perp1 * cAngle1) + (perp2 * sAngle1)); | |
p2 = End+((perp1 * cAngle2) + (perp2 * sAngle2)); | |
p3 = End+((perp1 * cAngle3) + (perp2 * sAngle3)); | |
PlaneF frontPlane(p1,p2,p3); | |
planes.push_back(frontPlane); | |
PlaneSetF planeSet(planes.address(),9); | |
ConePoly.buildFromPlanes(planeSet); | |
gServerContainer.polyhedronFindObjects(ConePoly, TypeMask, SimpleQueryList::insertionCallback, &queryList); | |
for (U32 i = 0; i < queryList.mList.size(); i++) | |
{ | |
mSearchList.push_back(new SimObjectPtr<SceneObject>); | |
*(mSearchList.last()) = queryList.mList[i]; | |
} | |
if (mSearchList.size() != 0) | |
{ | |
sgSortReferencePoint = mSearchReferencePoint; | |
dQsort(mSearchList.address(), mSearchList.size(), | |
sizeof(SimObjectPtr<SceneObject>*), cmpSearchPointers); | |
} | |
} | |
void SceneContainer::initBoxSearch( | |
const Point3F Start, | |
const Point3F End, | |
const U32 TypeMask) | |
{ | |
cleanupSearchVectors(); | |
Point3F center = ( End - Start ) / 2; | |
mSearchReferencePoint = center; | |
Box3F queryBox; | |
Point3F startcorner = Point3F((Start - center).x, (Start - center).y, (Start - center).z); | |
Point3F endcorner = Point3F((End - center).x, (End - center).y, (End - center).z); | |
Point3F minCorner = Point3F(mMax(startcorner.x, endcorner.x) == startcorner.x ? endcorner.x : startcorner.x, | |
mMax(startcorner.y, endcorner.y) == startcorner.y ? endcorner.y : startcorner.y, | |
mMax(startcorner.z, endcorner.z) == startcorner.z ? endcorner.z : startcorner.z); | |
Point3F maxCorner = Point3F(mMax(startcorner.x, endcorner.x), | |
mMax(startcorner.y, endcorner.y), | |
mMax(startcorner.z, endcorner.z)); | |
queryBox.minExtents = minCorner; | |
queryBox.maxExtents = maxCorner; | |
SimpleQueryList queryList; | |
gServerContainer.findObjects(queryBox, TypeMask, SimpleQueryList::insertionCallback, &queryList); | |
for (U32 i = 0; i < queryList.mList.size(); i++) | |
{ | |
mSearchList.push_back(new SimObjectPtr<SceneObject>); | |
*(mSearchList.last()) = queryList.mList[i]; | |
} | |
if (mSearchList.size() != 0) | |
{ | |
sgSortReferencePoint = mSearchReferencePoint; | |
dQsort(mSearchList.address(), mSearchList.size(), | |
sizeof(SimObjectPtr<SceneObject>*), cmpSearchPointers); | |
} | |
} | |
void SceneContainer::initCubeSearch( | |
const Point3F Center, | |
const F32 Size, | |
const U32 TypeMask) | |
{ | |
cleanupSearchVectors(); | |
mSearchReferencePoint = Center; | |
Box3F queryBox; | |
queryBox.minExtents -= Point3F(Size); | |
queryBox.maxExtents += Point3F(Size); | |
SimpleQueryList queryList; | |
gServerContainer.findObjects(queryBox, TypeMask, SimpleQueryList::insertionCallback, &queryList); | |
for (U32 i = 0; i < queryList.mList.size(); i++) | |
{ | |
mSearchList.push_back(new SimObjectPtr<SceneObject>); | |
*(mSearchList.last()) = queryList.mList[i]; | |
} | |
if (mSearchList.size() != 0) | |
{ | |
sgSortReferencePoint = mSearchReferencePoint; | |
dQsort(mSearchList.address(), mSearchList.size(), | |
sizeof(SimObjectPtr<SceneObject>*), cmpSearchPointers); | |
} | |
} | |
// ------ IPS SpellSystem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// After | |
void initTypeSearch(const U32 searchMask); | |
// Add: | |
// IPS SpellSystem ------ | |
void initConeSearch( | |
const Point3F Start, | |
const Point3F End, | |
const F32 Radius, | |
const U32 TypeMask); | |
void initBoxSearch( | |
const Point3F Start, | |
const Point3F End, | |
const U32 TypeMask); | |
void initCubeSearch( | |
const Point3F Center, | |
const F32 Size, | |
const U32 TypeMask); | |
// ------ IPS SpellSystem |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment