ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


functions:hudlib

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
functions:hudlib [2016/05/07 17:28] korshunfunctions:hudlib [2016/10/16 13:29] – [Hudlib] korshun
Line 6: Line 6:
  
 Only drawing functions actually draw stuff. All other functions only manipulate render state. Only drawing functions actually draw stuff. All other functions only manipulate render state.
 +
 +Drawing functions change ZDoom's global message settings ([[zdoom>SetHudSize]] and [[zdoom>SetFont]]) every time they are called. Other functions do not touch them.
 +
 +===== Examples =====
 +
 +==== Simple 2D drawing ====
 +
 +<code>
 +HudSetPoint(320.0, 240.0);
 +HudDrawText(1, "Hello!");
 +</code>
 +
 +==== Simple 3D drawing ====
 +
 +<code>
 +HudSetCameraActor(0);
 +HudSetPoint3D(0.0, 0.0, 0.0);
 +HudDrawText(2, "This is the center of the map!");
 +</code>
  
 ===== Virtual screen size ===== ===== Virtual screen size =====
Line 11: Line 30:
 These functions replace ''[[zdoom>SetHudSize]]''. They work exactly the same, but hudlib needs to wrap ''SetHudSize'' for message scaling. These functions replace ''[[zdoom>SetHudSize]]''. They work exactly the same, but hudlib needs to wrap ''SetHudSize'' for message scaling.
  
-<note important>The virtual screen size does **not** affect the size of **distance-scaled** 3D messages.</note>+<note important>Virtual screen size affects the size of 3D messages.</note>
  
 ==== HudSetVirtualSize ==== ==== HudSetVirtualSize ====
 ''void HudSetVirtualSize(fixed width, fixed height)'' ''void HudSetVirtualSize(fixed width, fixed height)''
  
-Sets the virtual screen size to the given dimensions. The default size is 640x480. This works exactly like ''SetHudSize''.+Sets the virtual screen size to the given dimensions. The default size is 640x480. This works exactly like ''[[zdoom>SetHudSize]]''.
  
 ==== HudUseRealSize ==== ==== HudUseRealSize ====
Line 32: Line 51:
  
 Controls whether the statusbar area should be included into the virtual screen. This corresponds to the third parameter of ''[[zdoom>SetHudSize]]'' Controls whether the statusbar area should be included into the virtual screen. This corresponds to the third parameter of ''[[zdoom>SetHudSize]]''
 +
 +===== Widescreen support =====
 +
 +==== Hud boundaries ====
 +''fixed HudLeft()''
 +
 +''fixed HudRight()''
 +
 +''fixed HudTop()''
 +
 +''fixed HudBottom()''
 +
 +Return the boundaries of the screen for current virtual screen size, accounting for current **physical** aspect ratio. Equivalent to adding or subtracting a hud border manually.
 +
 +**Example**
 +
 +<code>
 +// This message will stick to the left border of the screen (with a gap), even in widescren.
 +HudSetPoint(HudLeft() + 3.0, 240.0);
 +</code>
 +
 +==== Hud borders ====
 +''fixed HudBorderX()''
 +
 +''fixed HudBorderY()''
 +
 +Return hud borders for current virtual screen size, accounting for current **physical** aspect ratio.
  
 ===== 2D positioning ===== ===== 2D positioning =====
Line 208: Line 254:
 ''void HudSetShowToEveryone(bool showToEveryone)'' ''void HudSetShowToEveryone(bool showToEveryone)''
  
-If set to true, the message will be shown to everyone, and not just to the activator. This settings toggles between ''[[zdoom>HudMessage]]'' and ''[[zdoom>HudMessageBold]]'' in hudlib.+If set to true, the message will be shown to everyone, and not just to the activator. This setting toggles between ''[[zdoom>HudMessage]]'' and ''[[zdoom>HudMessageBold]]'' in hudlib.
  
 ==== HudSetLayer ==== ==== HudSetLayer ====
Line 240: Line 286:
 ===== 3D Camera position ===== ===== 3D Camera position =====
  
-Default camera position is (000).+==== HudSetCameraPosition ==== 
 +''void HudSetCameraPosition(fixed xfixed yfixed z)''
  
-Default camera direction is the world X axis.+Sets the position of the camera from which 3D messages will be viewed. 
 + 
 +Default: (0, 0, 0). 
 + 
 +==== HudSetCameraAngles ==== 
 +''void HudSetCameraAngles(fixed angle, fixed pitch)'' 
 + 
 +Sets the direction of the camera through which 3D messages will be viewed. The direction is specified as a pair of angles. 
 + 
 +Default: (0, 0). 
 + 
 +<note important>Remember that actor pitch in ZDoom is inverted.</note> 
 + 
 +<note tip>If you want to do ''HudSetCameraAngles(GetActorAngle(tid), -GetActorPitch(tid))'', use ''HudSetCameraActor(tid)'' instead.</note>
  
 ==== HudSetCameraActor ==== ==== HudSetCameraActor ====
 ''void HudSetCameraActor(int tid)'' ''void HudSetCameraActor(int tid)''
 +
 +Reads the actor's position and direction and automatically sets up the camera using the functions above.
  
 ==== HudSetCameraActorAdvanced ==== ==== HudSetCameraActorAdvanced ====
-''void HudSetCameraActor(int tid, fixed offsetX, fixed offsetY, fixed offsetZ, int flags)''+''void HudSetCameraActor(int tid, int flags)'' 
 + 
 +Same as ''HudSetCameraActor'', but with flags to turn off various features: 
 +  * ''HUD_CAMERAACTOR_NOPOSITION'' -- do not set the camera's position 
 +  * ''HUD_CAMERAACTOR_NOPREDICTION'' -- do not take the actor's velocity into account when setting the camera position. 
 +  * ''HUD_CAMERAACTOR_NODIRECTION'' -- do not set the direction of the camera based on the actor's angle and pitch 
 +  * ''HUD_CAMERAACTOR_NOVIEWHEIGHT'' -- do not take into account the view height of the actor when setting the camera's position.
  
 ===== 3D Message position ===== ===== 3D Message position =====
- 
-Default camera position is (0, 0, 0). 
- 
-Default 2D offset for 3D messages is (0, 0). 
- 
-There is no default 3D position as messages are drawn in 2D by default. 
  
 ==== HudSetPoint3D ==== ==== HudSetPoint3D ====
 ''void HudSetPoint3D(fixed x, fixed y, fixed z)'' ''void HudSetPoint3D(fixed x, fixed y, fixed z)''
  
-==== HudSetPointActor ==== +Sets the point at which the 3D message will be drawn. The next message drawn will be 3D. 
-''void HudSetPointActor(int tid, fixed offsetX, fixed offsetY, fixed offsetZ)''+ 
 +Default: none.
  
 ==== HudSet2DOffset ==== ==== HudSet2DOffset ====
 ''void HudSet2DOffset(fixed x, fixed y)'' ''void HudSet2DOffset(fixed x, fixed y)''
  
-===== 3D Distance =====+Sets the 2D offset of the 3D message relative to the projected point.
  
-Automatic distance scaling is OFF by default.+Default: (0, 0). 
 + 
 +===== 3D Projection ===== 
 + 
 +==== HudSetProjectionMode ==== 
 +''void HudSetProjectionMode(int mode)'' 
 + 
 +Sets the method to use when projecting 3D points to the screen. 
 + 
 +Available modes are: 
 +  * ''HUD_PROJECTION_AUTO'' -- use Y-shearing projection in Software renderer and true 3D projection in OpenGL (renderer is determined using ''IsOpenGL()''). 
 +  * ''HUD_PROJECTION_YSHEARING'' -- always use Y-shearing projection 
 +  * ''HUD_PROJECTION_3D'' -- always use true 3D projection 
 + 
 +===== 3D Distance =====
  
 ==== HudSetAutoDistanceScale ==== ==== HudSetAutoDistanceScale ====
 ''void HudSetAutoDistanceScale(bool autoDistanceScale)'' ''void HudSetAutoDistanceScale(bool autoDistanceScale)''
 +
 +If enabled, the message will be automatically scaled based on distance to the camera plane.
 +
 +Default: true.
  
 ==== HudGetDistance ==== ==== HudGetDistance ====
 ''fixed HudGetDistance()'' ''fixed HudGetDistance()''
 +
 +Returns the distance from the 3D point to the camera plane. Note that this is **not** the the distance between the camera and the point.
 +
 +Returns negative distances if the point is behind the camera.
 +
 +**Example**
 +
 +<code>
 +if (HudGetDistance() > 256.0)
 +    HudDrawText("*");
 +else
 +    HudDrawText("Shoot here!");
 +</code>
  
 ===== State management ===== ===== State management =====
 +
 +You can save and retrieve hudlib states using these functions. The maximum amount of saved states is configured through ''#define ACSUTILS_HUDLIB_SAVEDSTATES'' in your project's ACSUtils settings.
  
 ==== HudResetState ==== ==== HudResetState ====
Line 291: Line 387:
 Saves the current render state to a stack. Saves the current render state to a stack.
  
-<note important>There is a limit on how many states can be saved. If you save too many states, you will be notified through [[.error|the error system]].</note>+<note important>There is a limit on how many states can be saved. If you save more than ''ACSUTILS_HUDLIB_SAVEDSTATES'' states, you will be notified through [[.error|the error system]].</note>
 ==== HudPopState ==== ==== HudPopState ====
 ''void HudPopState()'' ''void HudPopState()''
Line 301: Line 397:
  
 Deletes all saved render states. Deletes all saved render states.
- 
-