コード例 #1
0
ファイル: Test.cs プロジェクト: MeLikeyCode/GodotTutorials
    public override void _Ready()
    {
        // local to parent
        var result = Transform.Xform(new Vector2(10, 10));

        GD.Print("(10,10), local to parent: ", result);

        // parent to local
        var result2 = Transform.Inverse().Xform(result);

        GD.Print($"{result}, parent to local: ", result2);

        var result3 = Transform.XformInv(result);

        GD.Print("parent to local, way 2: ", result3);

        // local to global
        var result4 = GlobalTransform.Xform(new Vector2(10, 10));

        GD.Print("(10,10), local to global: ", result4);

        // global to local
        var result5 = GlobalTransform.XformInv(result4);

        GD.Print($"{result4}, global to local");

        // sibling to sibling
        var sibling = GetNode <Godot.Sprite>("../Child2");

        var asGlobal = GlobalTransform.Xform(new Vector2(10, 10));
        var result6  = sibling.GlobalTransform.XformInv(asGlobal);

        GD.Print("(10,10), local to sibling: ", result6);
    }
コード例 #2
0
    public override void _Process(float delta)
    {
        loopCount++;

        var localRight = Transform.basis.Column0;
        var localUp    = Transform.basis.Column1;
        var localFwd   = Transform.basis.Column2;


        Translate(Vector3.Forward * delta * 10);

        //var targetDiff = GlobalTransform.origin - steerTarget;

        var desiredXform = GlobalTransform.LookingAt(steerTarget, Vector3.Up);

        GlobalTransform = GlobalTransform.InterpolateWith(desiredXform, 1f * delta);

        //        Transform.Rotated(Vector3.Up)

        //Transform.
        //Transform.InterpolateWith

        if (loopCount % 100 == 0)
        {
            GD.Print($"{loopCount / 100}: localFwd={localFwd.ToString("F2")}");
        }

        //Transform.InterpolateWith

        //GD.Print("steerTarget", steerTarget);
    }
コード例 #3
0
ファイル: WidgetAdapter3D.cs プロジェクト: klenin/Citrus
        internal protected override bool PartialHitTest(ref HitTestArgs args)
        {
            if (Widget == null)
            {
                return(false);
            }
            var plane    = GetPlane();
            var ray      = args.Ray;
            var distance = ray.Intersects(plane);

            if (distance.HasValue && distance <= args.Distance)
            {
                var oldPoint = args.Point;
                try {
                    args.Point = (Vector2)GlobalTransform.CalcInverted().TransformVector(ray.Position + ray.Direction * distance.Value) * new Vector2(1, -1);
                    Widget.RenderChainBuilder?.AddToRenderChain(renderChain);
                    if (renderChain.HitTest(ref args))
                    {
                        args.Distance = distance.Value;
                        return(true);
                    }
                } finally {
                    args.Point = oldPoint;
                    renderChain.Clear();
                }
            }
            return(false);
        }
コード例 #4
0
    public virtual void Draw()
    {
        if (Multimesh != null)
        {
            int visibleParticles = 0;
            foreach (Particle particle in particles)
            {
                if (particle.alive)
                {
                    Transform t = particle.transform;

                    if (!local)
                    {
                        t = GlobalTransform.AffineInverse() * t;
                    }

                    Multimesh.SetInstanceTransform(visibleParticles, t);
                    Multimesh.SetInstanceColor(visibleParticles, particle.color);
                    visibleParticles++;
                }
            }

            Multimesh.VisibleInstanceCount = visibleParticles;
        }
    }
コード例 #5
0
    protected override void OnDrawScene(SceneView scene)
    {
        Waypoint  keyframe = Target;
        Crazyflie drone    = keyframe.Drone;

        CrazyflieEditor.Draw(drone);
        Vector3 position = GlobalTransform.Transfomed(keyframe.Position);

        if (keyframe.JointType != JointType.Linear)
        {
            DrawTangent(keyframe, false);
            DrawTangent(keyframe, true);
        }

        if (targetPoint == 0)
        {
            CustomHandles.DrawCircle(position, 0.0375f, Color.yellow);
            MoveHandle(keyframe, position, 0.06f, 0.045f, keyframe.SetPosition);
        }
        else
        {
            CustomHandles.DrawCircle(position, 0.0375f, Color.white);
        }

        if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Delete)
        {
            drone.RemoveWaypoint(Target);
        }


        // -- GUI -- //
        DrawGUI(keyframe);
    }
コード例 #6
0
        public Matrix44 CalcPointTransform(float amount)
        {
            var length       = 0f;
            var segmentCount = GetSegmentCount();
            var scale        = GlobalTransform.GetScale(false);

            for (int i = 0; i < segmentCount; i++)
            {
                var point1        = GetPoint(i);
                var point2        = GetPoint(i + 1);
                var segmentLength = ((point2.Position - point1.Position) * scale).Length;
                if (length <= amount && amount < length + segmentLength)
                {
                    return(Interpolate((amount - length) / segmentLength, point1, point2));
                }
                length += segmentLength;
            }
            if (Nodes.Count > 1)
            {
                return(Interpolate(1.0f, GetPoint(segmentCount - 1), GetPoint(segmentCount)));
            }
            if (Nodes.Count == 1)
            {
                return(Matrix44.CreateTranslation(((SplinePoint3D)Nodes[0]).Position));
            }
            return(Matrix44.Identity);
        }
コード例 #7
0
ファイル: ULevel.cs プロジェクト: solarisstar/ME3Explorer
 public void LoadStaticMeshComponents()
 {
     for (int i = 0; i < UStatComp.Count; i++)
     {
         int entry = UPR.FindObjectProperty("StaticMesh", UStatComp[i].props);
         if (entry >= 0 && entry < pcc.Header.ExportCount)
         {
             if (pcc.getClassName(pcc.Export[entry].Class) == "StaticMesh")
             {
                 UStaticMesh t = new UStaticMesh(pcc.EntryToBuff(entry), pcc.names);
                 t.ReadProperties(4);
                 t.index  = entry;
                 t.index2 = UStatComp[i].index;
                 t.index3 = i;
                 entry    = UPR.FindProperty("Scale3D", UStatComp[i].props);
                 LevelProperties LP = UStatComp[i].LP;
                 GlobalTransform g  = UStatComp[i].LP.GT;
                 if (entry != -1)
                 {
                     Vector3 v = PropToVector3(UStatComp[i].props[entry + 1].raw);
                     g.scl.X *= v.X;
                     g.scl.Y *= v.Y;
                     g.scl.Z *= v.Z;
                 }
                 g.scl *= g.scl2;
                 LP.GT  = g;
                 t.LP   = LP;
                 UStat.Add(t);
             }
         }
     }
 }
コード例 #8
0
    protected void DrawTangent(Waypoint keyframe, bool invert)
    {
        Vector3          position        = GlobalTransform.Transfomed(keyframe.Position);
        Vector3          tangentPosition = GlobalTransform.Transfomed(invert ? keyframe.InverseWorldTangent : keyframe.WorldTangent);
        Action <Vector3> applyFunction   = invert ? (Action <Vector3>)keyframe.SetInverseTangent : keyframe.SetTangent;

        Handles.color = Color.white;
        Handles.SphereHandleCap(0, tangentPosition, Quaternion.identity, 0.01f, EventType.Repaint);

        Handles.color = Palette.Translucent;
        Handles.DrawLine(position, tangentPosition);

        if (CustomHandles.SelectableButton(tangentPosition, 0.015f, Color.white))
        {
            targetPoint = (invert ? 2 : 1);
        }

        // Circle
        FreeMove(keyframe, tangentPosition, 0.015f, CustomHandles.CircleCap, applyFunction);

        // Selected
        if ((!invert && targetPoint == 1) || (invert && targetPoint == 2))
        {
            CustomHandles.DrawCircle(tangentPosition, 0.015f, Color.yellow);
            MoveHandle(keyframe, tangentPosition, 0.04f, 0.025f, applyFunction);
        }
    }
コード例 #9
0
ファイル: ULevel.cs プロジェクト: solarisstar/ME3Explorer
 public void LoadStaticMeshCollectionActors()
 {
     for (int i = 0; i < UStatColl.Count; i++)
     {
         for (int j = 0; j < UStatColl[i].Entries.Count; j++)
         {
             if (UStatColl[i].Entries[j] >= 0 && UStatColl[i].Entries[j] < pcc.Header.ExportCount)
             {
                 UStaticMeshComponent t = new UStaticMeshComponent(pcc.EntryToBuff(UStatColl[i].Entries[j]), pcc.names);
                 t.UPR = UPR;
                 t.Deserialize();
                 LevelProperties LP = UStatColl[i].LP;
                 GlobalTransform g  = new GlobalTransform();
                 g.m      = UStatColl[i].Matrices[j];
                 g.scl    = new Vector3(1, 1, 1);
                 g.scl2   = 1;
                 LP.GT    = g;
                 t.LP     = LP;
                 t.index  = UStatColl[i].Entries[j];
                 t.index2 = j;
                 t.index3 = i;
                 UStatComp.Add(t);
             }
         }
     }
 }
コード例 #10
0
    public static void DrawSelector(Waypoint keyframe, bool showTime = false)
    {
        Vector3 position   = GlobalTransform.Transfomed(keyframe.Position);
        float   size       = 0.025f;
        float   hitboxSize = 1.5f * size;

        // -- DOT -- //
        Handles.color = Color.white;
        Handles.SphereHandleCap(0, position, Quaternion.identity, size, EventType.Repaint);

        // -- SELECTION -- //
        if (CustomHandles.SelectableButton(position, hitboxSize, Color.white))
        {
            Selection.activeObject = keyframe;
            targetPoint            = 0;
        }

        // -- MOVEMENT -- //
        FreeMove(keyframe, position, hitboxSize, CustomHandles.NullCap, keyframe.SetPosition);

        // -- LABEL -- //
        if (showTime)
        {
            string timestamp = $"{keyframe.time.ToString("0.0")} s";
            Handles.Label(position + LabelOffset, timestamp, CustomGUI.LabelStyle);
        }
    }
コード例 #11
0
 private void AlignCarWithGround()
 {
     if (Down.IsColliding())
     {
         var n = Down.GetCollisionNormal().Normalized();
         GlobalTransform = GlobalTransform.InterpolateWith(GlobalTransform.LookingAtWithY(n), .1f);
     }
 }
コード例 #12
0
        public override void Render()
        {
            if (SkipRender)
            {
                return;
            }

            bool lightningEnabled = ProcessLightning && Viewport != null && Viewport.LightSource != null && Viewport.LightSource.Visible;
            bool shadowsEnabled   = lightningEnabled && Viewport.LightSource.ShadowMappingEnabled;

            Renderer.World    = GlobalTransform;
            Renderer.CullMode = CullMode;
            var invWorld = GlobalTransform.CalcInverted();

            foreach (var sm in Submeshes)
            {
                var skin = sm.Material as IMaterialSkin;
                if (skin != null && sm.Bones.Count > 0)
                {
                    skin.SkinEnabled = sm.Bones.Count > 0;
                    if (skin.SkinEnabled)
                    {
                        if (sharedBoneTransforms.Length < sm.Bones.Count)
                        {
                            sharedBoneTransforms = new Matrix44[sm.Bones.Count];
                        }
                        for (var i = 0; i < sm.Bones.Count; i++)
                        {
                            sharedBoneTransforms[i] = sm.BoneBindPoses[i] * sm.Bones[i].GlobalTransform * invWorld;
                        }
                        skin.SetBones(sharedBoneTransforms, sm.Bones.Count);
                    }
                }
                var lightningMaterial = sm.Material as IMaterialLightning;
                if (lightningMaterial != null)
                {
                    lightningMaterial.ProcessLightning = lightningEnabled;
                    if (lightningEnabled)
                    {
                        lightningMaterial.SetLightData(Viewport.LightSource);
                    }
                }

                var shadowMaterial = sm.Material as IMaterialShadowReciever;
                if (shadowMaterial != null)
                {
                    shadowMaterial.RecieveShadows = shadowsEnabled && RecieveShadow;
                }

                for (int i = 0; i < sm.Material.PassCount; i++)
                {
                    sm.Material.Apply(i);
                    PlatformRenderer.DrawTriangles(sm.Mesh, 0, sm.Mesh.IndexBuffer.Data.Length);
                }
                Renderer.PolyCount3d += sm.Mesh.IndexBuffer.Data.Length / 3;
            }
        }
コード例 #13
0
    public void OnTrajectoryUpdated(Vector3 translation, Vector3 velocity, Vector3 yaw, Vector3 pitch)
    {
        Translation = translation;
        Rotation    = yaw;
        var localVelocity = GlobalTransform.Inverse().basis.Xform(velocity);

        animTree.Set("parameters/locomotion/blend_position", new Vector2(localVelocity.x, localVelocity.z));

        //Pitch will be used when we have IK working with the model.
    }
コード例 #14
0
ファイル: WidgetAdapter3D.cs プロジェクト: klenin/Citrus
        public override float CalcDistanceToCamera(Camera3D camera)
        {
            if (Widget == null)
            {
                return(0f);
            }
            var p = GlobalTransform.TransformVector((Vector3)(Widget.Position * new Vector2(1, -1)));

            return(camera.View.TransformVector(p).Z);
        }
コード例 #15
0
 public override void _PhysicsProcess(float delta)
 {
     if (lerp_towards_target)
     {
         GlobalTransform = GlobalTransform.InterpolateWith(target, lerp_speed * delta);
     }
     else
     {
         GlobalTransform = GlobalTransform.InterpolateWith(initial_transform, lerp_speed * delta);
     }
 }
コード例 #16
0
        public float CalcLengthRough()
        {
            var length       = 0f;
            var segmentCount = GetSegmentCount();
            var scale        = GlobalTransform.GetScale(false);

            for (int i = 0; i < segmentCount; i++)
            {
                length += ((GetPoint(i + 1).Position - GetPoint(i).Position) * scale).Length;
            }
            return(length);
        }
コード例 #17
0
ファイル: Person.cs プロジェクト: CastleOfArgg/Blues
    public override void _PhysicsProcess(float delta)
    {
        if (AI == null)
        {
            return;
        }
        AI();

        //move
        if (WayPoint == null)
        {
            MoveCharacter(delta, new Vector3());
            return;
        }

        //rotate
        RotateObjectLocal(Vector3.Up, Mathf.Pi);
        var rot = GlobalTransform.LookingAt(EnemyBody.GlobalTransform.origin, new Vector3(0, 1, 0)).basis.GetEuler();

        if (Mathf.Abs(Transform.basis.GetEuler().y - rot.y) > Mathf.Pi)
        {
            if (rot.y < 0)
            {
                rot.y += 2 * Mathf.Pi;
            }
            else
            {
                rot.y -= 2 * Mathf.Pi;
            }
        }

        rot   = Rotation.LinearInterpolate(rot, delta * RotateSpeed) - Transform.basis.GetEuler();
        rot.y = Mathf.Clamp(rot.y, -1, 1);
        RotateObjectLocal(Vector3.Up, rot.y);
        RotateObjectLocal(Vector3.Up, Mathf.Pi);

        //movement
        var dist = WayPoint.GlobalTransform.origin - GlobalTransform.origin;

        if (Mathf.Sqrt(Mathf.Pow(dist.x, 2) + Mathf.Pow(dist.z, 2)) < Resources.WaypointDistance)
        {
            MoveCharacter(delta, new Vector3());
            return;
        }
        var movement = new Vector3(Mathf.Clamp(dist.x, -1, 1), 0, Mathf.Clamp(dist.z, -1, 1));

        MoveCharacter(delta, movement);

        //makes sure everything is unchanged
        Orthonormalize();

        AnimTree.Advance(delta);
    }
コード例 #18
0
 public override void _PhysicsProcess(float delta)
 {
     _translation = GlobalTransform.Translated(new Vector3(delta * DoorSpeed, 0, 0));
     if (_opening && _door.GlobalTransform.origin > _maxTotalTransform.origin)
     {
         _door.GlobalTransform = _door.GlobalTransform.Translated(new Vector3(delta * DoorSpeed, 0, 0));
     }
     else if (!_opening && _door.GlobalTransform.origin < _originalTransform.origin)
     {
         _door.GlobalTransform = _door.GlobalTransform.Translated(new Vector3(delta * -DoorSpeed, 0, 0));
     }
 }
コード例 #19
0
 private void configurePaths(IDictionary <DataComposition, VisibilityConfiguration> cards)
 {
     this.paths = new Dictionary <DataComposition, PathAnimator>();
     foreach (KeyValuePair <DataComposition, VisibilityConfiguration> keyValuePair in this.initialPositions)
     {
         DataComposition         key       = keyValuePair.Key;
         GlobalTransform         transform = keyValuePair.Value.Transform;
         VisibilityConfiguration visibilityConfiguration;
         if (cards.TryGetValue(key, out visibilityConfiguration) && CardPathsAnimation.shouldMove(visibilityConfiguration.Transform, transform))
         {
             bool            flag = false;
             EntityComponent entityComponent;
             if (key.TryGetOne <EntityComponent>(out entityComponent))
             {
                 flag = (entityComponent.get_Parent().IsCard() && !visibilityConfiguration.Show && !this.animatingCards.Contains(key));
             }
             if (!flag)
             {
                 int           num = this.animatingCards.IndexOf(key);
                 AnimationClip animationClip;
                 if (num >= 0 && num < this.curves.Length)
                 {
                     animationClip = this.curves[num];
                 }
                 else
                 {
                     F one = keyValuePair.Value.GetOne <F>();
                     animationClip = ((one == null) ? this.curves[this.curves.Length - 1] : one);
                 }
                 if (animationClip != null)
                 {
                     PathAnimator component = new GameObject(Constants.Fe(), new Type[]
                     {
                         typeof(Animation),
                         typeof(dwd.core.animation.paths.Path),
                         typeof(PathAnimator)
                     }).GetComponent <PathAnimator>();
                     component.ParentToAndZero(base.transform);
                     this.paths.Add(key, component);
                     Animation component2 = component.GetComponent <Animation>();
                     component2.AddClip(animationClip, animationClip.name);
                     component2.clip = animationClip;
                     float num2;
                     this.delays.TryGetValue(key, out num2);
                     this.duration            = Mathf.Max(this.duration, animationClip.length + num2);
                     component.StartTransform = transform;
                     component.EndTransform   = new GlobalTransform(component.transform);
                 }
             }
         }
     }
 }
コード例 #20
0
    private static void MoveHandle(Waypoint keyframe, Vector3 position, float size, float offset, Action <Vector3> applyFunction)
    {
        EditorGUI.BeginChangeCheck();
        Vector3 updatedPosition = CustomHandles.MoveHandle(position, offset, size);

        updatedPosition = GlobalTransform.InverseTransfomed(updatedPosition);
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(keyframe, "Change Waypoint");
            applyFunction.Invoke(updatedPosition);
            keyframe.Drone.UpdateView();
        }
    }
コード例 #21
0
    private static void FreeMove(Waypoint keyframe, Vector3 position, float size, Handles.CapFunction capFunction, Action <Vector3> applyFunction)
    {
        EditorGUI.BeginChangeCheck();
        Vector3 newPosition = Handles.FreeMoveHandle(position, Quaternion.identity, size, DefaultSnap, capFunction);

        newPosition = GlobalTransform.InverseTransfomed(newPosition);
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(keyframe, "Change Waypoint");
            applyFunction.Invoke(newPosition);
            keyframe.Drone.UpdateView();
        }
    }
コード例 #22
0
ファイル: ULevel.cs プロジェクト: solarisstar/ME3Explorer
 public void LoadStaticMeshActors()
 {
     for (int i = 0; i < UStatActors.Count; i++)
     {
         int entry = UPR.FindObjectProperty("StaticMeshComponent", UStatActors[i].props);
         if (entry >= 0 && entry < pcc.Header.ExportCount)
         {
             UStaticMeshComponent t = new UStaticMeshComponent(pcc.EntryToBuff(entry), pcc.names);
             t.UPR = UPR;
             t.Deserialize();
             LevelProperties LP = UStatActors[i].LP;
             GlobalTransform g  = new GlobalTransform();
             if (i == 21)
             {
             }
             entry = UPR.FindProperty("location", UStatActors[i].props);
             if (entry != -1)
             {
                 g.loc = PropToVector3(UStatActors[i].props[entry + 1].raw);
             }
             entry = UPR.FindProperty("Rotator", UStatActors[i].props);
             if (entry != -1)
             {
                 g.rot = PropToCYPRVector3(UStatActors[i].props[entry].raw);
             }
             entry = UPR.FindProperty("DrawScale3D", UStatActors[i].props);
             if (entry != -1)
             {
                 g.scl = PropToVector3(UStatActors[i].props[entry + 1].raw);
             }
             else
             {
                 g.scl = new Vector3(1, 1, 1);
             }
             entry = UPR.FindProperty("DrawScale", UStatActors[i].props);
             if (entry != -1)
             {
                 g.scl2 = BitConverter.ToSingle(UStatActors[i].props[entry + 1].raw, UStatActors[i].props[entry + 1].raw.Length - 4);
             }
             else
             {
                 g.scl2 = 1;
             }
             LP.GT   = g;
             t.LP    = LP;
             t.index = entry;
             UStatComp.Add(t);
         }
     }
 }
コード例 #23
0
        public void RenderDepthBuffer(IMaterial mat)
        {
            if (SkipRender)
            {
                return;
            }

            Renderer.World    = GlobalTransform;
            Renderer.CullMode = CullMode;

            var invWorld = GlobalTransform.CalcInverted();

            foreach (var sm in Submeshes)
            {
                var def = sm.Material;

                sm.Material = mat;

                var skin = sm.Material as IMaterialSkin;
                if (skin != null && sm.Bones.Count > 0)
                {
                    if (sharedBoneTransforms.Length < sm.Bones.Count)
                    {
                        sharedBoneTransforms = new Matrix44[sm.Bones.Count];
                    }
                    for (var i = 0; i < sm.Bones.Count; i++)
                    {
                        sharedBoneTransforms[i] = sm.BoneBindPoses[i] * sm.Bones[i].GlobalTransform * invWorld;
                    }

                    skin.SkinEnabled = true;
                    skin.SetBones(sharedBoneTransforms, sm.Bones.Count);
                }
                else
                {
                    skin.SkinEnabled = false;
                }

                for (int i = 0; i < sm.Material.PassCount; i++)
                {
                    sm.Material.Apply(i);
                    PlatformRenderer.DrawTriangles(sm.Mesh, 0, sm.Mesh.IndexBuffer.Data.Length);
                }
                Renderer.PolyCount3d += sm.Mesh.IndexBuffer.Data.Length / 3;

                sm.Material = def;
            }
        }
コード例 #24
0
 public void UpdateCards(IDictionary <DataComposition, VisibilityConfiguration> cards)
 {
     if (this.initialized)
     {
         if (float.IsNaN(this.startTime))
         {
             using (IEnumerator <KeyValuePair <DataComposition, VisibilityConfiguration> > enumerator = this.initialPositions.GetEnumerator())
             {
                 while (enumerator.MoveNext())
                 {
                     KeyValuePair <DataComposition, VisibilityConfiguration> keyValuePair = enumerator.Current;
                     cards[keyValuePair.Key] = keyValuePair.Value;
                 }
                 return;
             }
         }
         if (this.paths == null)
         {
             this.configurePaths(cards);
         }
         float num = Time.time - this.startTime;
         foreach (KeyValuePair <DataComposition, PathAnimator> keyValuePair2 in this.paths)
         {
             DataComposition         key   = keyValuePair2.Key;
             PathAnimator            value = keyValuePair2.Value;
             VisibilityConfiguration visibilityConfiguration = cards[key];
             GlobalTransform         transform = visibilityConfiguration.Transform;
             float num2;
             this.delays.TryGetValue(key, out num2);
             value.EndTransform = transform;
             visibilityConfiguration.Transform = value.GetTransformAtTime(Mathf.Max(0f, num - num2));
             visibilityConfiguration.Show      = this.DoShow;
             if (this.animatingCards.Contains(key))
             {
                 visibilityConfiguration.GetOne <j.V>().A = true;
                 f.E.DisplayMode display = this.initialPositions[key].GetOne <f.E>().display;
                 visibilityConfiguration.GetOne <f.E>().display = display;
                 visibilityConfiguration.GetOne <f.c>().A       = false;
             }
         }
         if (num >= this.duration)
         {
             this.set_Completed(true);
             this.initialized = false;
         }
     }
 }
コード例 #25
0
    public static void DrawWaypoints(List <Waypoint> waypoints)
    {
        foreach (Waypoint waypoint in waypoints)
        {
            WaypointEditor.DrawSelector(waypoint, showTimestamps);
        }


        if (showEndpoints)
        {
            Waypoint firstWaypoint = waypoints[0];
            Waypoint lastWaypoint  = waypoints[waypoints.Count - 1];
            Vector3  endOffset     = (waypoints.Count < 2) ? AlternateLabelOffset : LabelOffset;

            Handles.Label(GlobalTransform.Transfomed(firstWaypoint.Position) + LabelOffset, "START", CustomGUI.TitleStyle);
            Handles.Label(GlobalTransform.Transfomed(lastWaypoint.Position) + endOffset, "END", CustomGUI.TitleStyle);
        }
    }
コード例 #26
0
    public void ApplyGlobalTransform()
    {
        List <Waypoint> waypoints = this.Waypoints;

        if (waypoints == null)
        {
            return;
        }

        Undo.RecordObjects(waypoints.ToArray(), "Apply Global Transform");
        foreach (Waypoint waypoint in waypoints)
        {
            Vector3 newPosition = GlobalTransform.Transfomed(waypoint.Position);
            Vector3 newTangent  = GlobalTransform.Transfomed(waypoint.WorldTangent);
            waypoint.SetPosition(newPosition);
            waypoint.SetTangent(newTangent);
        }
    }
コード例 #27
0
ファイル: CustomHandles.cs プロジェクト: mikendu/DroneMayhem
    public static void DrawBezierPath(List <Waypoint> waypoints, Color pathColor, float thiccness = 3.0f)
    {
        int numKeyframes = waypoints.Count - 1;

        for (int i = 0; i < numKeyframes; i++)
        {
            Waypoint currentKeyframe = waypoints[i];
            Waypoint nextKeyframe    = waypoints[i + 1];
            bool     linearStart     = (currentKeyframe.JointType == JointType.Linear);
            bool     linearEnd       = (nextKeyframe.JointType == JointType.Linear);

            Vector3 startPos     = GlobalTransform.Transfomed(currentKeyframe.Position);
            Vector3 endPos       = GlobalTransform.Transfomed(nextKeyframe.Position);
            Vector3 startTangent = linearStart ? startPos : GlobalTransform.Transfomed(currentKeyframe.WorldTangent);
            Vector3 endTangent   = linearEnd ? endPos : GlobalTransform.Transfomed(nextKeyframe.InverseWorldTangent);

            Handles.DrawBezier(startPos, endPos, startTangent, endTangent, pathColor, null, thiccness);
        }
    }
コード例 #28
0
    // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _PhysicsProcess(float delta)
    {
        if (Target != null)
        {
            var targetPos = Target.GlobalTransform.Translated(Offset);
            GlobalTransform = GlobalTransform.InterpolateWith(targetPos, LerpSpeed * delta);
            LookAt(Target.GlobalTransform.origin, Vector3.Up);

            if (LockYPos)
            {
                this.SetGlobalOriginY(OriginalPos.y);
            }

            if (LockYRot)
            {
                this.SetGlobalBasisY(OriginalRot.y);
            }

            GlobalTransform = GlobalTransform.Orthonormalized();
        }
    }
コード例 #29
0
        private bool HitTestGeometry(Ray ray, out float distance)
        {
            var hit = false;

            distance = float.MaxValue;
            ray      = ray.Transform(GlobalTransform.CalcInverted());
            foreach (var submesh in Submeshes)
            {
                var vertices = ((IVertexBuffer <Vertex>)submesh.Mesh.VertexBuffers[0]).Data;
                for (int i = 0; i <= vertices.Length - 3; i += 3)
                {
                    var d = ray.IntersectsTriangle(vertices[i].Pos, vertices[i + 1].Pos, vertices[i + 2].Pos);
                    if (d != null && d.Value < distance)
                    {
                        distance = d.Value;
                        hit      = true;
                    }
                }
            }
            return(hit);
        }
コード例 #30
0
ファイル: Conveyor.cs プロジェクト: sodomon2/dwarfcorp
        override public void Update(DwarfTime Time, ChunkManager Chunks, Camera Camera)
        {
            base.Update(Time, Chunks, Camera);

            var        pushVector = Vector3.UnitZ;
            Quaternion rot;
            Vector3    scale;
            Vector3    trans;

            GlobalTransform.Decompose(out scale, out rot, out trans);

            pushVector  = Vector3.Transform(pushVector, rot * Quaternion.CreateFromAxisAngle(Vector3.UnitY, -(float)Math.PI / 2.0f));
            pushVector *= (float)Time.ElapsedGameTime.TotalSeconds * 4.0f;

            foreach (var body in Manager.World.EnumerateIntersectingObjects(GetBoundingBox(), CollisionType.Dynamic))
            {
                if (GetBoundingBox().Contains(body.LocalPosition) == ContainmentType.Contains)
                {
                    body.LocalPosition += pushVector;
                }
            }
        }
コード例 #31
0
ファイル: ULevel.cs プロジェクト: CreeperLava/ME3Explorer
 public void LoadInterpActors()
 {
     for (int i = 0; i < UIntAct.Count; i++)
     {
         int entry = UPR.FindObjectProperty("StaticMeshComponent", UIntAct[i].props);
         if (entry >= 0 && entry < pcc.Header.ExportCount)
         {
             UStaticMeshComponent t = new UStaticMeshComponent(pcc.EntryToBuff(entry), pcc.names);
             t.UPR = UPR;
             t.Deserialize();
             t.index = entry;
             LevelProperties LP = UIntAct[i].LP;
             GlobalTransform g = new GlobalTransform();
             entry = UPR.FindProperty("location", UIntAct[i].props);
             if (entry != -1) g.loc = PropToVector3(UIntAct[i].props[entry + 1].raw);
             entry = UPR.FindProperty("Rotator", UIntAct[i].props);
             if (entry != -1) g.rot = PropToCYPRVector3(UIntAct[i].props[entry].raw);
             entry = UPR.FindProperty("DrawScale3D", UIntAct[i].props);
             if (entry != -1) g.scl = PropToVector3(UIntAct[i].props[entry + 1].raw);
             else g.scl = new Vector3(1, 1, 1);
             entry = UPR.FindProperty("DrawScale", UIntAct[i].props);
             if (entry != -1) g.scl2 = BitConverter.ToSingle(UIntAct[i].props[entry + 1].raw, UIntAct[i].props[entry + 1].raw.Length - 4);
             else g.scl2 = 1;
             LP.GT = g;
             t.LP = LP;
             
             UStatComp.Add(t);
         }
     }
 }
コード例 #32
0
ファイル: ULevel.cs プロジェクト: CreeperLava/ME3Explorer
 public void LoadStaticMeshCollectionActors()
 {
     for (int i = 0; i < UStatColl.Count; i++)
         for (int j = 0; j < UStatColl[i].Entries.Count; j++)
             if (UStatColl[i].Entries[j] >= 0 && UStatColl[i].Entries[j] < pcc.Header.ExportCount)
             {
                 UStaticMeshComponent t = new UStaticMeshComponent(pcc.EntryToBuff(UStatColl[i].Entries[j]), pcc.names);
                 t.UPR = UPR;
                 t.Deserialize();
                 LevelProperties LP = UStatColl[i].LP;
                 GlobalTransform g = new GlobalTransform();
                 g.m = UStatColl[i].Matrices[j];
                 g.scl = new Vector3(1, 1, 1);
                 g.scl2 = 1;
                 LP.GT = g;
                 t.LP = LP;
                 t.index = UStatColl[i].Entries[j];
                 t.index2 = j;
                 t.index3 = i;
                 UStatComp.Add(t);
             }
 }