Ejemplo n.º 1
0
        public void Render(Transform tx, bool awake, Render render)
        {
            Transform world = Transform.Mul(tx, local);

            Vec3[] vertices = new Vec3[8] {
                new Vec3(-e.x, -e.y, -e.z),
                new  Vec3(-e.x, -e.y, e.z),
                new  Vec3(-e.x, e.y, -e.z),
                new   Vec3(-e.x, e.y, e.z),
                new   Vec3(e.x, -e.y, -e.z),
                new         Vec3(e.x, -e.y, e.z),
                new     Vec3(e.x, e.y, -e.z),
                new Vec3(e.x, e.y, e.z)
            };

            for (int i = 0; i < 36; i += 3)
            {
                Vec3 a = Transform.Mul(world, vertices[kBoxIndices[i]]);
                Vec3 b = Transform.Mul(world, vertices[kBoxIndices[i + 1]]);
                Vec3 c = Transform.Mul(world, vertices[kBoxIndices[i + 2]]);

                Vec3 n = Vec3.Normalize(Vec3.Cross(b - a, c - a));

                //render->SetPenColor( 0.2f, 0.4f, 0.7f, 0.5f );
                //render->SetPenPosition( a.x, a.y, a.z );
                //render->Line( b.x, b.y, b.z );
                //render->Line( c.x, c.y, c.z );
                //render->Line( a.x, a.y, a.z );

                render.SetTriNormal(n.x, n.y, n.z);
                render.Triangle(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z);
            }
        }
Ejemplo n.º 2
0
        // http://box2d.org/2014/02/computing-a-basis/
        public static void ComputeBasis(Vec3 a, ref Vec3 b, ref Vec3 c)
        {
            // Suppose vector a has all equal components and is a unit vector: a = (s, s, s)
            // Then 3*s*s = 1, s = sqrt(1/3) = 0.57735027. This means that at least one component of a
            // unit vector must be greater or equal to 0.57735027. Can use SIMD select operation.

            if (Math.Abs(a.x) >= (0.57735027))
            {
                b.Set(a.y, -a.x, 0);
            }
            else
            {
                b.Set(0, a.z, -a.y);
            }

            b = Vec3.Normalize(b);
            c = Vec3.Cross(a, b);
        }
Ejemplo n.º 3
0
        public Body(BodyDef def, Scene scene)
        {
            LinearVelocity  = def.linearVelocity;
            AngularVelocity = def.angularVelocity;
            Vec3.Identity(ref Force);
            Vec3.Identity(ref Torque);
            Q.Set(Vec3.Normalize(def.axis), def.angle);
            Tx.rotation    = Q.ToMat3();
            Tx.position    = def.position;
            SleepTime      = 0;
            GravityScale   = def.gravityScale;
            Layers         = def.layers;
            UserData       = def.userData;
            Scene          = scene;
            Flags          = 0;
            LinearDamping  = def.linearDamping;
            AngularDamping = def.angularDamping;

            if (def.bodyType == eDynamicBody)
            {
                Flags |= eDynamic;
            }

            else
            {
                if (def.bodyType == eStaticBody)
                {
                    Flags |= eStatic;
                    Vec3.Identity(ref LinearVelocity);
                    Vec3.Identity(ref AngularVelocity);
                    Vec3.Identity(ref Force);
                    Vec3.Identity(ref Torque);
                }

                else if (def.bodyType == eKinematicBody)
                {
                    Flags |= eKinematic;
                }
            }

            if (def.allowSleep)
            {
                Flags |= eAllowSleep;
            }

            if (def.awake)
            {
                Flags |= eAwake;
            }

            if (def.active)
            {
                Flags |= eActive;
            }

            if (def.lockAxisX)
            {
                Flags |= eLockAxisX;
            }

            if (def.lockAxisY)
            {
                Flags |= eLockAxisY;
            }

            if (def.lockAxisZ)
            {
                Flags |= eLockAxisZ;
            }

            Boxes       = new List <Box>();
            ContactList = new List <ContactEdge>();
        }
Ejemplo n.º 4
0
 public void Set(Vec3 n, Vec3 p)
 {
     normal   = Vec3.Normalize(n);
     distance = Vec3.Dot(normal, p);
 }
Ejemplo n.º 5
0
 public void Set(Vec3 a, Vec3 b, Vec3 c)
 {
     normal   = Vec3.Normalize(Vec3.Cross(b - a, c - a));
     distance = Vec3.Dot(normal, a);
 }