Thursday, 11 May 2023

Gimbal lock

 Gimbal lock is a problem that can occur when using Euler angles to represent rotations in 3D graphics. It happens when two of the three rotational degrees of freedom (e.g., pitch, yaw, and roll) become aligned, causing a loss of one degree of freedom and making it impossible to represent certain rotations.


To understand gimbal lock, imagine a camera with three perpendicular axes that can rotate around each axis. These rotations are typically represented using Euler angles, which describe the rotation around each axis in a particular order (e.g., pitch, yaw, and roll). However, if the pitch angle is close to 90 degrees (i.e., the camera is looking straight up or down), the yaw and roll axes become aligned, and it becomes impossible to rotate the camera around the yaw or roll axis independently. This loss of one degree of freedom is called gimbal lock.


Gimbal lock can cause problems in 3D graphics applications because it can lead to unexpected behavior when rotating objects or cameras. For example, if a camera is looking straight up or down and the user tries to rotate it around the yaw or roll axis, the camera may suddenly "jump" to a different orientation due to the loss of one degree of freedom.


To avoid gimbal lock, many 3D graphics applications use quaternions to represent rotations instead of Euler angles. Quaternions are not subject to gimbal lock and can be smoothly interpolated between orientations, making them a more robust choice for representing rotations in 3D space.

Quaternion

 A quaternion is a four-dimensional vector that is commonly used to represent rotations in 3D space. A quaternion can be represented as q = w + xi + yj + zk, where w is the scalar part and (x, y, z) is the vector part.

In 3D graphics programming, quaternions are often used to represent rotations because they can be interpolated smoothly and are not subject to gimbal lock, a problem that can occur when using Euler angles to represent rotations.
Quaternions have several properties that make them useful for representing rotations. For example:
- They can be composed using a simple multiplication operation, making it easy to concatenate multiple rotations.
- They can be normalized to represent a pure rotation, allowing for easy interpolation between two orientations.
- They are immune to gimbal lock, a problem that can occur when using Euler angles to represent rotations.

In practice, quaternions are often used in combination with matrices to represent rotations in 3D space. The matrix can be used to transform a point in space, while the quaternion can be used to represent the rotation applied to the matrix.
Quaternions are widely used in computer graphics, game development, and robotics, among other fields.

Wednesday, 10 May 2023

Explanation of object space and world space in vex context

 In VEX, "object space" and "world space" are two different coordinate systems used to represent the position and orientation of objects in a scene.


"Object space" refers to the local coordinate system of a specific object in the scene. This coordinate system is relative to the object's origin, which is typically located at the center of the object's geometry. In object space, the X, Y, and Z axes are aligned with the object's local axis system.


"World space" refers to the global coordinate system of the scene. This coordinate system is fixed and does not change, regardless of the position or orientation of individual objects in the scene. In world space, the X, Y, and Z axes are aligned with the global axis system of the scene.


When working with VEX in Houdini, you may need to transform vectors or points from one coordinate system to another. For example, if you want to move an object from its current position in object space to a new position in world space, you would need to transform the object's position vector from object space to world space.



Fundamental Notes on Vector Expression Language - VEX coding in Houdini

Basics:  


So you want to learn VEX! 

VEX can be a powerful tool to achieve complex effects in Houdini. Here are some tips to get started:

  1. Start with the basics: Begin with understanding basic programming concepts such as variables, data types, and control flow. Once you have a good grasp of these, move on to learning VEX-specific concepts such as vectors, matrices, and functions.

  2. Learn by doing: Practice is the key to mastering any programming language. Start with small projects and gradually move on to more complex ones. Houdini provides a number of tutorials and example files that can help you get started.

  3. Use the Houdini documentation: Houdini has extensive documentation on VEX that can be accessed through the Help menu. You can also access it online at https://www.sidefx.com/docs/houdini/vex/index.html.

  4. Join the community: Houdini has a strong community of users who are always willing to help out. Join forums such as the SideFX forum or Reddit's Houdini subreddit to ask questions and learn from other users.

  5. Experiment: Don't be afraid to experiment and try out different approaches to achieve your desired effect. VEX can be a powerful tool, and with some creativity, you can achieve some amazing results.

I hope these tips help you get started with learning VEX.

To get you started here are some basics of VEX: 1. Variables: VEX supports different data types such as integers, floats, and vectors. You can declare variables using the `int`, `float`, and `vector` keywords, respectively. For example:


  
   int myInteger = 10;
   float myFloat = 3.14;
   vector myVector = {1, 2, 3};
   
   
2. Operators: VEX supports a variety of operators, including arithmetic, comparison, and logical operators. For example:

   int a = 10;
   int b = 5;
   int c = a + b; // adds a and b and assigns the result to c
   int d = a > b; // assigns 1 to d (true) because a is greater than b
   int e = !d; // assigns 0 to e (false) because !d means not d
   
3. Functions: VEX provides a range of built-in functions that can be used for various tasks, such as math functions, string manipulation, and vector operations. For example:

   float myFloat = 3.14;
   float myAbs = abs(myFloat); // assigns 3.14 to myAbs
   vector myVector = {1, 2, 3};
   vector myNormalizedVector = normalize(myVector); 
   // normalizes the vector and assigns it to myNormalizedVector
  
4. Control Flow: VEX supports if-else statements and loops such as for and while loops. For example:

   int a = 10;
   int b = 5;
   if (a > b) {
       printf("a is greater than b");
   } else {
       printf("a is not greater than b");
   }

   for (int i = 0; i < 10; i++) {
       printf("i is %d", i);
   }
  
  
These are just some of the basics of VEX. As you dive deeper into VEX, you will learn about more advanced concepts such as structs, arrays, and shaders.