MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / CheckCursorTarget

Method CheckCursorTarget

engine/Poseidon/UI/InGame/InGameUIMenuSim.cpp:178–366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176 }
177 }
178}
179
180Target* InGameUI::CheckCursorTarget(Vector3& itPos, Vector3Par cursorDir, const Camera& camera, CameraType cam,
181 bool knownOnly)
182{
183 AIUnit* unit = GWorld->FocusOn();
184 AISubgroup* subgroup = unit->GetSubgroup();
185 AIGroup* group = subgroup->GetGroup();
186 EntityAI* vehicle = unit->GetVehicle();
187
188 float maxVisDist = floatMax(vehicle->GetType()->GetIRScanRange(), TACTICAL_VISIBILITY);
189
190 CollisionBuffer retVal;
191 GLandscape->ObjectCollision(retVal, vehicle, nullptr, camera.Position(), camera.Position() + cursorDir * maxVisDist,
192 0, ObjIntersectView);
193 // select first intersected object
194 int minI = -1;
195 float minT = 1e10;
196 for (int i = 0; i < retVal.Size(); i++)
197 {
198 const CollisionInfo& info = retVal[i];
199 if (!info.object)
200 {
201 continue;
202 }
203 if (info.under < minT)
204 {
205 minT = info.under;
206 minI = i;
207 }
208 }
209 Target* iTarget = nullptr;
210
211 itPos = camera.Position();
212
213#if 1
214 if (minI >= 0)
215 {
216 // check intersection with land
217 const CollisionInfo& info = retVal[minI];
218 EntityAI* ai = dyn_cast<EntityAI, Object>(info.object);
219 if (ai)
220 {
221 Vector3 iPos = info.object->WorldTransform().FastTransform(info.pos);
222 Vector3 iDir = iPos - camera.Position();
223 Vector3 iDirN = iDir.Normalized();
224 float iDirSize = iDir * iDirN;
225 Vector3 lPos;
226 float isect = GLandscape->IntersectWithGroundOrSea(&lPos, camera.Position(), iDirN, 0, iDirSize * 1.1);
227 // we know what is
228
229 if (isect > iDirSize)
230 {
231 // no ground obstacle
232 // check if we know the target
233 if (knownOnly)
234 {
235 iTarget = group->FindTarget(ai);

Callers

nothing calls this directly

Calls 15

floatMaxFunction · 0.85
saturateMaxFunction · 0.85
FocusOnMethod · 0.80
GetIRScanRangeMethod · 0.80
ObjectCollisionMethod · 0.80
FindTargetAllMethod · 0.80
GetCameraTypeMethod · 0.80
IsKindOfMethod · 0.80
IsKnownByMethod · 0.80
GetIRTargetMethod · 0.80
GeometrySphereMethod · 0.80

Tested by

no test coverage detected