Showview: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
→‎Realistic examples: whole screen example
Fox (talk | contribs)
 
(3 intermediate revisions by 2 users not shown)
Line 7: Line 7:


The on-screen coordinates can be in any shape; they do not have to be in the same x-y ratio as the screen resolution. However, the aspect ratio at which the scene is drawn in the sub-viewport is unspecified and may differ between renderers and settings of ''r_usenewaspect''. (For example, different ratios may result in warping or graphical glitches in the view.)
The on-screen coordinates can be in any shape; they do not have to be in the same x-y ratio as the screen resolution. However, the aspect ratio at which the scene is drawn in the sub-viewport is unspecified and may differ between renderers and settings of ''r_usenewaspect''. (For example, different ratios may result in warping or graphical glitches in the view.)
Their permissible range is 0 to 319 for the screen x coordinate, and 0 to 199 for the screen y coordinate, both inclusive.
Their permissible range is 0 to 319 for the screen x coordinate, and 0 to 199 for the screen y coordinate, both inclusive.
== Coordinates ==
These normalized coordinates are transformed to actual screen coordinates depending on the command used:
These normalized coordinates are transformed to actual screen coordinates depending on the command used:


Line 20: Line 24:
The resulting coordinates are 0-based with the origin being the upper left corner and denote an inclusive range of pixels in the x or y direction in the classic renderer.
The resulting coordinates are 0-based with the origin being the upper left corner and denote an inclusive range of pixels in the x or y direction in the classic renderer.


<br/>
For example, the command
For example, the command
  '''''showview''''' x y z a h s  0 0  31 0
  '''''showview''''' x y z a h s  0 0  31 0
Line 33: Line 36:
Keep in mind when using this command that the game will have to completely redraw everything from the specified perspective, which can produce a sizeable framerate hit.
Keep in mind when using this command that the game will have to completely redraw everything from the specified perspective, which can produce a sizeable framerate hit.


===Realistic examples===
==Examples==
The correct way of drawing to the whose screen is
The correct way of drawing to the whole screen is
  '''showviewunbiased''' x y z a h s '''''0 0 319 199'''''
  '''showviewunbiased''' x y z a h s '''''0 0 319 199'''''


<br/>
This will embed a small version of the player's view near the top left corner of the screen:
This will embed a small version of the player's view near the top left corner of the screen:
  getplayer[THISACTOR].posx x
  getplayer[THISACTOR].posx x
Line 48: Line 50:
  updatesectorz x y z sect
  updatesectorz x y z sect
  '''showviewunbiased''' x y z ang horiz sect 16 8 56 39
  '''showviewunbiased''' x y z ang horiz sect 16 8 56 39
<br/>
This lengthy example will create a "gun camera" that shows a closeup view of wherever the player is currently aiming. In addition to showview and basic EDuke commands, it also uses [[updatesectorz]], [[myos]], and [[hitscan]], as well as the [[event]] [[EVENT_DISPLAYREST]].
gamevar sv_scrnx1 0 0
gamevar sv_scrny1 0 0
gamevar sv_scrnx2 0 0
gamevar sv_scrny2 0 0
gamevar sv_sect 0 0
gamevar sv_temp1 0 0
gamevar sv_temp2 0 0
gamevar sv_x 0 0
gamevar sv_y 0 0
gamevar sv_z 0 0
gamevar sv_hitx 0 0
gamevar sv_hity 0 0
gamevar sv_hitz 0 0
gamevar sv_cos 0 0
gamevar sv_sin 0 0
gamevar sv_ang 0 0
gamevar sv_horiz 0 0
state sv_playerview
  getplayer[THISACTOR].posx sv_x
  getplayer[THISACTOR].posy sv_y
  getplayer[THISACTOR].posz sv_z
  subvar sv_z 512
  getplayer[THISACTOR].cursectnum sv_sect
ends
onevent EVENT_DISPLAYREST {
// get coords
  setvar sv_scrnx1 23
  setvar sv_scrny1 16
  setvarvar sv_scrnx2 sv_scrnx1 addvar sv_scrnx2 50
  setvarvar sv_scrny2 sv_scrny1 addvar sv_scrny2 47 //  31 for correct ratio
// display frame
  setvarvar sv_temp1 sv_scrnx1 subvar sv_temp1 7
  setvarvar sv_temp2 sv_scrny1 subvar sv_temp2 8
  myos sv_temp1 sv_temp2 SCREENBREAK6 0 16
// do the hitscan
  getplayer[THISACTOR].ang sv_ang
  getplayer[THISACTOR].horiz sv_horiz
  getplayer[THISACTOR].posx sv_hitx
  getplayer[THISACTOR].posy sv_hity
  getplayer[THISACTOR].posz sv_hitz
  getplayer[THISACTOR].cursectnum sv_temp2
  subvar sv_hitz 512
  cos sv_cos sv_ang
  sin sv_sin sv_ang
  setvar sv_temp1 100
  subvarvar sv_temp1 sv_horiz
  getplayer[THISACTOR].horizoff sv_horiz
  subvarvar sv_temp1 sv_horiz
  shiftvarl sv_temp1 11
  hitscan sv_hitx sv_hity sv_hitz sv_temp2 sv_cos sv_sin sv_temp1 sv_temp2 sv_temp1 sv_temp1 sv_hitx sv_hity sv_hitz CLIPMASK1
  getplayer[THISACTOR].horiz sv_temp1
  getplayer[THISACTOR].horizoff sv_horiz
  addvarvar sv_horiz sv_temp1
// get distance between player and hitscan location
  getplayer[THISACTOR].posx sv_x
  getplayer[THISACTOR].posy sv_y
  getplayer[THISACTOR].posz sv_z
  subvarvar sv_x sv_hitx
  mulvarvar sv_x sv_x
  subvarvar sv_y sv_hity
  mulvarvar sv_y sv_y
  addvarvar sv_x sv_y
  sqrt sv_x sv_x
  ifvarl sv_x 768 state sv_playerview // if dist < 768, just show the player's view
  else { // otherwise, move camera 768 units back from hitscan location on x-y plane and adjust z accordingly
subvarvar sv_z sv_hitz
mulvar sv_z 768
ifvare sv_x 0 setvar sv_x 1
divvarvar sv_z sv_x
addvarvar sv_z sv_hitz
setvarvar sv_x sv_hitx
setvarvar sv_y sv_hity
mulvar sv_cos -768
mulvar sv_sin -768
divvar sv_cos 16384
divvar sv_sin 16384
addvarvar sv_x sv_cos
addvarvar sv_y sv_sin
subvar sv_z 512
// if the calculated position isn't in a sector (this does happen) then just show the player's view
updatesectorz sv_x sv_y sv_z sv_sect
ifvare sv_sect -1 state sv_playerview
// make sure the camera can still see the hitscan location
cansee sv_x sv_y sv_z sv_sect sv_hitx sv_hity sv_hitz sv_temp2 sv_temp1
ifvare sv_temp1 0 state sv_playerview
  }
// check again to make sure we're in a sector
  ifvarn sv_sect -1 {
// x y z ang horiz sect scrn_x scrn_y scrn_x2 scrn_y2
'''showviewunbiased''' sv_x sv_y sv_z sv_ang sv_horiz sv_sect sv_scrnx1 sv_scrny1 sv_scrnx2 sv_scrny2
  }
// display crosshair
  addvarvar sv_scrnx1 sv_scrnx2 divvar sv_scrnx1 2
  addvarvar sv_scrny1 sv_scrny2 divvar sv_scrny1 2
  myos sv_scrnx1 sv_scrny1 CROSSHAIR 0 0
}
endevent


[[Category:EDuke32 specific commands]]
[[Category:EDuke32 specific commands]]
[[Category:Screen drawing commands]]
[[Category:Screen drawing commands]]

Latest revision as of 02:17, 20 February 2020

showview <x> <y> <z> <angle> <horiz> <sector> <scrn_x1> <scrn_y1> <scrn_x2> <scrn_y2>
showviewunbiased <x> <y> <z> <angle> <horiz> <sector> <scrn_x1> <scrn_y1> <scrn_x2> <scrn_y2>

Displays on-screen the view from in-game coordinates (<x>,<y>,<z>), looking at angle <angle> and with z-angle (up and down) <horiz>, between screen coordinates (<scrn_x1>,<scrn_y1>) and (<scrn_x2>,<scrn_y2>).

<sector> is the sector that contains the in-game coordinates.

The on-screen coordinates can be in any shape; they do not have to be in the same x-y ratio as the screen resolution. However, the aspect ratio at which the scene is drawn in the sub-viewport is unspecified and may differ between renderers and settings of r_usenewaspect. (For example, different ratios may result in warping or graphical glitches in the view.)

Their permissible range is 0 to 319 for the screen x coordinate, and 0 to 199 for the screen y coordinate, both inclusive.

Coordinates

These normalized coordinates are transformed to actual screen coordinates depending on the command used:

For showview, the scaling biases them towards zero, so that the whole screen can never be covered in any other resolution than 320x200:

real_scrn_x = round_towards_zero((<scrn_x>*xdim)/320)
real_scrn_y = round_towards_zero((<scrn_y>*ydim)/200)

On the other hand, showviewunbiased transforms them such that the greatest permissible normalized value will be mapped to the greates actual screen coordinate:

real_scrn_x = round_towards_zero((<scrn_x>*(xdim-1))/319)
real_scrn_y = round_towards_zero((<scrn_y>*(ydim-1))/199)

The resulting coordinates are 0-based with the origin being the upper left corner and denote an inclusive range of pixels in the x or y direction in the classic renderer.

For example, the command

showview x y z a h s  0 0  31 0

draws the view in a one-pixel high line covering about one tenth of the screen length from the left, and

showview x y z a h s  0 0  0 19

a one-pixel wide line covering approximately one tenth of the height from above.

The command

showview x y z a h s  0 0  0 0

would use exactly the upper left pixel in the classic renderer. (Polymost currently behaves differently, but this may be subject to change.)

Keep in mind when using this command that the game will have to completely redraw everything from the specified perspective, which can produce a sizeable framerate hit.

Examples

The correct way of drawing to the whole screen is

showviewunbiased x y z a h s 0 0 319 199

This will embed a small version of the player's view near the top left corner of the screen:

getplayer[THISACTOR].posx x
getplayer[THISACTOR].posy y
getplayer[THISACTOR].posz z
getplayer[THISACTOR].ang ang
getplayer[THISACTOR].horiz horiz
getplayer[THISACTOR].horizoff temp
addvarvar horiz temp
updatesectorz x y z sect
showviewunbiased x y z ang horiz sect 16 8 56 39