예제 #1
0
// Project 3D point 'a' from world-space to screen-space
func perspProj(a *vec3.T, cam *Camera) *vec2.T {
	m := mkExtrinsicCameraMtx(cam)
	printM4(m)
	sp := vec3.From(a)
	m.TransformVec3(&sp)
	return &vec2.T{sp[0], sp[1]}
}
예제 #2
0
func (r *R) drawRadarBeam() {
	m := mat3.Ident
	m.AssignZRotation(cam.Orientation[0])
	view := vec3.UnitX
	view.Scale(100) // prescale view vector to take meaningful size on screen
	m.TransformVec3(&view)
	pos2 := vec3.From(&cam.Pos)
	pos2[2] = 0
	pos2.Add(&view)
	r.sr.SetDrawColor(0, 255, 0, 255)
	r.sr.DrawLine(int(cam.Pos[0]), int(cam.Pos[1]), int(pos2[0]), int(pos2[1]))
}
예제 #3
0
func mkExtrinsicCameraMtx(cam *Camera) *mat4.T {
	mRot := mat3.Ident
	mRot.AssignEulerRotation(cam.Orientation[0], cam.Orientation[1], cam.Orientation[2])
	mRot.Transpose()
	printM3(&mRot)
	m := mat4.From(&mRot)
	mRot.Scale(-1)
	camPos := vec3.From(&cam.Pos)
	mRot.TransformVec3(&camPos)
	m[3] = vec4.From(&camPos)
	return &m
}