MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / strikeRandomPoint

Method strikeRandomPoint

Engine/source/T3D/fx/lightning.cpp:771–883  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

769}
770
771void Lightning::strikeRandomPoint()
772{
773 AssertFatal(isServerObject(), "Error, client objects may not initiate lightning!");
774
775
776 Point3F strikePoint( gRandGen.randF( 0.0f, 1.0f ), gRandGen.randF( 0.0f, 1.0f ), 0.0f );
777
778 // check if an object is within target range
779 Point3F worldPosStrikePoint = strikePoint;
780
781 worldPosStrikePoint *= mObjScale;
782 worldPosStrikePoint += getPosition();
783 worldPosStrikePoint += Point3F( -mObjScale.x * 0.5f, -mObjScale.y * 0.5f, 0.0f );
784
785 Box3F queryBox;
786 F32 boxWidth = strikeRadius * 2.0f;
787
788 queryBox.minExtents.set( -boxWidth * 0.5f, -boxWidth * 0.5f, -mObjScale.z * 0.5f );
789 queryBox.maxExtents.set( boxWidth * 0.5f, boxWidth * 0.5f, mObjScale.z * 0.5f );
790 queryBox.minExtents += worldPosStrikePoint;
791 queryBox.maxExtents += worldPosStrikePoint;
792
793 SimpleQueryList sql;
794 getContainer()->findObjects(queryBox, DAMAGEABLE_TYPEMASK,
795 SimpleQueryList::insertionCallback, &sql);
796
797 SceneObject *highestObj = NULL;
798 F32 highestPnt = 0.0f;
799
800 for( U32 i = 0; i < sql.mList.size(); i++ )
801 {
802 Point3F objectCenter;
803 sql.mList[i]->getObjBox().getCenter(&objectCenter);
804 objectCenter.convolve(sql.mList[i]->getScale());
805 sql.mList[i]->getTransform().mulP(objectCenter);
806
807 // check if object can be struck
808
809 RayInfo rayInfo;
810 Point3F start = objectCenter;
811 start.z = mObjScale.z * 0.5f + getPosition().z;
812 Point3F end = objectCenter;
813 end.z = -mObjScale.z * 0.5f + getPosition().z;
814 bool rayHit = gServerContainer.castRay( start, end,
815 (0xFFFFFFFF),
816 &rayInfo);
817
818 if( rayHit && rayInfo.object == sql.mList[i] )
819 {
820 if( !highestObj )
821 {
822 highestObj = sql.mList[i];
823 highestPnt = objectCenter.z;
824 continue;
825 }
826
827 if( objectCenter.z > highestPnt )
828 {

Callers 1

lightning.cppFile · 0.80

Calls 15

getPositionFunction · 0.85
randFMethod · 0.80
findObjectsMethod · 0.80
mulPMethod · 0.80
postNetEventMethod · 0.80
Point3FClass · 0.50
getContainerFunction · 0.50
setMethod · 0.45
sizeMethod · 0.45
getCenterMethod · 0.45
convolveMethod · 0.45
getScaleMethod · 0.45

Tested by

no test coverage detected