Exemple #1
0
        public Transform PlaceShip(ShipConstruct ship, ExBuildControl.Box vessel_bounds)
        {
            if (site == null)
            {
                return(part.transform);
            }
            Transform xform;

            xform = part.FindModelTransform("EL launch pos");

            var        points    = new Points(site);
            GameObject launchPos = new GameObject("EL launch pos");

            launchPos.transform.position = points.center;
            launchPos.transform.rotation = points.GetOrientation();
            xform = launchPos.transform;
            Debug.LogFormat("[EL SurveyStation] launchPos {0} {1}", xform.position, xform.rotation);

            float   angle;
            Vector3 axis;

            xform.rotation.ToAngleAxis(out angle, out axis);

            Part    rootPart = ship.parts[0].localRoot;
            Vector3 pos      = rootPart.transform.position;
            Vector3 shift    = points.ShiftBounds(xform, pos, vessel_bounds);

            shift += xform.position;
            rootPart.transform.Translate(shift, Space.World);
            rootPart.transform.RotateAround(xform.position,
                                            axis, angle);
            return(xform);
        }
Exemple #2
0
        public Transform PlaceShip(ShipConstruct ship, ExBuildControl.Box vessel_bounds)
        {
            if (SpawnTransform != "")
            {
                launchTransform = part.FindModelTransform(SpawnTransform);
                //Debug.Log (String.Format ("[EL] launchTransform:{0}:{1}",
                //						  launchTransform, SpawnTransform));
            }
            if (launchTransform == null)
            {
                launchTransform = part.FindModelTransform("EL launch pos");
            }
            if (launchTransform == null)
            {
                Vector3    offset    = Vector3.up * (SpawnHeightOffset + spawnOffset);
                Transform  t         = part.transform;
                GameObject launchPos = new GameObject("EL launch pos");
                launchPos.transform.parent    = t;
                launchPos.transform.position  = t.position;
                launchPos.transform.rotation  = t.rotation;
                launchPos.transform.position += t.TransformDirection(offset);
                launchTransform = launchPos.transform;
                //Debug.Log (String.Format ("[EL] launchPos {0}",
                //						  launchTransform));
            }

            float   angle;
            Vector3 axis;

            launchTransform.rotation.ToAngleAxis(out angle, out axis);

            Part    rootPart = ship.parts[0].localRoot;
            Vector3 pos      = rootPart.transform.position;
            Vector3 shift    = new Vector3(-pos.x, -vessel_bounds.min.y, -pos.z);

            //Debug.Log (String.Format ("[EL] pos: {0} shift: {1}", pos, shift));
            shift += launchTransform.position;
            //Debug.Log (String.Format ("[EL] shift: {0}", shift));
            rootPart.transform.Translate(shift, Space.World);
            rootPart.transform.RotateAround(launchTransform.position, axis,
                                            angle);
            return(launchTransform);
        }
Exemple #3
0
            public Vector3 ShiftBounds(Transform frame, Vector3 pos,
                                       ExBuildControl.Box box)
            {
                Vector3 shift = new Vector3(-pos.x, -box.min.y, -pos.z);
                Vector3 mins  = box.min - pos;
                Vector3 maxs  = box.max - pos;
                Vector3 mid   = (mins + maxs) / 2;

                if (bounds.ContainsKey("+X"))
                {
                    float max_x = Vector3.Dot(frame.right, bounds["+X"]);
                    if (bounds.ContainsKey("-X"))
                    {
                        float min_x = Vector3.Dot(frame.right, bounds["-X"]);
                        shift.x += (max_x + min_x) / 2 - mid.x;
                    }
                    else
                    {
                        shift.x += max_x - maxs.x;
                    }
                }
                else if (bounds.ContainsKey("-X"))
                {
                    float min_x = Vector3.Dot(frame.right, bounds["-X"]);
                    shift.x += min_x - mins.x;
                }
                if (bounds.ContainsKey("+Y"))
                {
                    shift.y = -pos.y;
                    float max_y = Vector3.Dot(frame.up, bounds["+Y"]);
                    if (bounds.ContainsKey("-Y"))
                    {
                        float min_y = Vector3.Dot(frame.up, bounds["-Y"]);
                        shift.y += (max_y + min_y) / 2 - mid.y;
                    }
                    else
                    {
                        shift.y += max_y - maxs.y;
                    }
                }
                else if (bounds.ContainsKey("-Y"))
                {
                    shift.y = -pos.y;
                    float min_y = Vector3.Dot(frame.up, bounds["-Y"]);
                    shift.y += min_y - mins.y;
                }
                if (bounds.ContainsKey("+Z"))
                {
                    float max_z = Vector3.Dot(frame.forward, bounds["+Z"]);
                    if (bounds.ContainsKey("-Z"))
                    {
                        float min_z = Vector3.Dot(frame.forward, bounds["-Z"]);
                        shift.z += (max_z + min_z) / 2 - mid.z;
                    }
                    else
                    {
                        shift.z += max_z - maxs.z;
                    }
                }
                else if (bounds.ContainsKey("-Z"))
                {
                    float min_z = Vector3.Dot(frame.forward, bounds["-Z"]);
                    shift.z += min_z - mins.z;
                }

                return(shift);
            }