Modify muzzle if needed to aim at whatever is straight in front of the camera. Let the caller know if we actually modified the result.
| 2159 | // Modify muzzle if needed to aim at whatever is straight in front of the camera. Let the |
| 2160 | // caller know if we actually modified the result. |
| 2161 | bool ShapeBase::getCorrectedAim(const MatrixF& muzzleMat, VectorF* result) |
| 2162 | { |
| 2163 | F32 pullInD = sFullCorrectionDistance; |
| 2164 | const F32 maxAdjD = 500; |
| 2165 | |
| 2166 | VectorF aheadVec(0, maxAdjD, 0); |
| 2167 | |
| 2168 | MatrixF camMat; |
| 2169 | Point3F camPos; |
| 2170 | |
| 2171 | F32 pos = 0; |
| 2172 | GameConnection * gc = getControllingClient(); |
| 2173 | if (gc && !gc->isFirstPerson()) |
| 2174 | pos = 1.0f; |
| 2175 | |
| 2176 | getCameraTransform(&pos, &camMat); |
| 2177 | |
| 2178 | camMat.getColumn(3, &camPos); |
| 2179 | camMat.mulV(aheadVec); |
| 2180 | Point3F aheadPoint = (camPos + aheadVec); |
| 2181 | |
| 2182 | // Should we check if muzzle point is really close to camera? Does that happen? |
| 2183 | Point3F muzzlePos; |
| 2184 | muzzleMat.getColumn(3, &muzzlePos); |
| 2185 | |
| 2186 | Point3F collidePoint; |
| 2187 | VectorF collideVector; |
| 2188 | disableCollision(); |
| 2189 | RayInfo rinfo; |
| 2190 | if (getContainer()->castRay(camPos, aheadPoint, STATIC_COLLISION_TYPEMASK|DAMAGEABLE_TYPEMASK, &rinfo) && |
| 2191 | (mDot(rinfo.point - mObjToWorld.getPosition(), mObjToWorld.getForwardVector()) > 0)) // Check if point is behind us (could happen in 3rd person view) |
| 2192 | collideVector = ((collidePoint = rinfo.point) - camPos); |
| 2193 | else |
| 2194 | collideVector = ((collidePoint = aheadPoint) - camPos); |
| 2195 | enableCollision(); |
| 2196 | |
| 2197 | // For close collision we want to NOT aim at ground since we're bending |
| 2198 | // the ray here as it is. But we don't want to pop, so adjust continuously. |
| 2199 | F32 lenSq = collideVector.lenSquared(); |
| 2200 | if (lenSq < (pullInD * pullInD) && lenSq > 0.04) |
| 2201 | { |
| 2202 | F32 len = mSqrt(lenSq); |
| 2203 | F32 mid = pullInD; // (pullInD + len) / 2.0; |
| 2204 | // This gives us point beyond to focus on- |
| 2205 | collideVector *= (mid / len); |
| 2206 | collidePoint = (camPos + collideVector); |
| 2207 | } |
| 2208 | |
| 2209 | VectorF muzzleToCollide = (collidePoint - muzzlePos); |
| 2210 | lenSq = muzzleToCollide.lenSquared(); |
| 2211 | if (lenSq > 0.04) |
| 2212 | { |
| 2213 | muzzleToCollide *= (1 / mSqrt(lenSq)); |
| 2214 | * result = muzzleToCollide; |
| 2215 | return true; |
| 2216 | } |
| 2217 | return false; |
| 2218 | } |
nothing calls this directly
no test coverage detected