http://marupeke296.com/OGL_No3_Matrix.htmlマルペケさんのサイトの行列取得関数をプチコ用に書き換えてみました
float[16]なのでLMATRIXに指定できる値のはず
動作テストはしてないですが
;var[3] = Vector3
;var[16] = Matrix4x4
def cot(v)
return 1.0 / tan(v);
end
def select(PickA, A, B)
if PickA then
return A
endif
return B
end
;注視点からビュー行列を作成
;target = Float3(0.0, 0.0, 0.0), eye = Float3(0.0, 0.0, -50.0), up = Float3(0.0, 1.0, 0.0)
def lookAtLH(target, eye, up)
var out[16];
var zaxis = v3normalize(v3sub(target, eye))
var xaxis = v3normalize(v3cross(up,zaxis))
var yaxis = v3cross(zaxis,xaxis)
out[ 0] = xaxis[0]
out[ 1] = yaxis[0]
out[ 2] = zaxis[0]
out[ 3] = 0.0
out[ 4] = xaxis[1]
out[ 5] = yaxis[1]
out[ 6] = zaxis[1]
out[ 7] = 0.0
out[ 8] = xaxis[2]
out[ 9] = yaxis[2]
out[10] = zaxis[2]
out[11] = 0.0
out[12] = v3dot(-xaxis,eye)
out[13] = v3dot(-yaxis,eye)
out[14] = v3dot(-zaxis,eye)
out[15] = 1.0
return out
end
;射影変換行列を取得
;fovY = Rad(30.0), screenX = 640.0, screenY = 480.0, nZ = 1.0, fZ = 3000.0
def perspLH(fovY, screenX, screenY, nZ, fZ)
var out[16] = [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]
var yScale = cot( select(fovY == 0.0f , 30.0f , fovY)) / 2.0 )
var xScale = select(screenY == 0.0f , 480.0 , screenY) * yScale / select((screenX == 0.0f) , 640.0 , screenX)
var subZ = select(fZ - nZ == 0.0 , 3000.0 , fZ - nZ)
var farZ = select(fZ == 0.0 , 3001.0 , fZ)
var nearZ = select(nZ == 0.0 , 1.0 , nZ)
out[0] = xScale
out[5] = yScale
out[10] = farZ / subZ
out[11] = 1.0
out[14] = -nearZ * farZ / subZ
return out;
end
参考サイト
https://yttm-work.jp/gmpg/gmpg_0002.htmlhttp://marupeke296.com/DXG_No72_ViewProjInfo.htmlmarupeke296.sakura.ne.jp/DXG_No70_perspective.html