
14.05.2025, 22:33
|
|
Познающий
Регистрация: 23.05.2024
Сообщений: 42
С нами:
1042221
Репутация:
8
|
|
C++:
Код:
#include
bool
IsPointInFrontOfCamera
(
const
CVector
&
cameraPos
,
const
CVector
&
cameraForward
,
const
CVector
&
targetPos
)
{
CVector directionToTarget
=
targetPos
-
cameraPos
;
directionToTarget
.
Normalize
(
)
;
return
(
cameraForward
.
x
*
directionToTarget
.
x
+
cameraForward
.
y
*
directionToTarget
.
y
+
cameraForward
.
z
*
directionToTarget
.
z
)
>
0.1f
;
}
ImVec2
CalculateEdgePosition
(
const
CVector
&
targetPos
,
const
CVector
&
cameraPos
,
const
CVector
&
cameraForward
,
ImVec2 screenSize
)
{
const
float
margin
=
10.0f
;
const
float
imageSize
=
32.0f
;
bool
isInFront
=
IsPointInFrontOfCamera
(
cameraPos
,
cameraForward
,
targetPos
)
;
CVector dirToTarget
=
targetPos
-
cameraPos
;
dirToTarget
.
Normalize
(
)
;
CVector2D
screenDir
(
dirToTarget
.
x
,
dirToTarget
.
y
)
;
float
aspectRatio
=
screenSize
.
x
/
screenSize
.
y
;
ImVec2
screenCenter
(
screenSize
.
x
*
0.5f
,
screenSize
.
y
*
0.5f
)
;
ImVec2 projectedPoint
=
ImVec2
(
screenCenter
.
x
+
screenDir
.
x
*
screenCenter
.
x
*
aspectRatio
,
screenCenter
.
y
-
screenDir
.
y
*
screenCenter
.
y
)
;
if
(
!
isInFront
)
{
projectedPoint
.
x
=
screenCenter
.
x
*
2
-
projectedPoint
.
x
;
projectedPoint
.
y
=
screenCenter
.
y
*
2
-
projectedPoint
.
y
;
}
float
x
=
std
::
clamp
(
projectedPoint
.
x
,
margin
,
screenSize
.
x
-
margin
-
imageSize
)
;
float
y
=
std
::
clamp
(
projectedPoint
.
y
,
margin
,
screenSize
.
y
-
margin
-
imageSize
)
;
if
(
!
isInFront
)
{
x
=
(
projectedPoint
.
x
GetPosition
(
)
;
CVector cameraForward
=
pLocalPed
->
GetForward
(
)
;
CVector screenPosition
=
Utils
::
ConvertGameCoordsToScreen
(
targetPosition
)
;
ImVec2 screenSize
=
ImGui
::
GetIO
(
)
.
DisplaySize
;
bool
isInFront
=
IsPointInFrontOfCamera
(
cameraPosition
,
cameraForward
,
targetPosition
)
;
bool
isVisibleOnScreen
=
isInFront
&&
(
screenPosition
.
x
>=
0
&&
screenPosition
.
x
=
0
&&
screenPosition
.
y
AddText
(
textPos
,
IM_COL32_WHITE
,
distanse
)
;
ImVec2
imagePos
(
screenPosition
.
x
-
16.0f
,
screenPosition
.
y
+
15.0f
)
;
drawlist
->
AddImage
(
(
void
*
)
iconToolTip
,
imagePos
,
ImVec2
(
imagePos
.
x
+
32.0f
,
imagePos
.
y
+
32.0f
)
)
;
const
char
*
text
=
"Добыча камня"
;
ImVec2 text2Pos
=
ImVec2
(
screenPosition
.
x
-
ImGui
::
CalcTextSize
(
text
)
.
x
*
0.5f
,
screenPosition
.
y
+
47.0f
)
;
drawlist
->
AddText
(
text2Pos
,
IM_COL32_WHITE
,
text
)
;
ImGui
::
PopFont
(
)
;
}
else
{
ImVec2 edgePos
=
CalculateEdgePosition
(
targetPosition
,
cameraPosition
,
cameraForward
,
screenSize
)
;
drawlist
->
AddImage
(
(
void
*
)
iconToolTip
,
edgePos
,
ImVec2
(
edgePos
.
x
+
32.0f
,
edgePos
.
y
+
32.0f
)
)
;
}
ImGui
::
EndFrame
(
)
;
ImGui
::
Render
(
)
;
ImGui_ImplDX9_RenderDrawData
(
ImGui
::
GetDrawData
(
)
)
;
}
Попробуй так
|
|
|