Dive into 3D Math: A Beginner's Toolkit for Twinfinity Developers

Dive into 3D Math: A Beginner's Toolkit for Twinfinity Developers

Welcome to the exciting world of 3D app development! If you're stepping into this realm for the first time, especially with Twinfinity, you're in for an adventure. Let's unpack some key concepts of 3D math that will be your trusty sidekicks on this journey.

Vectors

In essence, a vector is a directional arrow in space. It has magnitude (how long the arrow is) and direction (where the arrow points).

  • Components: In 3D, vectors have three parts: x, y, and z. These represent how far the vector reaches along each axis of the 3D space.

  • Usage: You’ll use vectors for everything from positioning objects to defining movement and even calculating lighting.

Points

While vectors are about direction and magnitude, points are specific locations in your 3D space.

  • Understanding Points: Think of a point as a pin on a map. It tells you where something is but not where it's headed or how fast it's going.

Coordinate Systems: The Framework of Your 3D World

In 3D development, everything is placed within a coordinate system. This is true also for Twinfinity

  • Cartesian Coordinates: Twinfinity uses a lefthanded Cartesian coordinate system. This is the most common system, using x, y, and z axes to define positions in space.




  • World vs. Local Coordinates: Objects in your 3D world have their own local coordinates, which relate to their position and orientation, while world coordinates define positions in the overall 3D space.

Understanding Transformations

Transformations are the actions that move or change objects in your 3D space. There are three main types:

  1. Scaling: Changing the size of an object. Imagine zooming in and out of an image.

  2. Rotation: Spinning the object around. It’s like rotating a globe on its stand.

  3. Translation: Moving an object from one point to another. Think of sliding a piece across a board.

If you need to do more than one of the scale, rotate, translate operations then make sure you do it in the scale, rotate, translate order to get the desired outcome.

Essential Math Concepts

  • Dot Product: This operation helps determine the angle between two vectors. The dot product, or scalar product as it is also known is quite often used for lighting calculations, checking angles between vectors, vector length and much more.

  • Cross Product: This gives you a vector that’s perpendicular to two other vectors. It’s key for calculating normals, which are crucial in rendering and lighting.

  • Normals: A normal is a vector emanating from a surface, pointing outward. Picture it like an invisible arrow that defines which way the surface is facing. In Twinfinity normals are normalized, meaning that their length is 1 meter. Normals are very commonly used when trying to place objects in the 3D space.

 

Illustrating the cross product. axb being perpendicular to the plane that is defined by a and b.

Understanding what the dotproduct values mean can be very usefull in 3d programming. Knowing if two vectors are perpendicular to eachother is an example.

 

Applying These Concepts in Twinfinity

Between Twinfinity and BabylonJS most of the nitty-gritty of 3D calculations are handled for you. However, understanding what these concepts do will help you apply them when creating your next Twinfinity app. In this playground you will basic usage of some of the principles of this article.

Conclusion

Mastering these basic 3D math concepts will significantly ease your journey into developing engaging and interactive apps in Twinfinity. Remember, practice makes perfect. The more you experiment and apply these concepts, the more intuitive they'll become in your development process. Happy coding!