Exemplo n.º 1
0
    void Init()
    {
        camera = playerDummy.Camera;

        objectDummy = new ObjectDummy();

        rigid = new BodyRigid();
        rigid.MaxAngularVelocity = 0.0f;
        rigid.Freezable          = true;

        shape             = new ShapeCapsule(radius, height);
        shape.Restitution = 0.0f;
        shape.Continuous  = false;

        rigid.Enabled    = true;
        objectDummy.Body = rigid;
        shape.Body       = rigid;

        position  = vec3.ZERO;
        direction = new vec3(1.0f, 0.0f, 0.0f);
        phiAngle  = 90.0f;

        for (int i = 0; i < (int)State.NumStates; i++)
        {
            states[i] = 0;
            times[i]  = 0.0f;
        }

        UpdateTransform();

        PhysicalMask            = physicalMask;
        PhysicsIntersectionMask = intersectionMask;
        CollisionMask           = collisionMask;
        PhysicalMass            = physicalMass;
        SetCollisionRadius(radius);
        SetCollisionHeight(height);
        MinFriction  = minFriction;
        MaxFriction  = maxFriction;
        MinVelocity  = minVelocity;
        MaxVelocity  = maxVelocity;
        Acceleration = acceleration;
        Damping      = damping;
        Jumping      = jumping;

        Ground  = 0;
        Ceiling = 0;

        Game.Player = playerDummy;
    }
Exemplo n.º 2
0
    override public bool HitTest(ShapeCapsule other)
    {
        var mat = Matrix4x4.Rotate(other.transform.rotation);
        var h   = mat.MultiplyVector(new Vector3(other.length * 0.5f, 0, 0));
        // 2点の座標
        Vector3 p1 = other.transform.position - h;
        Vector3 p2 = other.transform.position + h;


        var ab = p2 - p1;
        var ac = new Vector3(transform.position.x, transform.position.y) - p1;

        var     t = Vector2.Dot(ab, ac);
        Vector2 c;

        if (t <= 0)
        {
            c = p1;
        }
        else
        {
            float denom = Vector2.Dot(ab, ab);
            if (t >= denom)
            {
                c = p2;
            }
            else
            {
                t /= denom;
                c  = p1 + ab * t;
            }
        }
        var tmp = c - new Vector2(transform.position.x, transform.position.y);

        return(Mathf.Sqrt(Vector2.Dot(tmp, tmp)) <= radius + other.radius);
    }
Exemplo n.º 3
0
 abstract public bool HitTest(ShapeCapsule other);
Exemplo n.º 4
0
 override public bool HitTest(ShapeCapsule other)
 {
     return(false);
 }
Exemplo n.º 5
0
    private void Init()
    {
        if (showAdvancedSettings)
        {
            showAdvancedSettings = false;
        }

        if (useExternalBody)
        {
            useExternalBody = false;
        }

        PlayerDummy player = node as PlayerDummy;

        if (!player)
        {
            return;
        }

        // decompose transformation
        position  = node.WorldPosition;
        direction = MathLib.Normalize(new vec3(-node.WorldTransform.AxisZ));

        camera = player.Camera;

        if (playerBody)
        {
            dummy = playerBody.Body as BodyDummy;
            if (dummy)
            {
                for (int i = 0; i < dummy.NumShapes; i++)
                {
                    if (!shape)
                    {
                        shape = dummy.GetShape(i) as ShapeCapsule;
                    }
                }

                if (shape)
                {
                    shape.Restitution = 0.0f;
                    shape.Continuous  = false;

                    PhysicalIntersectionMask = shape.PhysicsIntersectionMask;
                    CollisionMask            = shape.CollisionMask;
                    Mass            = shape.Mass;
                    CollisionRadius = shape.Radius;
                    CollisionHeight = shape.Height;
                }
            }
        }

        if (!dummy || !shape)
        {
            if (playerBody)
            {
                playerBody.Enabled = false;
            }

            playerBody = new ObjectDummy();
            dummy      = new BodyDummy();

            shape             = new ShapeCapsule(1.0f, 1.0f);
            shape.Restitution = 0.0f;
            shape.Continuous  = false;

            dummy.Enabled   = true;
            playerBody.Body = dummy;
            shape.Body      = dummy;

            PhysicalIntersectionMask = physicalIntersectionMask;
            CollisionMask            = collisionMask;
            Mass            = mass;
            CollisionRadius = collisionRadius;
            CollisionHeight = collisionHeight;
        }

        contacts = new List <ShapeContact>();

        UpdateTransform();

        maxSlopeAngle   = MathLib.Max(maxSlopeAngle, maxStaticSlopeAngle);
        maxSlidingSpeed = MathLib.Max(maxSlidingSpeed, minSlidingSpeed);

        if (showDebug)
        {
            Visualizer.Enabled   = true;
            Render.ShowTriangles = 1;
        }

        isInitialized = true;
    }