Lecture 3 Notes

Jul 14, 2024

Lecture 3 Notes

Introduction

  • Turret Example: Placing and aligning turret objects on uneven surfaces in a game.
  • Main Focus: Understanding transformation matrices, vectors, and cross products.

Housekeeping

  • Notification pings: Students needed to react to the ping.
  • Lecture Naming: Episodes are named by stream index, not by days.

Transformation Between Coordinate Systems

  • Context: Methods to transform objects between different spaces in games.
  • Elementary Methods: Basic vector transformations are not sufficient for complete transformations.
  • Transformation Matrices: Using matrices to store and manipulate transformation data.

Matrices

  • Definition: Another way to store numerical data, like vectors but in a more structured form.
  • Columns and Rows: Can be used to store vectors and more complex transformations.
  • Types: Square matrices (2x2, 3x3, 4x4) and their properties.

Common Matrix Types

  • Identity Matrix: For transformations with no change, maintaining components as is.
  • Rotation Matrices: For storing rotation transformations.
  • Column and Row Vectors: Ways to store one-dimensional data within matrices.
  • Transformation Matrices in Games: Often 4x4 matrices, storing position, rotation, and scale.

Practical Use of Matrices in Unity

  • Transformations: Unity functions like transform.localToWorldMatrix and transform.worldToLocalMatrix enable transformations.
  • Functions: transform.TransformPoint, transform.InverseTransformPoint, and transform.TransformVector manipulate positions and directions according to object transforms.
  • 4x4 Matrices in Unity: Handle detailed transformations, including scaling.

Cross Product

  • Definition: Mathematical operation that results in a vector perpendicular to two other vectors.
  • Anti-Commutative Property: Order affects results; a x b != b x a
  • Utility: Generating basis vectors for coordinate systems.
  • Visualization: Using right-hand or left-hand rule to determine direction.

Practical Examples

  • Coordinate Basis Generation: Example using cross products to generate right and up vectors for a given forward vector.
  • Game Development: Adjusting object orientations to maintain alignment with a ground surface using cross products and raycasting.

Application: Placing a Turret on Uneven Terrain

  • Problem Statement: Align turret to surface normal while ensuring a forward direction.
  • Steps:
    • Raycasting from camera to terrain surface.
    • Calculating normal vector of the hit surface.
    • Using cross product to determine right (x-axis) vector perpendicular to normal and view direction.
    • Calculating forward (z-axis) vector as cross product of right and up vectors.
    • Using quaternion look rotations to set turret transformation.
  • Common Issues: Normalizing vectors, avoiding self-hitting in raycasts.

Coordinate Systems in Different Software

  • Conventions: Variations in axis orientation and handedness.
  • Unity Specifics: Left-handed coordinate system, y-axis as up.

Additional Useful Information

  • Left vs Right Handed Rules: Impacts orientation visualization in 3D space.
  • Practical Tips: Matrix and vector multiplication, transformation pipelines, and coordinate space mapping.

Assignments

  • First Assignment: Rebuild and improve the turret placement system demonstrated in the lecture. Use cross products to correct orientation and handle special cases.
  • Matrix-related Problem: Involves transforming positions using local offsets and understanding the full transformation pipeline in Unity.