예제 #1
0
        public override void AffectOther(Node other) // called when used as a link
        {
            if (!active || !activated)
            {
                return;
            }
            Vector2R diff = other.body.pos - parent.body.pos;
            float    len;

            if (lockedDistance)
            {
                len = lockedVals[other];
            }
            else
            {
                len = diff.Length();
            }

            if (len > maxdist)
            {
                if (lockedAngle)
                {
                    other.body.pos = parent.body.pos + confiningVects[other] * maxdist;
                }
                else
                {
                    float percent = maxdist / len;
                    diff          *= percent;
                    other.body.pos = parent.body.pos + diff;
                }
            }
            else if (len < mindist)
            {
                if (lockedAngle)
                {
                    other.body.pos = parent.body.pos + confiningVects[other] * mindist;
                }
                else
                {
                    float percent = mindist / len;
                    diff          *= percent;
                    other.body.pos = parent.body.pos + diff;
                }
            }
            else
            {
                if (lockedAngle)
                {
                    other.body.pos = parent.body.pos + confiningVects[other] * len;
                    //Console.WriteLine("{0}, {1}, {2}", confiningVects[other], other.transform.position, len);
                }
            }
            //diff = other.transform.position - parent.transform.position;
            //Console.WriteLine(diff.Length());
        }
예제 #2
0
        public static void VelocityToOutput(Dictionary <string, dynamic> args, ModifierInfo mi)
        {
            Vector2R velocity = ((Node)mi.fpInfos["v1"].ob).body.velocity;
            float    max      = (Defaultered("max", args, 2f));
            float    min      = (Defaultered("min", args, 0.1f));
            float    highest  = (Defaultered("highest", args, 20f));
            float    o1       = velocity.Length() / highest;

            o1 = o1 * (max - min) + min;
            mi.fpInfos["v1"].SetValue(o1);
        }
예제 #3
0
 public void Lock()
 {
     if (parent == null)
     {
         return;
     }
     lockedVals = new Dictionary <Node, int>();
     foreach (Node other in outgoing.ToList())
     {
         Vector2R len = other.body.pos - parent.body.pos;
         lockedVals[other] = (int)len.Length();
     }
 }
예제 #4
0
파일: VMath.cs 프로젝트: MHDante/OrbitVR
 public static void NormalizeSafe(ref Vector2R v)
 {
     if (v.X != 0 || v.Y != 0)
     {
         float len = v.Length();
         if (len == 0)
         {
             return;
         }
         float invLen = 1.0f / len;
         v.X *= invLen;
         v.Y *= invLen;
     }
 }
예제 #5
0
        public override void DrawLine(Vector2R start, Vector2R end, float thickness, Color color, float depth)
        {
            if (thickness * zoom < 1)
            {
                thickness = 1 / zoom;
            }
            Vector2R diff        = (end - start); // *mapzoom;
            Vector2R centerpoint = (end + start) / 2;
            //centerpoint *= mapzoom;
            float len = diff.Length();
            //thickness *= 2f * mapzoom;
            Vector2 scalevect = new Vector2(len, thickness) / 128;
            float   angle     = (float)(Math.Atan2(diff.Y, diff.X));

            Draw(Textures.Whitecircle, centerpoint, color, scalevect, angle, depth);
        }
예제 #6
0
        public override void DrawLinePermanent(Vector2R start, Vector2R end, float thickness, Color color, int life)
        {
            if (thickness * zoom < 1)
            {
                thickness = 1 / zoom;
            }
            Vector2R diff        = (end - start); // *mapzoom;
            Vector2R centerpoint = (end + start) / 2;
            //centerpoint *= mapzoom;
            float len = diff.Length();
            //thickness *= 2f * mapzoom;
            Vector2 scalevect = new Vector2(len, thickness);
            float   angle     = (float)(Math.Atan2(diff.Y, diff.X));

            //Draw(textures.whitepixel, centerpoint, null, color, angle, Assets.textureCenters[textures.whitepixel], scalevect, Layer);
            AddPermanentDraw(Textures.Whitecircle, centerpoint, color, scalevect, angle, life);
        }
예제 #7
0
파일: VMath.cs 프로젝트: MHDante/OrbitVR
        public static Vector2R NormalizeSafe(this Vector2R v)
        {
            if (v.X == 0 && v.Y == 0)
            {
                return(v);
            }
            float len = v.Length();

            if (len == 0)
            {
                return(v);
            }
            float invLen = 1.0f / len;

            v.X *= invLen;
            v.Y *= invLen;
            return(v);
        }
예제 #8
0
파일: VMath.cs 프로젝트: MHDante/OrbitVR
 public static Vector2R Redirect(Vector2R source, Vector2R direction)
 {
     return(direction *= source.Length() / direction.Length());
     //return Resize(direction, source.Length());
 }
예제 #9
0
        public override void Draw()
        {
            if (++counter % onceEveryAmount != 0)
            {
                return;
            }
            Vector2R start = parent.body.pos;

            if (prevPos == Vector2R.Zero)
            {
                prevPos = start;
                return;
            }
            //don't draw lines from screen edge to edge if screenwrapping
            if (parent.movement.mode == movemode.screenwrap)
            {
                float diffx = prevPos.X - start.X;
                if (diffx > room.WorldWidth / 2)
                {
                    start.X += room.WorldWidth;
                }
                else if (diffx < -room.WorldWidth / 2)
                {
                    start.X -= room.WorldWidth;
                }
                float diffy = prevPos.Y - start.Y;
                if (diffy > room.WorldHeight / 2)
                {
                    start.Y += room.WorldHeight;
                }
                else if (diffy < -room.WorldHeight / 2)
                {
                    start.Y -= room.WorldHeight;
                }
            }

            Vector2R diff        = (prevPos - start);
            Vector2R centerpoint = (prevPos + start) / 2;
            float    len         = diff.Length();
            Vector2R scalevect;
            float    xscale = len;
            float    yscale = thickness;

            //float outerscale = yscale;
            //float beamdist = 1f;
            if (brightness)
            {
                xscale = brightness;
            }
            //if (thickness)
            //{
            //    yscale = thickness;
            //    outerscale = yscale * beamRatio;
            //}

            scalevect = new Vector2R(xscale, yscale);

            float testangle = (float)(Math.Atan2(diff.Y, diff.X));

            VMath.NormalizeSafe(ref diff);
            diff = new Vector2R(-diff.Y, diff.X);

            //uncommet later when not using direction based color shit
            Color coll;
            int   alpha = 255; //i * (255 / min);

            //Console.WriteLine(alpha);
            if (IsColorByAngle)
            {
                coll = ColorChanger.getColorFromHSV((testangle + (float)Math.PI) * (float)(180 / Math.PI));
            }
            else
            {
                coll = new Color(parent.body.color.R, parent.body.color.G, parent.body.color.B, alpha);
            }
            //room.Camera.AddPermanentDraw(Textures.Whitepixel, centerpoint, parent.body.color, scalevect, testangle,
            //                             laserLength);
            //Todo:drawlines
            prevPos = start;
        }
예제 #10
0
파일: Fist.cs 프로젝트: MHDante/OrbitVR
        public override void PlayerControl(Input input)
        {
            //fistNode.movement.active = false;
            //fistNode.body.velocity = fistNode.body.effvelocity * nodeKnockback;
            Vector2R newstickpos = input.GetRightStick().toV2R();
            Vector2R relVel      = newstickpos - oldstickpos;

            if (state == fistmode.ready)
            {
                fistNode.body.pos    = parent.body.pos;
                fistNode.body.orient = parent.body.orient;
                //if stick is moving away from center of stick
                if (newstickpos.LengthSquared() > oldstickpos.LengthSquared())
                {
                    //if stick is moving fast enough
                    float len = relVel.Length();
                    if (relVel.Length() > 0.2f) //deadzone
                    {
                        state = fistmode.punching;
                        float power = (float)Math.Log((double)len + 2.0, 2.0) / 2f;
                        //Console.WriteLine(power);
                        VMath.NormalizeSafe(ref relVel);
                        relVel *= power;
                        //Console.WriteLine(relVel.X + " : " + relVel.Y);
                        //fistNode.body.ApplyForce(relVel);
                        fistNode.body.velocity = relVel * 10f;
                        fistNode.body.orient   = VMath.VectorToAngle(relVel);
                    }
                }
            }
            else if (state == fistmode.punching)
            {
                //check if fully punched.
                if (Vector2R.Distance(fistNode.body.pos, parent.body.pos) > fistReach)
                {
                    state = fistmode.retracting;
                }
            }
            else if (state == fistmode.retracting)
            {
                //fistNode.body.pos = Vector2.Lerp(fistNode.body.pos, parent.body.pos, 0.1f);

                //Vector2 vel = (parent.body.pos - fistNode.body.pos);
                //VMath.NormalizeSafe(ref vel);
                //vel *= 1;
                //fistNode.body.velocity = vel;

                Vector2R vel = (parent.body.pos - fistNode.body.pos);
                //if (vel.Length() < 5)
                //{
                VMath.NormalizeSafe(ref vel);
                vel *= 20;
                //}
                fistNode.body.velocity = vel;
                if (Vector2R.DistanceSquared(fistNode.body.pos, parent.body.pos) < 50 * 50)
                {
                    state = fistmode.ready;
                }
            }
            //if (state != fistmode.ready)
            //    Console.WriteLine(state);
            oldstickpos = newstickpos;
        }
예제 #11
0
        public override void AffectSelf()
        {
            if (active && activated)
            {
                foreach (Node other in outgoing)
                {
                    Vector2R diff = other.body.pos - parent.body.pos;
                    float    len;
                    if (lockedDistance)
                    {
                        len = lockedVals[other];
                    }
                    else
                    {
                        len = diff.Length();
                    }

                    if (len > maxdist)
                    {
                        if (lockedAngle)
                        {
                            other.body.pos = parent.body.pos + confiningVects[other] * maxdist;
                        }
                        else
                        {
                            float percent;
                            if (lockedDistance)
                            {
                                percent = len / diff.Length();
                            }
                            else
                            {
                                percent = maxdist / len;
                            }
                            diff          *= percent;
                            other.body.pos = parent.body.pos + diff;
                        }
                    }
                    else if (len < mindist)
                    {
                        if (lockedAngle)
                        {
                            other.body.pos = parent.body.pos + confiningVects[other] * mindist;
                        }
                        else
                        {
                            float percent;
                            if (lockedDistance)
                            {
                                percent = len / diff.Length();
                            }
                            else
                            {
                                percent = mindist / len;
                            }
                            diff          *= percent;
                            other.body.pos = parent.body.pos + diff;
                        }
                    }
                    else
                    {
                        if (lockedAngle)
                        {
                            other.body.pos = parent.body.pos + confiningVects[other] * len;
                            //Console.WriteLine("{0}, {1}, {2}", confiningVects[other], other.transform.position, len);
                        }
                        if (lockedDistance)
                        {
                            float percent = len / diff.Length();
                            //else percent = mindist / len;
                            diff          *= percent;
                            other.body.pos = parent.body.pos + diff;
                        }
                    }


                    //diff = other.transform.position - parent.transform.position;
                    //Console.WriteLine(diff.Length());
                }
            }
        }
예제 #12
0
파일: Shovel.cs 프로젝트: MHDante/OrbitVR
        public override void PlayerControl(Input input)
        {
            Vector2R newstickpos   = input.GetRightStick(shovelReach, true).toV2R(); //input.GetRightStick();
            Vector2R pos           = newstickpos * shovelReach;
            Vector2R worldStickPos = parent.body.pos + pos;
            Vector2R diff          = worldStickPos - shovelNode.body.pos;
            //float angle = Utils.VectorToAngle(shovelNode.body.pos - parent.body.pos) + VMath.PIbyTwo % VMath.twoPI;
            Vector2R shovelDir = shovelNode.body.pos - parent.body.pos;

            shovelDir = new Vector2R(shovelDir.Y, -shovelDir.X);
            shovelNode.body.SetOrientV2(shovelDir);

            if (modeShovelPosition == ModeShovelPosition.AbsoluteStickPos)
            {
                shovelNode.body.pos = worldStickPos;
            }
            else if (modeShovelPosition == ModeShovelPosition.PhysicsBased)
            {
                float len = diff.Length();
                if (len < 1)
                {
                    shovelNode.body.velocity = Vector2R.Zero;
                }
                else
                {
                    float velLen = shovelNode.body.velocity.Length();

                    Vector2R diffcopy = diff;
                    VMath.NormalizeSafe(ref diffcopy);

                    Vector2R normalizedVel = shovelNode.body.velocity;
                    VMath.NormalizeSafe(ref normalizedVel);

                    float result = 0;
                    Vector2R.Dot(ref diffcopy, ref normalizedVel, out result);

                    diffcopy *= result;
                    Vector2R force = (diff / physicsDivisor);
                    if (shovelling && compoundedMass >= 1)
                    {
                        force /= compoundedMass * 1;
                    }
                    shovelNode.body.velocity = diffcopy + force;
                    //shovelNode.body.ApplyForce(force);
                }
            }

            if (shovelling)
            {
                //if (fc.newGamePadState.Triggers.Right < deadzone && fc.oldGamePadState.Triggers.Right > deadzone)
                if (input.BtnReleased(InputButtons.RightTrigger_Mouse1))
                {
                    shovelling = false;
                    foreach (Node n in shovelLink.targets.ToList())
                    {
                        if (physicsThrow)
                        {
                            n.body.velocity = n.body.effvelocity;
                        }
                        else
                        {
                            Vector2R stickdirection = newstickpos;
                            VMath.NormalizeSafe(ref stickdirection);

                            n.body.velocity = stickdirection * throwSpeed;
                        }
                        n.collision.active = true;
                        shovelLink.targets.Remove(n);
                        n.body.ClearExclusionChecks();
                        n.body.color = n.body.permaColor;
                    }
                    shovelLink.formation.UpdateFormation();
                    shovelLink.active = false;
                    shovelNode.room.AllActiveLinks.Remove(shovelLink);
                    compoundedMass = 0f;
                }
            }
            else
            {
                if (input.BtnClicked(InputButtons.RightTrigger_Mouse1))
                {
                    shovelling = true;
                    ObservableHashSet <Node> capturedNodes = new ObservableHashSet <Node>();
                    int count = 0;
                    Action <Collider, Collider> del = delegate(Collider c1, Collider c2) {
                        if (count >= maxShovelCapacity)
                        {
                            return;
                        }
                        if (c2.parent.dataStore.ContainsKey("shovelnodeparent"))
                        {
                            return;
                        }
                        if (c2.parent.HasComp <Diode>())
                        {
                            return;
                        }
                        if (modePlayers != ModePlayers.GrabBoth && c2.parent.IsPlayer)
                        {
                            if (modePlayers == ModePlayers.GrabNone)
                            {
                                return;
                            }
                            if (modePlayers == ModePlayers.GrabSelf && c2.parent != parent)
                            {
                                return;
                            }
                            if (modePlayers == ModePlayers.GrabOtherPlayers && c2.parent == parent)
                            {
                                return;
                            }
                        }
                        float dist = Vector2R.Distance(c1.pos, c2.pos);
                        if (dist <= scoopReach)
                        {
                            count++;
                            capturedNodes.Add(c2.parent);
                            c2.parent.body.color = parent.body.color;
                        }
                    };
                    shovelNode.room.GridsystemAffect.retrieveOffsetArraysAffect(shovelNode.body, del, scoopReach * 2);
                    shovelLink.targets = capturedNodes;
                    shovelLink.formation.UpdateFormation();
                    shovelLink.active = true;
                    shovelNode.room.AllActiveLinks.Add(shovelLink);
                    compoundedMass = 0f;
                    foreach (Node n in capturedNodes)
                    {
                        n.collision.active = false;
                        compoundedMass    += n.body.mass;
                    }
                }
            }
        }