| 107 | } |
| 108 | |
| 109 | void SampleLargeWorld::addWindMills(const PxTriangleMeshGeometry& meshGeom, BasicRandom& random, const PxBounds3& bound, PxCollection& outCollection) |
| 110 | { |
| 111 | PxPhysics& physics = getPhysics(); |
| 112 | PxMaterial& material = getDefaultMaterial(); |
| 113 | |
| 114 | const PxReal millHalfHeight = 20.0f; |
| 115 | const PxReal millRadius =9.0f; |
| 116 | const PxReal fanRadius = 22.0f; |
| 117 | const PxReal fanWidth = 3.0f; |
| 118 | const PxReal fanThin = 0.5f; |
| 119 | const PxReal axisHalfHeight = 5.0f; |
| 120 | const PxReal axisRadius = 1.0f; |
| 121 | const PxVec3 millExtent( |
| 122 | millRadius*0.5f + axisHalfHeight + axisRadius + fanThin, |
| 123 | fanRadius*0.5f + millRadius + millHalfHeight, |
| 124 | millRadius*0.5f + axisHalfHeight + axisRadius + fanThin |
| 125 | ) ; |
| 126 | |
| 127 | PxBounds3 millBornBound = bound; |
| 128 | millBornBound.fattenFast(-millRadius*2.0f); |
| 129 | |
| 130 | //Store mill position to check if new mill is overlaped with old mills |
| 131 | PxVec3 millPts[5]; |
| 132 | |
| 133 | PxU32 mills = 0, retryNum = 1; |
| 134 | do |
| 135 | { |
| 136 | //Raycast against terrain from random pos to get mill foot point |
| 137 | PxVec3 rayStart( |
| 138 | random.rand( millBornBound.minimum.x, millBornBound.maximum.x), |
| 139 | bound.maximum.y, |
| 140 | random.rand( millBornBound.minimum.z, millBornBound.maximum.z)); |
| 141 | |
| 142 | PxReal maxDist = 2*(bound.maximum.y - bound.minimum.y); |
| 143 | |
| 144 | PxRaycastHit hit; |
| 145 | |
| 146 | PxU32 hitsNum = PxGeometryQuery::raycast( |
| 147 | rayStart, PxVec3(0.0f,-1.0f,0.0f), |
| 148 | meshGeom, PxTransform(PxIdentity), maxDist, |
| 149 | PxHitFlag::ePOSITION, 1, &hit); |
| 150 | |
| 151 | if( hitsNum ) |
| 152 | { |
| 153 | PxVec3 millPt = hit.position; |
| 154 | millPt.y += millHalfHeight - millRadius; |
| 155 | |
| 156 | PxVec3 axisPt = millPt; |
| 157 | axisPt.y += millHalfHeight + millRadius; |
| 158 | axisPt.x += millRadius; |
| 159 | |
| 160 | PxVec3 fanPt = axisPt; |
| 161 | fanPt.x += axisHalfHeight; |
| 162 | |
| 163 | //Roughly check if fans of mill collided with terrain |
| 164 | PxQueryFilterData filter( PxQueryFlag::eANY_HIT); |
| 165 | PxOverlapBuffer buf; |
| 166 | PxBoxGeometry fanBox(fanThin, fanRadius, fanRadius); |
nothing calls this directly
no test coverage detected