# sm-3d-camera-control

A Rust crate providing a convenient and efficient interface for controlling virtual 3D cameras, enabling precise manipulation of camera parameters for rendering and simulation purposes. This crate simplifies the process of setting up and adjusting camera perspectives, making it ideal for applications like game development, 3D modeling, and scientific visualization.

## Installation

To use `sm-3d-camera-control` in your Rust project, add the following to your `Cargo.toml` file:
toml
[dependencies]
sm-3d-camera-control = "0.1.0" # Replace with the latest version

## Usage Examples

Here are a few examples demonstrating how to use the `sm-3d-camera-control` crate:

**1. Basic Camera Setup:**
rust
use sm_3d_camera_control::Camera;
use sm_3d_camera_control::Vector3;

fn main() {
    // Create a new camera with a specific position and target.
    let mut camera = Camera::new(
        Vector3::new(0.0, 0.0, 5.0), // Position
        Vector3::new(0.0, 0.0, 0.0), // Target
        Vector3::new(0.0, 1.0, 0.0), // Up vector
        45.0,                        // Field of view (degrees)
        1.0,                         // Aspect ratio
        0.1,                         // Near clipping plane
        100.0,                       // Far clipping plane
    );

    // Print the camera's view matrix.
    println!("View matrix: {:?}", camera.get_view_matrix());
}

**2. Moving the Camera:**
rust
use sm_3d_camera_control::Camera;
use sm_3d_camera_control::Vector3;

fn main() {
    let mut camera = Camera::new(
        Vector3::new(0.0, 0.0, 5.0),
        Vector3::new(0.0, 0.0, 0.0),
        Vector3::new(0.0, 1.0, 0.0),
        45.0,
        1.0,
        0.1,
        100.0,
    );

    // Move the camera along the X-axis.
    camera.translate(Vector3::new(1.0, 0.0, 0.0));

    // Print the updated camera position.
    println!("New camera position: {:?}", camera.position);
}

**3. Rotating the Camera:**
rust
use sm_3d_camera_control::Camera;
use sm_3d_camera_control::Vector3;

fn main() {
    let mut camera = Camera::new(
        Vector3::new(0.0, 0.0, 5.0),
        Vector3::new(0.0, 0.0, 0.0),
        Vector3::new(0.0, 1.0, 0.0),
        45.0,
        1.0,
        0.1,
        100.0,
    );

    // Rotate the camera around the Y-axis by 30 degrees.
    camera.rotate_y(30.0);

    // Print the updated view matrix.
    println!("Updated view matrix: {:?}", camera.get_view_matrix());
}

**4. Adjusting the Field of View:**
rust
use sm_3d_camera_control::Camera;
use sm_3d_camera_control::Vector3;

fn main() {
    let mut camera = Camera::new(
        Vector3::new(0.0, 0.0, 5.0),
        Vector3::new(0.0, 0.0, 0.0),
        Vector3::new(0.0, 1.0, 0.0),
        45.0,
        1.0,
        0.1,
        100.0,
    );

    // Adjust the field of view.
    camera.set_field_of_view(60.0);

    // Print the new field of view.
    println!("New field of view: {}", camera.field_of_view);
}

**5. Zooming with the Camera:**
rust
use sm_3d_camera_control::Camera;
use sm_3d_camera_control::Vector3;

fn main() {
    let mut camera = Camera::new(
        Vector3::new(0.0, 0.0, 5.0),
        Vector3::new(0.0, 0.0, 0.0),
        Vector3::new(0.0, 1.0, 0.0),
        45.0,
        1.0,
        0.1,
        100.0,
    );

    // Zoom in by moving the camera closer to the target.
    camera.zoom(1.0);

    // Print the updated camera position.
    println!("New camera position: {:?}", camera.position);
}

## Feature Summary

*   **Flexible Camera Creation:** Easily instantiate cameras with customizable parameters such as position, target, up vector, field of view, aspect ratio, and near/far clipping planes.
*   **Precise Camera Manipulation:** Provides methods for translating and rotating the camera to achieve desired perspectives.
*   **View Matrix Generation:** Automatically calculates and provides the view matrix, essential for rendering 3D scenes.
*   **Adjustable Field of View:** Dynamically modify the field of view to zoom in or out, enhancing visual control.
*   **Intuitive API:** Designed for ease of use, allowing developers to quickly integrate camera control functionality into their projects.

## License

MIT

This crate 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/