3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Hot Soup ProcessorAdvent Calendar 2017

Day 14

HSP3.5 HGIMG4 で複数カメラ視点描画

Last updated at Posted at 2017-12-14

HSP3.5 HGIMG4 ではオフスクリーンを応用して複数カメラ視点描画ができます。
通常のまま gpdraw を実行してしまうとイベントなどの自動移動がその回数分反映されてしまうため、gpdraw に引数を指定して自動移動反映と描画を分けるところがポイントです。
サンプルコードは以下のようになります。

#include "hgimg4.as"

#const EG_CALC GPDRAW_OPT_OBJUPDATE
#const EG_DRAW2D (GPDRAW_OPT_DRAW2D | GPDRAW_OPT_DRAW2D_LATE)
#const EG_DRAW3D (GPDRAW_OPT_DRAWSCENE | GPDRAW_OPT_DRAWSCENE_LATE)


	sx = ginfo(26)
	sy = ginfo(27)

	gpreset
	setcls CLSMODE_SOLID, 0x000033

// 上下往復運動
	newevent ev
	event_addpos ev, 0, -0.002, 0
	event_wait ev, 120
	event_addpos ev, 0, 0.002, 0
	event_wait ev, 120
	event_jump ev, 0

	gpload id, "res/duck"
	setangr id, 0, -64, 0
	setevent id, ev
	duck_id = id

// ちらつき防止用
	buffer 1, 32,32, 0

	ow = sx / 4
	oh = sy / 4

	dist = 4

// メインカメラ
	gpnull id
	gpcamera id, 45, double(sx) / double(sy), 0.5, 768
	setpos id, 2, 2, 3
	gplookat id, 0, 0, 0
	cam_id = id
// サブカメラ
	dim cams,4
	foreach cams
		gpnull id
		gpcamera id, 45, double(ow) / double(oh), 0.5, 768
		if cnt == 0 {
			setpos id, 0,0, dist
			gplookat id, 0,0,0
		}
		if cnt == 1 {
			setpos id, 0,dist,0
			setangr id, -64, 0, 0
		}
		if cnt == 2 {
			setpos id, -dist,0,0
			gplookat id, 0,0,0
		}
		if cnt == 3 {
			setpos id, dist,0,0
			gplookat id, 0,0,0
		}
		cams.cnt = id

		buffer cnt + 2, ow,oh, screen_offscreen
		celdiv cnt + 2, ow, oh, ow/2, oh/2
	loop

	repeat
		getreq ts, SYSREQ_TIMER
		getreq fps, SYSREQ_FPS
// 移動の反映
		gsel 1
		gpdraw EG_CALC
// サブカメラでのオフスクリーン描画
		foreach cams
			gsel cnt + 2
			redraw 0

			gpusecamera cams.cnt
			gpdraw EG_DRAW2D | EG_DRAW3D
			redraw 1
		loop
// メインカメラ
		gsel 0
		gpusecamera cam_id
		gpdraw EG_DRAW2D | EG_DRAW3D
// サブカメラのオフスクリーンを可視描画
		color 224,224,224
		foreach cams
			x = ((cnt & 1) * 10 + 3) * ow / 4
			y = ((cnt / 2) * 10 + 3) * oh / 4
			grect x, y, 0, ow+8, oh+8
		
			pos x, y
			celput cnt + 2
		loop

		pos 16, oh * 2
		color 224,224,224
		font "",36
		mes strf("%2d [fps]", fps)

		redraw 1
		await 1000/60
	loop
実行結果
z09four1.png
通常のメインカメラと正面、上、左右のサブカメラ

描画の回数だけ1フレームあたりの処理負荷は上がりますが、自キャラ位置視点や第三者視点と俯瞰視点との同時描画などが実現できます。

3
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?