CryENGINE specific data types

Besides the standard data types, such as int, bool, float, and so on, there are a lot of other data types in CryENGINE 3, which are very helpful if you start writing your own code:

  • Vec3: It represents a vector of three float values, which is used for positions and 3D-vectors
  • Ang3: It represents a vector of three floats, which is used to represent Euler rotations
  • Matrix33: It represents a 3 x 3 float matrix, which is used for the rotation matrix
  • Matrix34: It represents a 3 x 4 float matrix, which is used to store the rotation matrix with translation
  • Quat: It represents a Quaternion, which is used to efficiently store rotations and interpolate them

While you work with CryENGINE 3, you will use them a lot. All the common operations are supported, such as addition, subtraction, dot product, cross product, and so on.

Let us see an example of a C++ function to determine which of the two points is the closest to a target point:

Vec3 GetClosestPositionToTarget(const Vec3 target, const Vec3 posA, 
                                const Vec3 posB)
{
  const Vec3 a = target - posA; // vector between target and posA
  const Vec3 b = target - posB; // vector between target and posB

  // squared distance between target to posA
  const float dA = a.GetLengthSquared();
  // squared distance between target to posB
  const float dB = b.GetLengthSquared();

  if(dA < dB)
  {
    return posA; //posA is closer
  }
  return posB; //posB is closer
}

Note

Why use the squared length instead of the normal length? Well, when the normal length of vector dA is smaller than the length of dB, the squared length of dA is smaller than the squared length of dB too.

Pop quiz - Lua entities and scriptbind functions

  1. How do you define a new Lua Entity class?
    • By writing new C++ code
    • By adding a .ent and .lua file
    • By using Sandbox RollupBar
  2. Which Lua function is called to see if an entity can be used?
    • The IsUsable function
    • The OnUsed function
    • The OnInit function
  3. How do you make your Scriptbind function accessible from Lua?
    • Add a new function into the header (.h) file.
    • Implement the function in the source (.cpp) file.
    • Do a) and b), but also call SCRIPT_REG_TEMPLFUNC.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.233.43