sm-3d-camera-control
A library to simplify programmatic control of virtual 3D cameras, enabling precise positioning and orientation. This package provides a functional interface for generating camera parameters and transformations.
Installation
Add sm_3d_camera_control to your list of dependencies in mix.exs:
elixir
def deps do
[
{:sm_3d_camera_control, "~> 0.1.0"}] end
Usage Examples
Here are a few examples demonstrating how to use sm_3d_camera_control in your Elixir projects.
Example 1: Defining a simple camera position elixir alias Sm3DCameraControl.Camera
camera = Camera.new(position: {1, 2, 3}, target: {0, 0, 0}, up: {0, 1, 0}) IO.inspect camera
Output: %Sm3DCameraControl.Camera{position: {1, 2, 3}, target: {0, 0, 0}, up: {0, 1, 0}}
Example 2: Calculating the camera's view matrix elixir alias Sm3DCameraControl.Camera
camera = Camera.new(position: {1, 2, 3}, target: {0, 0, 0}, up: {0, 1, 0}) view_matrix = Camera.view_matrix(camera) IO.inspect view_matrix
Output: A 4x4 matrix representing the camera's view transformation.
Example 3: Generating a camera with a specific field of view and aspect ratio elixir alias Sm3DCameraControl.Camera
camera = Camera.new(position: {0, 0, 5}, target: {0, 0, 0}, up: {0, 1, 0}) |> Camera.with_perspective(fov: 45, aspect: 1.6)
IO.inspect camera
Output: %Sm3DCameraControl.Camera{aspect: 1.6, fov: 45, position: {0, 0, 5}, target: {0, 0, 0}, up: {0, 1, 0}}
Example 4: Using pattern matching to extract camera parameters elixir alias Sm3DCameraControl.Camera
camera = Camera.new(position: {1, 2, 3}, target: {0, 0, 0}, up: {0, 1, 0})
case camera do %Camera{position: {x, y, z}} ->
IO.puts "Camera position: x=#{x}, y=#{y}, z=#{z}"end
Output: Camera position: x=1, y=2, z=3
Example 5: Chaining operations to create and transform a camera elixir alias Sm3DCameraControl.Camera
camera = Camera.new() |> Camera.move(x: 1, y: 2, z: 3) |> Camera.look_at(target: {0, 0, 0}) |> Camera.rotate(angle: 30, axis: {0, 1, 0})
IO.inspect camera
Output: %Sm3DCameraControl.Camera{position: {modified_x, modified_y, modified_z}, target: {0, 0, 0}, up: {modified_up_x, modified_up_y, modified_up_z}}
Feature Summary
- Provides a simple and consistent API for managing 3D camera parameters.
- Supports defining camera position, target, and up vectors.
- Calculates the camera's view matrix for rendering.
- Allows setting perspective parameters such as field of view and aspect ratio.
- Offers functional operations for camera transformations like movement and rotation.
- Designed for seamless integration with Elixir's functional programming paradigm.
- Clear and concise API.
License
MIT
This package is part of the sm-3d-camera-control ecosystem. For advanced features and enterprise-grade tools, visit: https://supermaker.ai/blog/qwen-image-multiple-angles-3d-camera-alibabas-breakthrough-in-ai-camera-control/