コード例 #1
0
 public TransformExt()
 {
     position    = new Vector3(0, 0, 0);
     rotation    = Quaternion.identity;
     scale       = new Vector3(1, 1, 1);
     posLHS      = position;
     worldMatrix = Matrix4x4.identity;
 }
コード例 #2
0
 public TransformExt(Spatial spatial)
 {
     position = Vector3.FromV3(spatial.GetTranslation());
     rotation = Quaternion.FromEulerRHS(Vector3.FromV3((spatial.GetRotationDegrees())));
     scale    = Vector3.FromV3(spatial.GetScale());
     posLHS   = new Vector3(position.x, position.y, -position.z);
     updateTransformMatrix();
 }
コード例 #3
0
            public void RotateAround(Vector3 point, Vector3 axis, float angle)
            {
                float      distance  = (position - point).magnitude;
                Vector3    direction = (position - point).normalized;
                Quaternion rotate    = Quaternion.AngleAxis(angle, axis);

                direction = rotate * direction;
                position  = point + direction * distance;
            }
コード例 #4
0
            public static TransformExt FromTransform(Transform transform, Vector3 rotation)
            {
                TransformExt transformExt = new TransformExt();

                transformExt.worldMatrix = Matrix4x4.TransformToMatrix4x4(transform);
                transformExt.position    = Vector3.FromV3(transform.origin);
                transformExt.rotation    = Quaternion.FromEuler(rotation);
                transformExt.scale       = new Vector3(1, 1, 1);
                return(transformExt);
            }
コード例 #5
0
ファイル: Rocket.cs プロジェクト: dunyakilavuz/GA-Rockets
 public void Revive()
 {
     transform.position = startPos;
     transform.rotation = Quaternion.identity;
     velocity           = Vector3.zero;
     acceleration       = Vector3.zero;
     dead    = false;
     time    = 0;
     index   = 0;
     fitness = 0;
 }
コード例 #6
0
ファイル: Manager.cs プロジェクト: dunyakilavuz/GA-Rockets
    private void HandleCollisions()
    {
        for (int i = 0; i < rockets.Length; i++)
        {
            Vector3 rocketPos = rockets[i].transform.position;
            bool    kill      = false;

            for (int j = 0; j < obstacles.Length; j++)
            {
                Vector3 obstaclePos  = obstacles[j].transform.position;
                float   obstacleSize = obstacles[j].transform.scale.x;

                if ((rocketPos - obstaclePos).magnitude < obstacleSize && rockets[i].isDead() == false)
                {
                    rockets[i].SetToPunish(timeThisGeneration);
                    kill = true;
                }
            }

            Vector3 targetPos  = target.transform.position;
            float   targetSize = target.transform.scale.x;

            if ((rocketPos - targetPos).magnitude < targetSize && rockets[i].isDead() == false)
            {
                rockets[i].SetToReward(timeThisGeneration);
                kill = true;
                targetHits++;
            }

            if ((rocketPos.y > References.northWall || rocketPos.y < References.southWall ||
                 rocketPos.x > References.eastWall || rocketPos.x < References.westWall) &&
                rockets[i].isDead() == false)
            {
                rockets[i].SetToPunish(timeThisGeneration);
                kill = true;
            }

            if (kill == true)
            {
                rockets[i].Kill();
            }
        }
    }
コード例 #7
0
ファイル: Rocket.cs プロジェクト: dunyakilavuz/GA-Rockets
    public override void _Ready()
    {
        transform          = new TransformExt();
        startPos           = new Vector3(0, References.rocketStartHeight, 0);
        transform.position = startPos;
        transform.rotation = Quaternion.identity;
        transform.scale    = Vector3.one * References.rocketScale;
        exhaust            = (Particles)GetChild(1);
        velocity           = Vector3.zero;
        currentThrust      = 0;
        thrustPercentage   = 0;
        maxExhaustSpeed    = 20;
        maxExhaustTTL      = 1f;

        instructions = new Instruction[References.instructionSize];

        for (int i = 0; i < References.instructionSize; i++)
        {
            instructions[i] = new Instruction();
        }
    }
コード例 #8
0
 void updateTransformMatrix(Vector3 LHS)
 {
     worldMatrix = Matrix4x4.translationMatrix(LHS) * Matrix4x4.scaleMatrix(scale) * Matrix4x4.rotationMatrix(rotation);
 }
コード例 #9
0
ファイル: Rocket.cs プロジェクト: dunyakilavuz/GA-Rockets
 private void AddForce(Vector3 force)
 {
     acceleration = force / References.rocketMass;
     velocity    += acceleration;
     acceleration = Vector3.zero;
 }
コード例 #10
0
ファイル: Rocket.cs プロジェクト: dunyakilavuz/GA-Rockets
 public void Kill()
 {
     velocity = Vector3.zero;
     dead     = true;
 }