photo

vec3 helper functions

Recommended Posts

Are there any similar functions like they are in Unity engine for vec3? In Unity engine there are methods in Vector3 class like Normalize() or Distance().

Share this post


Link to post

you also have free functions for dot and cross product (free as in: not member of the class, use them as: dot(v1,v2) or cross(v1,v2) )

Share this post


Link to post

And what about C# ?

Share this post


Link to post
Posted (edited)

Dear @romcioPaluszek,

Documentation needs an update. I understood your confusion.

This code is from  in C# project.

using Unigine;


vec3 vector = new vec3(5.0f, 5.0f, 5.0f);
vector.Normalize();
float x = vector.x;
float y = vector.y;
float z = vector.z;
float len = vector.Length;

Works Charm. And if in doubt with documentation. You may right click on vec3 and check the definition.

NOTE:: I use Visual Studio. Definitions can be browsed in it. Not sure about Visual Code.

#region Assembly UnigineSharpCore_x64d, Version=1.0.1.0, Culture=neutral, PublicKeyToken=f6ef6838e040fba0
// path_to\UnigineSharpCore_x64d.dll
#endregion

using Unigine;

namespace Unigine
{
    public struct vec3
    {
        public static readonly vec3 BACK;
        public static readonly vec3 LEFT;
        public static readonly vec3 RIGHT;
        public static readonly vec3 FORWARD;
        public static readonly vec3 ZERO;
        public static readonly vec3 ONE;
        public static readonly vec3 EPS;
        public static readonly vec3 INF;
        public static readonly vec3 UP;
        public static readonly vec3 DOWN;
        public float x;
        public float z;
        public float y;
        public float w;

        public vec3(vec4 v);
        public vec3(double[] v);
        public vec3(float[] v);
        public vec3(ivec4 v);
        public vec3(ivec2 v);
        public vec3(dvec4 v);
        public vec3(dvec3 v);
        public vec3(dvec2 v);
        public vec3(vec3 v);
        public vec3(ivec3 v);
        public vec3(double v);
        public vec3(float v);
        public vec3(vec2 v);
        public vec3(dvec2 v, double vz);
        public vec3(vec2 v, float vz);
        public vec3(double vx, double vy, float vz);
        public vec3(float vx, float vy, float vz);

        public float MaxXY { get; }
        public float Length { get; }
        public float Length2 { get; }
        public vec3 Normalized { get; }
        public float Max { get; }

        public static float Dot(vec3 v0, vec3 v1);
        public static vec3 Lerp(vec3 v0, vec3 v1, float k);
        public float Dot(vec3 v);
        public bool Equals(vec3 v, float epsilon);
        public vec3 Equals(vec3 v_min, vec3 v_max);
        public vec3 Lerp(vec3 v, float k);
        public vec3 Normalize();
        public vec3 Saturate();
        public vec3 SetX(float v);
        public void SetY(float v);
        public override string ToString();

        public static vec3 operator +(vec3 v0, vec3 v1);
        public static vec3 operator +(vec3 v0, dvec3 v1);
        public static vec3 operator -(vec3 v);
        public static vec3 operator -(vec3 v0, vec3 v1);
        public static vec3 operator -(vec3 v0, dvec3 v1);
        public static vec3 operator *(vec3 v0, float v1);
        public static vec3 operator *(vec3 v0, dvec3 v1);
        public static vec3 operator *(vec3 v0, double v1);
        public static vec3 operator *(vec3 v0, vec3 v1);
        public static vec3 operator /(vec3 v0, float v1);
        public static vec3 operator /(vec3 v0, vec3 v1);
        public static vec3 operator /(vec3 v0, dvec3 v1);
        public static vec3 operator /(vec3 v0, double v1);
    }
}

So you can use..

C# documentation is confusing at many places.

Rohit

 

Edited by rohit.gonsalves

Share this post


Link to post

Yeah, documentation for some classes in C# may be confusing. Right now we are rewriting entire C# mathlib (to increase performance and add missing utility methods). This is not a fast process, please bear with us :)

We will take a look the documentation generation after 2.12 release.

Share this post


Link to post

Thanks for your answers. They finally helped me to find solution. One more question. I miss in quat struct functions that are in Unity3D engine in Quaternion class ( Quaternion.AngleAxis and Quaternion.Euler). Are there any alternatives in Unigine? I searched forum and docs, but did not found any solution. These functions are last step to port our Unity project to Unigine.

Share this post


Link to post

Hello,

Instead of Quaternion.AngleAxis you can use quaternion constructor with the axis and angle parameters:

float angle = 30.0f;
vec3 axis = vec3.FORWARD;
quat rotation = new quat(axis, angle);

Also function Quaternion.Euler can be replaced by quaternion constructor with angles parameters:
 

float x = 0.0f;
float y = 30.0f;
float z = 0.0f;
quat rotation = new quat(x, y, z);

 

Share this post


Link to post