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

Method strikeRandomPoint

Engine/source/T3D/fx/lightning.cpp:755–867  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

lightning.cppFile · 0.80

Calls 15

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
getTransformMethod · 0.45

Tested by

no test coverage detected