Beispiel #1
0
        ///<summary>
        ///Called when the owner is registered
        ///</summary>
        protected override bool _OnRegister(TorqueObject owner)
        {
            if (!base._OnRegister(owner) || !(owner is T2DSceneObject))
                return false;

            //todo: perform initialization for the component

            //todo: look up interfaces exposed by other components
            //E.g.,
            //_theirInterface =
            //     Owner.Components.GetInterface<ValueInterface<float>>(
            //         "float", "their interface name");

            //activate tick callback for this component.
            ProcessList.Instance.AddTickCallback(Owner, this);

            if (null != _monitoredObject as T2DSpawnObject)
            {
                string name;
                if (_monitoredObject.Name.EndsWith("Template") ||
                    _monitoredObject.Name.EndsWith("template"))
                {
                    name =
                        _monitoredObject.Name.Substring(
                            0, _monitoredObject.Name.Length - 8);
                }
                else
                {
                    name = _monitoredObject.Name + "Instance";
                }
                _monitoredObject =
                    TorqueObjectDatabase.Instance.FindObject<T2DStaticSprite>(name);
            }

            if ((_monitoredObject != null) && (_monitoredInterfaceName != null))
            {
                _monitoredInterface =
                    _monitoredObject.Components.GetInterface<ValueInterface<float>>(
                        "float", _monitoredInterfaceName);
            }

            //create a camera for the compass
            T2DSceneCamera defaultCamera =
                TorqueObjectDatabase.Instance.FindObject<T2DSceneCamera>("Camera");
            if (defaultCamera != null)
            {
                T2DSceneCamera instrumentCam =
                    (T2DSceneCamera)defaultCamera.Clone();
                instrumentCam.Name = "InstrumentCam";
                TorqueObjectType instrument =
                    TorqueObjectDatabase.Instance.GetObjectType("instrument");

                instrumentCam.CenterPosition = CameraCenter;
                instrumentCam.Extent = CameraExtent;

                TorqueObjectDatabase.Instance.Register(instrumentCam);

                //display the instrument camera on screen
                GUIControlStyle instrumentStyle = new GUIControlStyle();
                GUISceneview instrumentView = new GUISceneview();
                instrumentView.Name = "InstrumentView";
                instrumentView.Style = instrumentStyle;
                instrumentView.Camera = instrumentCam;

                //only render objects of type "instrument"
                instrumentView.RenderMask = instrument;
                instrumentView.Visible = true;
                instrumentView.Folder =
                    TorqueObjectDatabase.Instance.FindObject<GUISceneview>("DefaultSceneView");
                instrumentView.Position = ViewPosition;
                instrumentView.Size = ViewSize;
            }

            return true;
        }
        /// <summary>
        /// Called when the owner is registered
        /// </summary>
        protected override bool _OnRegister(TorqueObject owner)
        {
            if (!base._OnRegister(owner) || !(owner is T2DSceneObject))
                return false;

            // todo: perform initialization for the component

            // todo: look up interfaces exposed by other components
            // E.g.,
            // _theirInterface =
            //      Owner.Components.GetInterface<ValueInterface<float>>(
            //          "float", "their interface name");

            // activate tick callback for this component.
            ProcessList.Instance.AddTickCallback(Owner, this);

            _maxForwardSpeed =
                Owner.Components.GetInterface<ValueInterface<float>>(
                    "float", "maxForwardSpeed");
            _maxReverseSpeed =
                Owner.Components.GetInterface<ValueInterface<float>>(
                    "float", "maxReverseSpeed");
            _maxBrakingDeceleration =
                Owner.Components.GetInterface<ValueInterface<float>>(
                    "float", "maxBrakingDeceleration");

            return true;
        }
 /// <summary>
 /// Get interfaces for position and rotation of named link point, if link point exists.
 /// </summary>
 /// <param name="name">Name of link point to query.</param>
 /// <param name="position">TorqueInterface for link point position.</param>
 /// <param name="rotation">TorqueInterface for link point rotation.</param>
 /// <returns>True if link point exists.</returns>
 public bool GetLinkPoint(string name, out ValueInterface<Vector2> position, out ValueInterface<float> rotation)
 {
     Assert.Fatal(name != null && name != String.Empty, "link points must have a name");
     SList<LinkPoint> walk = _linkPoints;
     while (walk != null)
     {
         if (walk.Val.Name == name)
         {
             position = walk.Val.Position;
             rotation = walk.Val.Rotation;
             return true;
         }
         walk = walk.Next;
     }
     position = null;
     rotation = null;
     return false;
 }