world_camera
at each frame using the head position given by android::cardboard
This module is Android specific.
gamnit :: cardboard $ EulerCamera
Simple camera with perspective oriented with Euler angles (pitch, yaw, roll
)
gamnit :: cardboard $ EulerCamera
Simple camera with perspective oriented with Euler angles (pitch, yaw, roll
)
accept_scroll_and_zoom
Serializable::inspect
to show more useful information
more_collections :: more_collections
Highly specific, but useful, collections-related classes.performance_analysis :: performance_analysis
Services to gather information on the performance of events by categoriesserialization :: serialization_core
Abstract services to serialize Nit objects to different formatscore :: union_find
union–find algorithm using an efficient disjoint-set data structure
# Update the orientation of `world_camera` at each frame using the head position given by `android::cardboard`
#
# This module is Android specific.
module cardboard
import ::android::cardboard
import depth
intrude import cameras
redef class EulerCamera
# Do not use `yaw` and `pitch`, the value will instead originate from the Cardboard API
redef var rotation_matrix = new Matrix.identity(4)
# Get the angle value from the `rotation_matrix`
redef fun pitch
do
var a = rotation_matrix[0, 1]
var b = rotation_matrix[1, 1]
return -atan2(a, b)
end
# Get the angle value from the `rotation_matrix`
redef fun yaw
do
var a = rotation_matrix[2, 0]
var b = rotation_matrix[2, 2]
return -atan2(a, b)
end
end
redef class App
# Cardboard's head tacker instance
private var head_tracker: nullable NativeHeadTracker = null
# Rotation matrix read from `head_tracker`, reusing the same structure as a buffer
private var java_rotation_matrix = new JavaFloatArray(16) is lazy
# Initialize and set `head_tracker`
fun initialize_head_tracker
do
# Initialize the Cardboard head orientation tracker service
var head_tracker = new NativeHeadTracker(app.native_activity)
head_tracker.neck_model_enabled = true
head_tracker.start_tracking
self.head_tracker = head_tracker
# Set a wide field of view
world_camera.field_of_view_y = 1.0
end
# Read the rotation matrix from Cardboard and update `world_camera`
private fun update_from_head_tracker
do
var head_tracker = head_tracker
if head_tracker == null then return
head_tracker.last_head_view(java_rotation_matrix, 0)
# Copy values from the Java array to our matrix
for y in [0..4[ do
for x in [0..4[ do
world_camera.rotation_matrix[y, x] = java_rotation_matrix[y*4+x]
end
end
end
redef fun create_scene
do
super
initialize_head_tracker
end
redef fun update(dt)
do
super
update_from_head_tracker
end
redef fun pause
do
super
var tracker = head_tracker
if tracker != null then tracker.stop_tracking
end
redef fun resume
do
super
var tracker = head_tracker
if tracker != null then tracker.start_tracking
end
end
lib/gamnit/depth/cardboard.nit:15,1--108,3