diff --git a/camera/src/camera.mm b/camera/src/camera.mm index 39b5f8e..3411e36 100644 --- a/camera/src/camera.mm +++ b/camera/src/camera.mm @@ -390,6 +390,7 @@ int CameraPlatform_StopCapture() { [g_Camera.m_Delegate stopCamera]; [g_Camera.m_Delegate release]; + g_Camera.m_Delegate = 0; dmBuffer::Destroy(g_Camera.m_VideoBuffer); g_Camera.m_VideoBuffer = 0; diff --git a/input/game.input_binding b/input/game.input_binding index e69de29..3e91365 100644 --- a/input/game.input_binding +++ b/input/game.input_binding @@ -0,0 +1,12 @@ +key_trigger { + input: KEY_SPACE + action: "space" +} +mouse_trigger { + input: MOUSE_BUTTON_1 + action: "touch" +} +touch_trigger { + input: TOUCH_MULTI + action: "touch" +} diff --git a/main/main.collection b/main/main.collection index 5e753b2..ef9c7c0 100644 --- a/main/main.collection +++ b/main/main.collection @@ -77,6 +77,116 @@ embedded_instances { " w: 1.0\n" " }\n" "}\n" + "embedded_components {\n" + " id: \"label\"\n" + " type: \"label\"\n" + " data: \"size {\\n" + " x: 128.0\\n" + " y: 32.0\\n" + " z: 0.0\\n" + " w: 0.0\\n" + "}\\n" + "scale {\\n" + " x: 1.0\\n" + " y: 1.0\\n" + " z: 1.0\\n" + " w: 0.0\\n" + "}\\n" + "color {\\n" + " x: 1.0\\n" + " y: 1.0\\n" + " z: 1.0\\n" + " w: 1.0\\n" + "}\\n" + "outline {\\n" + " x: 0.0\\n" + " y: 0.0\\n" + " z: 0.0\\n" + " w: 1.0\\n" + "}\\n" + "shadow {\\n" + " x: 0.0\\n" + " y: 0.0\\n" + " z: 0.0\\n" + " w: 1.0\\n" + "}\\n" + "leading: 1.0\\n" + "tracking: 0.0\\n" + "pivot: PIVOT_NW\\n" + "blend_mode: BLEND_MODE_ALPHA\\n" + "line_break: false\\n" + "text: \\\"Space/Touch to toggle capture\\\"\\n" + "font: \\\"/builtins/fonts/system_font.font\\\"\\n" + "material: \\\"/builtins/fonts/label.material\\\"\\n" + "\"\n" + " position {\n" + " x: 90.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "embedded_components {\n" + " id: \"status\"\n" + " type: \"label\"\n" + " data: \"size {\\n" + " x: 128.0\\n" + " y: 32.0\\n" + " z: 0.0\\n" + " w: 0.0\\n" + "}\\n" + "scale {\\n" + " x: 1.0\\n" + " y: 1.0\\n" + " z: 1.0\\n" + " w: 0.0\\n" + "}\\n" + "color {\\n" + " x: 1.0\\n" + " y: 1.0\\n" + " z: 1.0\\n" + " w: 1.0\\n" + "}\\n" + "outline {\\n" + " x: 0.0\\n" + " y: 0.0\\n" + " z: 0.0\\n" + " w: 1.0\\n" + "}\\n" + "shadow {\\n" + " x: 0.0\\n" + " y: 0.0\\n" + " z: 0.0\\n" + " w: 1.0\\n" + "}\\n" + "leading: 1.0\\n" + "tracking: 0.0\\n" + "pivot: PIVOT_NW\\n" + "blend_mode: BLEND_MODE_ALPHA\\n" + "line_break: false\\n" + "text: \\\"label\\\\n" + "\\\"\\n" + " \\\"\\\"\\n" + "font: \\\"/builtins/fonts/system_font.font\\\"\\n" + "material: \\\"/builtins/fonts/label.material\\\"\\n" + "\"\n" + " position {\n" + " x: 90.0\n" + " y: -24.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" "" position { x: 95.39966 diff --git a/main/main.script b/main/main.script index d30a85c..6bbd636 100644 --- a/main/main.script +++ b/main/main.script @@ -1,12 +1,20 @@ -function init(self) - local logosize = 128 - local screen_width = sys.get_config("display.width", 600) - local screen_height = sys.get_config("display.height", 800) - local scale_width = screen_width / logosize - local scale_height = screen_height / logosize +local function stop_capture(self) + if self.cameraframe == nil then + return + end + + self.cameraframe = nil + camera.stop_capture() - go.set("#sprite", "scale", vmath.vector3(scale_width, scale_height, 1) ) + label.set_text("logo#status", "Capture Status: OFF") +end + + +local function start_capture(self) + if self.cameraframe ~= nil then + return + end if camera ~= nil then @@ -20,22 +28,39 @@ function init(self) end if camera.start_capture(type, quality) then - self.cameraframe = camera.get_frame() - self.camerainfo = camera.get_info() - print("Initialized camera") - pprint(self.camerainfo) - - self.cameratextureheader = {width=self.camerainfo.width, - height=self.camerainfo.height, - type=resource.TEXTURE_TYPE_2D, - format=resource.TEXTURE_FORMAT_RGB, - num_mip_maps=1 } + self.cameraframe = camera.get_frame() + self.camerainfo = camera.get_info() + print("Initialized camera") + pprint(self.camerainfo) + + self.cameratextureheader = {width=self.camerainfo.width, + height=self.camerainfo.height, + type=resource.TEXTURE_TYPE_2D, + format=resource.TEXTURE_FORMAT_RGB, + num_mip_maps=1 } end + label.set_text("logo#status", "Capture Status: ON") else print("could not start camera capture") + label.set_text("logo#status", "Capture Status: UNAVAILABLE") end end +function init(self) + msg.post(".", "acquire_input_focus") + + local logosize = 128 + local screen_width = sys.get_config("display.width", 600) + local screen_height = sys.get_config("display.height", 800) + local scale_width = screen_width / logosize + local scale_height = screen_height / logosize + + go.set("#sprite", "scale", vmath.vector3(scale_width, scale_height, 1) ) + + + start_capture(self) +end + function final(self) if self.cameraframe ~= nil then camera.stop_capture() @@ -44,10 +69,20 @@ end function update(self, dt) - if self.cameraframe then + if self.cameraframe ~= nil then local pathmodelcamera = go.get("#sprite", "texture0") resource.set_texture(pathmodelcamera, self.cameratextureheader, self.cameraframe) end - +end + + +function on_input(self, action_id, action) + if (action_id == hash("space") or action_id == hash("touch")) and action.pressed then + if self.cameraframe == nil then + start_capture(self) + else + stop_capture(self) + end + end end