Example #1
0
        public ParticleDigging(World world, Vector3 pos, Vector3 motion, float particleScale, BlockState state, FaceSides side) : base(world, pos, motion, particleScale, JsonModelLoader.TextureBlocks)
        {
            State = state;

            if (state.Model.RawModel is ModelBlockRaw)
            {
                var tex = state.Model.ParticleTexture;

                Vector2 start = tex.UVMin;
                Vector2 end   = tex.UVMax;

                Vector2 size = end - start;

                Vector2 pixel = size / 16;

                UVmin = start + pixel * new Vector2(MathUtil.NextFloat(0, 12), MathUtil.NextFloat(0, 12));
                UVmax = UVmin + pixel * 4;
            }

            if (side == FaceSides.Up)
            {
                Motion.Xz = SharpCraft.Instance.Camera.GetLookVec().Xz * 0.15f;
            }

            Vector3 vec = new Vector3(MathUtil.NextFloat(-1), MathUtil.NextFloat(-1), MathUtil.NextFloat(-1));

            _rotStep = vec.Normalized() * MathUtil.NextFloat(40, 75);
        }
Example #2
0
 //Spotlight constructor, takes a position Vector, a color Vector, a direction Vector and 
 public Spotlight(Vector3 position, Vector3 color, Vector3 direction, float minDot)
 {
     pos = position;
     this.color = color;
     D = direction.Normalized();
     this.minDot = minDot;
 }
Example #3
0
    public static OpenTK.Matrix4 GLLookAt(OpenTK.Vector3 eye, OpenTK.Vector3 center, OpenTK.Vector3 up)
    {
        OpenTK.Vector3 forward = (center - eye).Normalized();
        OpenTK.Vector3 upN     = up.Normalized();
        OpenTK.Vector3 right   = OpenTK.Vector3.Cross(forward, upN).Normalized();
        OpenTK.Vector3 u       = OpenTK.Vector3.Cross(right, forward);
        OpenTK.Matrix4 ret     = new OpenTK.Matrix4();

        ret.M11 = right[0]; ret.M12 = u[0]; ret.M13 = -forward[0]; ret.M14 = 0;
        ret.M21 = right[1]; ret.M22 = u[1]; ret.M23 = -forward[1]; ret.M24 = 0;
        ret.M31 = right[2]; ret.M32 = u[2]; ret.M33 = -forward[2]; ret.M34 = 0;
        ret.M41 = 0; ret.M42 = 0; ret.M43 = 0; ret.M44 = 1;

        OpenTK.Matrix4 tmp = OpenTK.Matrix4.CreateTranslation(-eye);

        OpenTK.Matrix4 finalRet = ret * tmp;
        finalRet = tmp * ret;

        return(finalRet);
    }
Example #4
0
 public Ray(Vector3 origin, Vector3 direction)
 {
     Origin = origin;
     Direction = direction.Normalized();
 }
Example #5
0
        private void SpawnProjectile()
        {
            Byt3.Engine.Physics.BEPUutilities.Vector3 v = Vector3.Zero;
            if (Grounded || !CameraRaycaster.ObjectUnderMouse(GameEngine.Instance.CurrentScene.Camera.LocalPosition,
                                                              out KeyValuePair <Collider, RayHit> hit))
            {
                Byt3.Engine.Physics.BEPUutilities.Vector3 vel =
                    new Vector3(-Vector4.UnitZ * nozzle.GetWorldTransform()) * BulletLaunchForce;
                v = vel;
            }
            else
            {
                Vector3 pos = hit.Value.Location;
                //pos.Y = looker.LocalPosition.Y;
                nozzle.LookAt(pos);
                Byt3.Engine.Physics.BEPUutilities.Vector3 vel =
                    new Vector3(-Vector4.UnitZ * nozzle.GetWorldTransform()) * BulletLaunchForce;
                v = vel;
            }

            Vector3    v1  = v;
            GameObject obj =
                new GameObject(nozzle.LocalPosition + (Byt3.Engine.Physics.BEPUutilities.Vector3)v1.Normalized(),
                               "BulletPlayer");

            obj.Rotation = nozzle.Rotation;
            obj.AddComponent(new LitMeshRendererComponent(bulletShader, bulletModel, bulletTexture, 1, false));
            obj.AddComponent(new DestroyTimer(5));
            obj.Scale = new Vector3(0.3f, 0.3f, 1);

            Collider coll = new Collider(new Box(Vector3.Zero, 0.3f, 0.3f, 1, BulletMass), bulletLayer);

            coll.PhysicsCollider.PositionUpdateMode = PositionUpdateMode.Continuous;
            if (!physicalBullets)
            {
                coll.IsTrigger = true;
            }

            obj.AddComponent(coll);
            coll.PhysicsCollider.ApplyLinearImpulse(ref v);
            Owner.Scene.Add(obj);
            //AudioSource.Clip = ShootSound;
            //AudioSource.Play();
            AudioSource.Clip = BulletsPerSecond < 20 ? ShootSound : ShootSound2;
            AudioSource.Play();
        }
Example #6
0
        public Primitive objectHit; //The primitive the ray hits (if applicable).

        public Ray(Vector3 Origin, Vector3 Direction, float length)
        {
            O = Origin;
            D = Direction.Normalized();
            l = length;
        }
Example #7
0
    public void ConstraintLookAt(Vector3 targetAbsRef, Vector3 upRelRef, Vector3 constraintAxisSelect)
    {

        Vector3 targetRelRef;

        if (IsChild)
            targetRelRef = Geometric.Quaternion_Rotate(_parentModel.Orientation.Inverted(), targetAbsRef);
        else
            targetRelRef = targetAbsRef;

        if (constraintAxisSelect.X != 0)
            targetRelRef.X = 0;
        else if (constraintAxisSelect.Y != 0)
            targetRelRef.Y = 0;
        else if (constraintAxisSelect.Z != 0)
            targetRelRef.Z = 0;

        //Vector v1 = new Vector3(0, 0, -1);
        //Vector moveV = _staticModel.Position - vector;
        //Vector v2 = moveV.RotateBy(_staticModel.Orientation.W, 0, 1, 0);

        /*Vector forward = lookAt.Normalized();
        Vector right = Vector::Cross(up.Normalized(), forward);
        Vector up = Vector::Cross(forward, right);*/
        Vector3 forward;
        if (IsChild)
        {
            //Normalizing target and transforming it to local system
            forward = targetRelRef.Normalized() - _parentModel.Position;
        }
        else
        {
            //Normalizing target.. local system is the same as world system
            forward = targetRelRef.Normalized();
        }
        //Normalizing upVector (we are assuming it is expressed in local system)
        Vector3 eye = _position.Normalized();
        Vector3 up = upRelRef.Normalized();

        //Insert manual imprecision to avoid singularity
        if (Vector3.Dot(forward, up) == 1)
        {
            forward.X += 0.001f;
            forward.Y += 0.001f;
            forward.Z += 0.001f;
        }

        //float angle = (float)Math.Acos( Vector3.Dot(current,targetAbsRef) );
        //Vector3 rotAxis = Vector3.CrossProduct(current, forward).Normalized();
        //Vector3 right = Vector3.CrossProduct(forward, up);

        Matrix4 lookAt_result = Matrix4.LookAt(eye.X, eye.Y, eye.Z, forward.X, forward.Y, forward.Z, up.X, up.Y, up.Z);
        Matrix3 targetRelOrientation_matrix = new Matrix3(lookAt_result);
        Quaternion targetRelOrientation_quaternion = Quaternion.FromMatrix(targetRelOrientation_matrix);

        /*
        Quaternion targetRelOrientation_quaternion = new Quaternion();
        targetRelOrientation_quaternion.W = (float)Math.Sqrt((double)(1.0f + right.X + up.Y + forward.Z)) * 0.5f;
        float w4_recip = 1.0f / (4.0f * targetRelOrientation_quaternion.W);
        targetRelOrientation_quaternion.X = (forward.Y - up.Z) * w4_recip;
        targetRelOrientation_quaternion.Y = (right.Z - forward.X) * w4_recip;
        targetRelOrientation_quaternion.Z = (up.X - right.Y) * w4_recip;
        */

        _orientation = targetRelOrientation_quaternion;

    }