/*Vibe2Game engine API reference v1.53*/ /*Note: in this API reference, a '[primitive]' parameter can be any of the following types: Triangle, Sphere, Box, Cylinder, Text. The maximum supported number of primitives is 16384 (256 for Text primitive)*/ #define FLT_EPSILON 0.000001 #define FLT_MAX 3.402823466e+38f #define PI 3.141593 typedef struct { float x; float y; float z; float w; } Quaternion; typedef struct { float x; float y; } Vector2; typedef struct { float x; float y; float z; } Vector3; typedef struct { float x; float y; float z; float w; } Vector4; typedef struct { float r; float g; float b; float a; } Color; typedef int PointLight; typedef int Text; typedef int Material; typedef int Triangle; typedef int Sphere; typedef int Box; typedef int Cylinder; typedef int Spline; bool Game_IsInitializing(); /*Returns true at the very first game loop. Used to determine when to execute code that initializes the game*/ float Game_GetTime(); /*Gets the elapsed time, in seconds, since the game was started*/ float Game_GetTick(); /*Gets the time, in seconds, taken by the previous game loop to execute. Typically used to make quantities, like speed, not influenced by frame rate (example: location = location + speed*Game_GetTick())*/ Randomizer_SetDeterministicSeed(int seed); /*Initializes the deterministic randomizer. Given the seed, ...Deterministic() functions in this API will always produce the same sequence of outputs*/ float Float_ACos(float c); float Float_ASin(float s); float Float_ATan(float t); float Float_ATan2(float y,float x); float Float_Cos(float c); float Float_Sin(float s); float Float_Tan(float t); float Float_Pow(float x,float y); float Float_Exp(float f); float Float_Sqrt(float f); float Float_Sign(float f); float Float_Ceil(float f); float Float_Floor(float f); float Float_Trunc(float f); float Float_Round(float f); float Float_Abs(float f); float Float_Max(float x,float y); float Float_Min(float x,float y); float Float_Clamp(float f,float min,float max); float Float_Mod(float x,float y); float Float_Wrap(float f,float min,float max); float Float_Interpolate(float a,float b,float interpolateionFactor); float Float_MapRange(float f,float rangeMin,float rangeMax,float mappedMin,float mappedMax,bool clamp); /*Maps a value from one range to another, optionally clamping the result to the target range*/ float Float_Randomize(float min,float max); /*Randomizes a float value between min and max (inclusive). Output is non-deterministic*/ float Float_RandomizeDeterministic(float min,float max); /*Randomizes a float value between min and max (inclusive)*/ int Int_Sign(int i); int Int_Clamp(int i,int min,int max); int Int_Wrap(int i,int min,int max); int Int_Randomize(int min,int max); /*Randomizes an integer value between min and max (inclusive). Output is non-deterministic*/ int Int_RandomizeDeterministic(int min,int max); /*Randomizes an integer value between min and max (inclusive)*/ Quaternion Quaternion_Create(float x,float y,float z,float w); /*Quaternions represent orientations/rotations*/ Quaternion Quaternion_CreateFromEulerAngles(float xAngleInRadians,float yAngleInRadians,float zAngleInRadians,int rotationsOrderId); /*rotationsOrderId: 0=xyz,1=xzy,2=yxz,3=yzx,4=zxy,5=zyx*/ Quaternion Quaternion_CreateFromAxisAngle(Vector3 axis,float angleInRadians); Quaternion Quaternion_CreateFromDirection(Vector3 direction); /*Creates a quaternion that orients a primitive (or the 'forward' vector created with Vector3_Create(0.0f,0.0f-1.0f)) towards the specified direction*/ Quaternion Quaternion_Invert(Quaternion q); /*For example, the inverse of a 0.65 radians rotation about the Y axis is a -0.65 radians rotation about the Y axis*/ Quaternion Quaternion_Multiply(Quaternion qA,Quaternion qB); /*Multiplying two quaternion means adding the two rotations they represent*/ Quaternion Quaternion_Slerp(Quaternion qA,Quaternion qB,float slerpFactor); /*For 'slerpFactor' values between 0 and 1, returns a rotation interpolated between qA and qB*/ Vector2 Vector2_Create(float x,float y); /*The Vector2 type natively supports arithmetic (+,-,*,/,%) and negation (-) operators. They all operate component-wise and are automatically overloaded to work in combination with the 'float' type*/ float Vector2_Dot(Vector2 a,Vector2 b); Vector2 Vector2_Normalize(Vector2 v); float Vector2_Length(Vector2 v); float Vector2_Distance(Vector2 a,Vector2 b); Vector2 Vector2_Interpolate(Vector2 a,Vector2 b,float interpolateionFactor); Vector3 Vector3_Create(float x,float y,float z); /*The Vector3 type natively supports arithmetic (+,-,*,/,%) and negation (-) operators. They all operate component-wise and are automatically overloaded to work in combination with the 'float' type*/ float Vector3_Dot(Vector3 a,Vector3 b); Vector3 Vector3_Cross(Vector3 a,Vector3 b); Vector3 Vector3_Normalize(Vector3 v); float Vector3_Length(Vector3 v); float Vector3_Distance(Vector3 a,Vector3 b); Vector3 Vector3_Interpolate(Vector3 a,Vector3 b,float interpolateionFactor); Vector3 Vector3_RotateWithQuaternion(Vector3 v,Quaternion q); Vector4 Vector4_Create(float x,float y,float z,float w); /*The Vector4 type natively supports arithmetic (+,-,*,/,%) and negation (-) operators. They all operate component-wise and are automatically overloaded to work in combination with the 'float' type*/ float Vector4_Dot(Vector4 a,Vector4 b); Vector4 Vector4_Normalize(Vector4 v); Color Color_Create(float r,float g,float b,float a); /*Component values are in the 0.0f-1.0f range, 4 values in total, for red, green, blue and alpha*/ Color Color_Interpolate(Color a,Color b,float interpolateionFactor); void AmbientLight_Set(Color color); /*Example: AmbientLight_Set(Color_Create(0.1f, 0.1f, 0.1f, 1.0f))*/ void Environment_SetGradient(Color horizonColor,Color gradientColor1,Color gradientColor2,Color zenithAndNadirColor,float gradientStop1,float gradientStop2); PointLight PointLight_Create(float visualProxyRadius); /*If 'visualProxyRadius' is > 0, an un-shaded sphere of the specified radius will be rendered to visualize where the light source is. The maximum supported number of lights is 32. Do not call this function outside the 'IsInitializing(){}' section*/ void PointLight_SetLocation(PointLight pointLight,Vector3 location); void PointLight_SetColor(PointLight pointLight,Color color); /*Light color is also typically used to set light intensity (the darker the color, the dimmer the light). Color components greater than one are supported, for overexposure-based effects, like bright flashes, extremely bright light sources etc*/ void PointLight_SetEmissivityRange(PointLight pointLight,float emissivityRange); /*Emissivity range is the distance at which illumination becomes zero. Note that this is typically used to limit illumination to specific areas, rather than adjusting light intensity*/ Material Material_Create(); /*The maximum supported number of materials is 16384. Do not call this function outside the 'IsInitializing(){}' section*/ Material_SetColor(Material material,Color color); Material_SetGlossiness(Material material,float glossiness); /*Use the following glossiness values as reference: 0.0f=no-glossiness,0.01f=dull-rubber,0.025f=rubber,0.035f=dull-plastic,0.05f=matte-plastic,0.1f=common-plastic,0.25f=glossy-plastic,0.5f=polished-plastic,2.5f=painted-metal. Glossiness = -1.0f makes the material look un-shaded (can be used to fake glowing objects or distant lights, like stars, without using light sources)*/ Triangle Primitive_CreateTriangle(); /*Adds a triangle to the scene (returns a Triangle primitive). Triangles are double-faced*/ bool Primitive_IsTriangle(Triangle triangle); /*Typically used to check if the primitive returned by functions like Clicked_GetPrimitive() is a valid Triangle primitive*/ void Primitive_SetTriangleVertices(Triangle triangle,Vector3 vertex0,Vector3 vertex1,Vector3 vertex2); /*Locations are in triangle's local coordinates*/ Sphere Primitive_CreateSphere(); /*Adds a sphere to the scene (returns a Sphere primitive)*/ bool Primitive_IsSphere(Sphere sphere); /*Typically used to check if the primitive returned by functions like Clicked_GetPrimitive() is a valid Sphere primitive*/ void Primitive_SetSphereRadius(Sphere sphere,float radius); void Primitive_SetSphereShrinking(Sphere sphere,float shrinking); /*Between 0.0f and 1.0f (i.e. scale-down only). Sphere width (X dimension) scaling allows rendering of ellipsoids*/ void Primitive_SetSphereFlattening(Sphere sphere,float flattening); /*Between 0.0f and 1.0f (i.e. scale-down only). Sphere height (Y dimension) scaling allows rendering of ellipsoids*/ void Primitive_SetSphereShortening(Sphere sphere,float shortening); /*Between 0.0f and 1.0f (i.e. scale-down only). Sphere length (Z dimension) scaling allows rendering of ellipsoids*/ Box Primitive_CreateBox(); /*Adds a box to the scene (returns a Box primitive). Setting the location of a Box means setting the location of the Box center. This is also the 'pivot' used when setting the Box orientation.*/ bool Primitive_IsBox(Box box); /*Typically used to check if the primitive returned by functions like Clicked_GetPrimitive() is a valid Box primitive*/ void Primitive_SetBoxDimensions(Box box,Vector3 dimensions); /*The 'dimensions' parameter is a vector of 3 positive values representing the X, Y and Z size of the box*/ void Primitive_SetBoxCornerRadius(Box box,float cornerRadius); /*A non-zero corner radius make the Box a 'rounded box'*/ void Primitive_SetBoxFrontShrinking(Box box,float shrinking); /*Between 0.0f and 1.0f (i.e. scale-down only). Width scaling of the Box front face (the -Z side) allows rendering of capped and not capped prisms and pyramids*/ void Primitive_SetBoxFrontFlattening(Box box,float flattening); /*Between 0.0f and 1.0f (i.e. scale-down only) Height scaling of the Box front face (the -Z side) allows rendering of capped and not capped prisms and pyramids*/ Cylinder Primitive_CreateCylinder(); /*Adds Cylinder to the scene (returns a Cylinder primitive). This is a cylinder aligned with the Z axis. The front cap is towards -Z. Setting the location of a Cylinder means setting the location of the Cylinder center. This is also the 'pivot' used when setting the Cylinder orientation.*/ bool Primitive_IsCylinder(Cylinder cylinder); /*Typically used to check if the primitive returned by functions like Clicked_GetPrimitive() is a valid Cylinder primitive*/ void Primitive_SetCylinderLength(Cylinder cylinder,float cylinderLength); /*The distance between the centers of the two spheres representing the Cylinder caps. The total length of the primitive is therefore [cylinderLength + cylinderRadiusA*0.5 + cylinderRadiusB*0.5]*/ void Primitive_SetCylinderRadii(Cylinder cylinder,float cylinderRadiusA,float cylinderRadiusB); /*Cylinder emispherical caps can be of different radius. The 'cylinderRadiusA' is the radius of back cap (+Z side). The 'cylinderRadiusB' is the radius of front cap (-Z side)*/ void Primitive_SetCylinderCornerRadius(Cylinder cylinder,float cornerRadius); /*A non-zero corner radius make the Cylinder a 'rounded cylinder'*/ void Primitive_SetCylinderFlattening(Cylinder cylinder,float flattening); /*Between 0.0f and 1.0f (i.e. scale-down only). Cylinder Y scaling is often used to render object like airplane wings, fish fins etc*/ Text Primitive_CreateText([stringLiteral]); /*The Text primitive is rendered as a 2D box with the specified text inside. The [stringLiteral] parameter must be a literal in quotes, like "hello world". It can however include numerical templates (e.g. "Amount = $(#0.2)" or "Distance is (#5.3) miles" or "Score: (#0.0)") that can then be set by using the Primitive_SetTextNumber() function (to make the previous examples look like: "Amount = $12.50" "Distance is 00012.500 miles" and "Score: 7981)". Setting the location of a Text primitive means setting the location, on screen, of the text box center. For reference, [0.0,0.0,0.0] is the screen center, [-1.0,-1.0,0.0] is the bottom-left corner, [1.0,1.0,0.0] is the top-right corner. The Z coordinate is typically zero. If negative, the text is not rendered (assumed 'behind the camera'). Setting the orientation of a Text primitive (a Quaternion) means setting the text box orientation about the text box center, using only the Z axis orientation of the quaternion. Do not call this function outside the 'IsInitializing(){}' section*/ bool Primitive_IsText(Text text); /*Typically used to check if the primitive returned by functions like Clicked_GetPrimitive() is a valid Text primitive*/ void Primitive_SetTextFont(Text text,int fontId); /*the 'fontId' supported values: 0=Arial,1=Arial Black,2=Brush Script MT,3=Comic Sans MS,4=Courier,5=Courier New,6=Garamond,7=Georgia,8=Gill Sans,9=Helvetica,10=Impact,11=Lucida Console,12=Monaco,13=Palatino,14=Tahoma,15=Times,16=Times New Roman,17=Trebuchet MS,18=Verdana*/ void Primitive_SetTextWrapping(Text text,bool useWrapping); /*If 'true' the text will be split into multiple lines to fit the largest font-size possible within the defined text label size*/ void Primitive_SetTextSize(Text text,float width,float heigh); /*Size of the Text item box. A width of 2.0f corresponds to the full display width, a height of 2.0f corresponds to the full display height. For example, to make a text box cover the entire screen except a small margin on all sides, place it at [0.0f,0.0f] and set its size to [1.95f,1.95f]. Another example: place a text box with a size of [0.4f,0.06f] at the top-left screen corner, place it at [-1.0f+0.4f*0.5f,1.0f-0.06f*0.5f]*/ void Primitive_SetTextMargin(Text text,float widthMargint,float heightMargin); /*Sets the space between the text box borders and the text inside it*/ void Primitive_SetTextColor(Text text,Color textColor); void Primitive_SetTextBackgroundColor(Text text,Color backgroundColor); void Primitive_SetTextCornerRadius(Text text,int cornerRadiusInPixels); /*Sets the radius of the rounded corners of the box surrounding the text. Use zero for sharp corners*/ void Primitive_SetTextBackdropBlur(Text text,int blurInPixels); /*Typical 'blurInPixels' value is 8. Use zero to disable backdrop blurring effect*/ void Primitive_SetTextNumber(Text text,int valueId,float value); /*The 'valueId' parameter indicates the numerical template to set, where template 0 is the first template encountered in the string, 1 is the second and so on*/ void Primitive_SetInvisible([primitive] primitive,bool invisible); /*Invisible primitives are not rendered and are ignored for collision detection or ray checking*/ void Primitive_SetOrientation([primitive] primitive,Quaternion orientation); /*For reference, when the camera has zero rotation, on screen a positive rotation about the Z (depth) axis is anti-clockwise, assuming the quaternion was created with Quaternion_CreateFromEulerAngles(0,0,angleInRadians,0) or with Quaternion_CreateFromAxisAngle(Vector3_Create(0.0f,0.0f,1.0f),angleInRadians)*/ Quaternion Primitive_GetOrientation([primitive] primitive); void Primitive_SetLocation([primitive] primitive,Vector3 location); /*Sets the location of the primitive center. If the primitive is Text, see Primitive_SetTextSize() for placement examples*/ Vector3 Primitive_GetLocation([primitive] primitive); void Primitive_SetMaterial([primitive] primitive,Material material); /*For Text, see Primitive_SetTextColor() instead*/ bool Primitive_CollisionCheck([primitive] primitiveA,[primitive] primitiveB,bool fastMode); /*Returns true if the two primitives approximately intersect. This function gurantees no false negatives, but false positives are possible when the shapes are close to one another or at least one shape is elongated (like a long cylinder or a nearly degenerate triangle). When 'fastMode' is true, detection is even more approximate, but this mode is very fast to process and allows games with hundreds of collision detection queries per game loop to keep an acceptable frame rate*/ int Clicked_GetPrimitive(); /*Gets the primitive tapped/clicked by the user during the current game loop. An invalid id (-2) is returned if the mouse was not clicked or (-1) if it was clicked but no primitive was hit. Note that this function returns the correct (non-negative) primitive at the moment of a mouse click (i.e. when the Mouse_Click() function returns true)*/ Vector3 Clicked_GetLocation(); /*Returns the tapped location on the surface of the primitive (except Text) tapped/clicked during the current game loop. Note that the returned location is only valid if Clicked_GetPrimitive() returns a valid primitive identifier during the current game loop.*/ Vector3 Clicked_GetNormal(); /*Returns the surface normal at the tapped location on the surface of the primitive (except Text) tapped/clicked during the current game loop. Note that the returned normal is only valid if Clicked_GetPrimitive() returns a valid primitive identifier during the current game loop*/ bool RayCheck(Vector3 rayFrom,Vector3 rayTo,[primitive] primitive); /*Returns true if the line segment between the 'rayFrom' and 'rayTo' locations intersects the specified primitive (except Text)*/ Vector3 RayCheck_GetLocation(); /*If called right after RayCheck() (assuming RayCheck() returned true), returns the location the ray hit the primitive at*/ Vector3 RayCheck_GetNormal(); /*If called right after RayCheck() (assuming RayCheck() returned true), returns the surface normal at the location the ray hit the primitive at*/ bool Mouse_Down(); /*Returns true if the mouse button is pressed*/ bool Mouse_Click(); /*Returns true if the mouse button was clicked (went from non-pressed to pressed) during the current game loop*/ float Mouse_X(); /*Returns the mouse pointer X location (undefined unless the mouse is currently pressed or being clicked). The value is between -1.0f (left display border) and 1.0f (right display border)*/ float Mouse_Y(); /*Returns the mouse pointer Y location (undefined unless the mouse is currently pressed or being clicked). The value is between -1.0f (bottom display border) and 1.0f (top display border)*/ void View_SetMode(int modeId); /*modeId=0: default view mode. Makes the camera look at a specified (and usually moving) location while trying to reach a specified (and usually moving) target position in space. modeId=1: auto-orbit view mode. Makes the camera look at a specified location while orbiting (azimuth variation) around it, while optionally also swinging (elevation variation) up and down. modeId=2: orbit view mode. Allows the player to orbit the camera around a specified location while looking at it. When the look-at location is moving (for example a moving vehicle), this view mode is often a better option than mode 0 because the player can use the orbiting functionality to view the tracked subject (and the surroundings) from any angle*/ void View_SetClipPlanes(float nearClipDistance,float farClipDistance); void View_SetFieldOfViewAngle(float fieldOfViewAngleInDegrees); void View_InitAutoOrbit(float cameraElevationInDegrees,float cameraAzimuthInDegrees,float cameraDistanceInMeters,float elevationMinInDegrees,float elevationMaxInDegrees,float elevationSpeedInDegreesPerSecond,float azimuthSpeedInDegreesPerSecond); /*Initializes the camera position and the look-at location for the view mode control enabled with View_SetMode(1). Positive elevation values make the camera take the 'lookAtLocation' from above. Positive azimuth values orbit the camera clockwise around the 'lookAtLocation'. The 'elevationMinInDegrees' and 'elevationMaxInDegrees' set the swing range for the elevation ('elevationSpeedInDegreesPerSecond' is the average swing speed).*/ void View_InitOrbit(float cameraElevationInDegrees,float cameraAzimuthInDegrees,float cameraDistanceInMeters); /*Initializes the camera position and the look-at location for the view mode control enabled with View_SetMode(2). Positive elevation values make the camera take the 'lookAtLocation' from above. Positive azimuth values orbit the camera clockwise around the 'lookAtLocation'*/ void View_SetTargetOrientation(Quaternion targetOrientation); /*Sets the reference orientation used to compute the actual location the camera will try to reach, for the view mode enabled with View_SetMode(0). This function is typically called at every game loop with the player-controlled actor's orientation as parameter. See also View_SetTargetLocationOffset()*/ void View_SetTargetLocation(Vector3 targetLocation); /*Sets the reference location used to compute the actual location the camera will try to reach, for the view mode enabled with View_SetMode(0). This function is typically called at every game loop with the player-controlled actor's location as parameter. See also View_SetTargetLocationOffset()*/ void View_SetTargetLocationOffset(Vector3 targetLocationOffset); /*The actual location the camera will try to reach is the one set with View_SetTargetLocation() plus the offset set here. Note that this offset is also rotated about the base location with the orientation set with View_SetTargetOrientation() (i.e., the offset is local to the target). For example, a [0.0f,0.0f,10.0f] offset is 10 units behind the target*/ void View_SetLookAtLocation(Vector3 lookAtLocation); /*Sets the look-at location for the current view mode (see View_SetMode())*/ void View_SetResponse(float viewAngularResponse,float viewLinearResponse); /*Used to make the view smoothly track/follow a moving look-at location (e.g. a moving subject). The smaller the response values, the smoother ('lazier') the view. Typical response values are 0.1f. Response values = 1.0f make the camera track the subject (or reach it's intended position) immediately. Zero response means the camera will not move at all. This setting is supported by all view modes (including mode 2)*/ void View_SetLockCameraRoll(int lockCameraRoll); /*For the view mode enabled with View_SetMode(0), locking the camera roll is used to follow the player-controlled actor like in a typical 3rd person view game*/ void View_SetZoomSensitivity(float zoomSensitivity); /*Sets the zoom control sensitivity for the view mode control enabled with View_SetMode(2). Default is 5.0f. Setting it to zero disables the ability to the zoom the view*/ Vector3 View_Project3DLocationToScreen(Vector3 location); /*Returns the screen coordinates (.x and .y component of the returned Vector3) of the specified world location. For reference, a returned value of [0.0f,0.0f,any-value] means screen center, [-1.0f,-1.0f,any-value] is the bottom-left corner, [1.0f,1.0f,any-value] is the top-right corner. The .z component of the returned Vector3 is the distance, from the camera, of the original 3d location, with negative values indicating that the 3d location is behind the camera*/ Spline Spline_Create(int controlPointCount); /*A spline is a list of control points defining a path in space. The path is guaranteed to pass through all defined control points. The fewer the points, the better the performance*/ void Spline_SetControlPointLocation(Spline,int controlPointId,Vector3 controlPointLocation); /*Sets the location of a Spline control point. Closed paths must have the first and last control points at exactly the same coordinates. Tip: use this function to reuse a spline if the only changes are control point locations*/ Vector3 Spline_GetControlPointLocation(Spline,int controlPointId); /*Returns the location of a Spline control point*/ Vector3 Spline_GetLocationAtTime(Spline,float splineTime); /*Returns the location in space of the path at the specified 'time'. Time 0.0f is the beginning of the spline path. Time 1.0f is the end of the spline path. The Vector3 returned by this function is typically used to set the location of an object, to make it follow the Spline path*/ Quaternion Spline_GetOrientationAtTime(Spline,float splineTime,float tiltFactor,float tiltSmoothness); /*Returns the orientation in space of the path at the specified 'time'. For example, when this orientation is applied to a [0.0f,0.0f,1.0f] Vector3 (using Vector3_RotateWithQuaternion()), the resulting vector indicates the local 'forward' direction of the path at the specified time. If 'tiltFactor' is non-zero (typically around 0.2), an object oriented using the returned Quaternion will be 'tilted' about the local 'forward' direction, towards the inside of a path's curve, in a way similar to how a motorbike tilts on road bends. The 'tiltSmoothness' (typically around 0.25) can be increased if the tilt action is too quick*/ Vector3 Spline_GetCurvatureAtTime(Spline,float splineTime,float curvatureSmoothness); /*Returns a vector pointing towards the 'outside' of the path curvature at the specified 'time'. The length of the returned vector is proportional to the degree of curvature and the 'curvatureSmoothness' parameter. As a rule of thumb, a circular path with a radius of 100.0f would return a vector about 5.0f units long (assuming a 'curvatureSmoothness' of about 0.25).*/ float Spline_GetLength(Spline); /*Returns the total length of a Spline*/