protected override void Awake() { base.Awake(); GoToOrigin.onClick.AddListener(delegate { var position = ((Drone)Source).GetJob().Pickup; AbstractCamera.LookHere(position); }); GoToDestination.onClick.AddListener(delegate { var position = ((Drone)Source).GetJob().DropOff; AbstractCamera.LookHere(position); }); GoToHub.onClick.AddListener(delegate { var position = ((Drone)Source).GetHub().transform.position; AbstractCamera.LookHere(position); }); FollowDrone.onClick.AddListener(delegate { AbstractCamera.Followee = ((Drone)Source).gameObject; }); JobInfo.onClick.AddListener(OpenJobWindow); JobHistory.onClick.AddListener(OpenJobHistoryWindow); }
private void ExecuteButton(IEvent iEvent) { if (iEvent.Target != null) { AbstractCamera.ActiveCamera.BreakFollow(); AbstractCamera.LookHere(new Vector3(iEvent.Target[0], iEvent.Target[1], iEvent.Target[2])); } iEvent.OpenWindow(); }
public override void OnInspectorGUI() { CompositeCamera compositeCamera; compositeCamera = target as CompositeCamera; if (compositeCamera == null) { return; } camerasFoldout = EditorGUILayout.Foldout(camerasFoldout, "Cameras"); if (camerasFoldout) { if (compositeCamera.cameras == null) { compositeCamera.cameras = new AbstractCamera[0]; } EditorGUILayout.BeginHorizontal(); string sp = " "; int newSize = EditorGUILayout.IntField(sp + "Size", compositeCamera.cameras.Length); EditorGUILayout.EndHorizontal(); if (newSize != compositeCamera.cameras.Length) { AbstractCamera[] newArray = new AbstractCamera[newSize]; Array.Copy(compositeCamera.cameras, newArray, Math.Min(newSize, compositeCamera.cameras.Length)); compositeCamera.cameras = newArray; } for (int i = 0; i < compositeCamera.cameras.Length; i++) { EditorGUILayout.BeginHorizontal(); compositeCamera.cameras[i] = (AbstractCamera)EditorGUILayout.ObjectField(sp + "Element " + i, compositeCamera.cameras[i], typeof(AbstractCamera)); EditorGUILayout.EndHorizontal(); } } EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); compositeCamera.currentCamera = EditorGUILayout.IntSlider("Current camera", Math.Min(compositeCamera.currentCamera, compositeCamera.cameras.Length - 1), 0, compositeCamera.cameras.Length - 1); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); compositeCamera.curve = EditorGUILayout.CurveField("Interpolation", compositeCamera.curve); EditorGUILayout.EndHorizontal(); lookAtDamping = EditorGUILayout.Foldout(lookAtDamping, "LookAt"); if (lookAtDamping) { ChaseCameraGUI.EditorGUISmoothLookAt(compositeCamera); } }
private void CastMiniMapRayToWorld(Vector2 localCursor) { var horizontalScale = MinimapCamera.pixelWidth * MapImage.uvRect.width; var xDir = localCursor.x * horizontalScale + MapImage.uvRect.x * MinimapCamera.pixelWidth; var verticalScale = MinimapCamera.pixelHeight * MapImage.uvRect.height; var yDir = localCursor.y * verticalScale + MapImage.uvRect.y * MinimapCamera.pixelHeight; var miniMapRay = MinimapCamera.ScreenPointToRay(new Vector2(xDir, yDir)); if (Physics.Raycast(miniMapRay, out RaycastHit miniMapHit, 3000, 1 << 13)) { Vector3 target = miniMapHit.point; AbstractCamera.LookHere(target); } }
protected override void Awake() { base.Awake(); GoToOrigin.onClick.AddListener(delegate { var position = ((Job)Source).Pickup; AbstractCamera.LookHere(position); }); GoToDestination.onClick.AddListener(delegate { var position = ((Job)Source).DropOff; AbstractCamera.LookHere(position); }); }
public static void EditorGUISmoothLookAt(AbstractCamera camera) { EditorGUILayout.BeginHorizontal (); camera.smoothLookAtEnabled = EditorGUILayout.Toggle("Rotation damping Enabled",camera.smoothLookAtEnabled); EditorGUILayout.EndHorizontal (); if (camera.smoothLookAtEnabled){ EditorGUILayout.BeginHorizontal (); camera.smoothLookAtDamping = EditorGUILayout.FloatField("Damping",camera.smoothLookAtDamping); EditorGUILayout.EndHorizontal (); } EditorGUILayout.BeginHorizontal (); camera.lookAtRotationOffset = Quaternion.Euler(EditorGUILayout.Vector3Field("Rotation offset",camera.lookAtRotationOffset.eulerAngles)); EditorGUILayout.EndHorizontal (); }
public static void EditorGUISmoothLookAt(AbstractCamera camera) { EditorGUILayout.BeginHorizontal(); camera.smoothLookAtEnabled = EditorGUILayout.Toggle("Rotation damping Enabled", camera.smoothLookAtEnabled); EditorGUILayout.EndHorizontal(); if (camera.smoothLookAtEnabled) { EditorGUILayout.BeginHorizontal(); camera.smoothLookAtDamping = EditorGUILayout.FloatField("Damping", camera.smoothLookAtDamping); EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginHorizontal(); camera.lookAtRotationOffset = Quaternion.Euler(EditorGUILayout.Vector3Field("Rotation offset", camera.lookAtRotationOffset.eulerAngles)); EditorGUILayout.EndHorizontal(); }
public override void OnInspectorGUI() { CompositeCamera compositeCamera; compositeCamera = target as CompositeCamera; if (compositeCamera == null) { return; } camerasFoldout = EditorGUILayout.Foldout(camerasFoldout, "Cameras"); if (camerasFoldout){ if (compositeCamera.cameras==null){ compositeCamera.cameras = new AbstractCamera[0]; } EditorGUILayout.BeginHorizontal (); string sp = " "; int newSize = EditorGUILayout.IntField(sp+"Size",compositeCamera.cameras.Length); EditorGUILayout.EndHorizontal (); if (newSize != compositeCamera.cameras.Length){ AbstractCamera[] newArray = new AbstractCamera[newSize]; Array.Copy(compositeCamera.cameras, newArray, Math.Min(newSize, compositeCamera.cameras.Length)); compositeCamera.cameras = newArray; } for (int i=0;i<compositeCamera.cameras.Length;i++){ EditorGUILayout.BeginHorizontal (); compositeCamera.cameras[i] = (AbstractCamera)EditorGUILayout.ObjectField(sp+"Element "+i, compositeCamera.cameras[i], typeof(AbstractCamera)); EditorGUILayout.EndHorizontal (); } } EditorGUILayout.Separator (); EditorGUILayout.BeginHorizontal (); compositeCamera.currentCamera = EditorGUILayout.IntSlider("Current camera", Math.Min( compositeCamera.currentCamera,compositeCamera.cameras.Length-1),0, compositeCamera.cameras.Length-1); EditorGUILayout.EndHorizontal (); EditorGUILayout.BeginHorizontal (); compositeCamera.curve = EditorGUILayout.CurveField("Interpolation", compositeCamera.curve); EditorGUILayout.EndHorizontal (); lookAtDamping =EditorGUILayout.Foldout(lookAtDamping, "LookAt"); if (lookAtDamping){ ChaseCameraGUI.EditorGUISmoothLookAt(compositeCamera); } }
/// <summary> /// Gets the pick ray. Single use, probably make static for now.... /// </summary> /// <returns></returns> public static Ray GetPickRay(AbstractCamera camera, GraphicsDevice graphicsDevice) { MouseState mouseState = Mouse.GetState(); // Reminder that these are clipping planes. The ray goes from the camera outwards. Vector3 nearSource = new Vector3((float)mouseState.X, mouseState.Y, 0f); Vector3 farSource = new Vector3((float)mouseState.X, mouseState.Y, 1f); Matrix world = Matrix.CreateTranslation(0, 0, 0); Vector3 nearPoint = graphicsDevice.Viewport.Unproject(nearSource, camera.Projection, camera.View, world); Vector3 farPoint = graphicsDevice.Viewport.Unproject(farSource, camera.Projection, camera.View, world); // Direction is thease two points make up a line. Vector3 direction = farPoint - nearPoint; direction.Normalize(); return(new Ray(nearPoint, direction)); }
protected override void Awake() { base.Awake(); GoToOrigin.onClick.AddListener(delegate { var position = ((RetiredDrone)Source).GetJob().Pickup; AbstractCamera.LookHere(position); }); GoToDestination.onClick.AddListener(delegate { var position = ((RetiredDrone)Source).GetJob().DropOff; AbstractCamera.LookHere(position); }); CollidedWith.onClick.AddListener(delegate { ((RetiredDrone)Source).OtherDrone?.OpenInfoWindow(); }); JobInfo.onClick.AddListener(OpenJobWindow); JobHistory.onClick.AddListener(OpenJobHistoryWindow); }
private void GoToHub() { var position = ((Hub)Source).transform.position; AbstractCamera.LookHere(position); }
/// <summary> /// Checks the mouse clicked. /// </summary> /// <param name="models">The models.</param> /// <param name="boardPlane">The board plane.</param> /// <param name="mouseDataReporter">The mouse data reporter.</param> /// <param name="camera">The camera.</param> /// <param name="graphicsDevice">The graphics device.</param> /// <returns></returns> public static MovementReport CheckMouseClicked(List <BasicModel> models, Plane boardPlane, MovementReport mouseDataReporter, AbstractCamera camera, GraphicsDevice graphicsDevice) { MouseState mouseState = Mouse.GetState(); if (mouseState.LeftButton == ButtonState.Pressed) { Ray pickRay = RayPick.GetPickRay(camera, graphicsDevice); Nullable <float> result = new Nullable <float>(); // Ray collides with a model. foreach (BasicModel model in models) { result = pickRay.Intersects(model.BoundingSphere); float selectedDistance = float.MaxValue; if (result.HasValue && mouseDataReporter.traveling == false) { selectedDistance = result.Value; // Do something to get more ship collided information mouseDataReporter.PlayerShipSelected["blueship"] = true; Console.WriteLine(string.Format("Slected ship, {0}.", "blueship")); mouseDataReporter.traveling = false; return(mouseDataReporter); } } if (!result.HasValue) { // Ray collides with the game board's plane. float collisionAt = float.MaxValue; Nullable <float> boardCollision = pickRay.Intersects(boardPlane); // prototype hardcodeing if (boardCollision.HasValue && mouseDataReporter.traveling == false && mouseDataReporter.PlayerShipSelected["blueship"] == true) { collisionAt = boardCollision.Value; Vector3 pointOfContact = pickRay.Position + pickRay.Direction * boardCollision.Value; mouseDataReporter.traveling = true; mouseDataReporter.PlayerShipSelected["blueship"] = false; mouseDataReporter.newCoordinates = pointOfContact; // Console.WriteLine(string.Format("Slected board space, {0} units away. At position {1}", collisionAt, pointOfContact)); return(mouseDataReporter); } } } return(mouseDataReporter); }
static void Main() { cube_thing.renderEngine.core.Settings.getInstance().setCurrentWindowSize(new int[] { 1024, 768 }); DisplayManager window = new DisplayManager(); //CAMERA setup GameObject camera = new GameObject("camera"); //Creating gameObject //String parameter is just a name AbstractCamera cam = new AbstractCamera(); //Creating camera World.getInstance().assingGameObject(camera); //Adding gameobject to the world cam.setMain(); //Sets this camera as main cam.setBackgroundColor(new Vector3(1,1,1)); //Sets background color -> RGB 0-1 at scale camera.addComponent(cam); //Adding the camera component to the gameobject camera.transform.position = new Vector3(0, 0, -5); renderEngine.tools.utils.Timer timer = renderEngine.tools.utils.Timer.getInstance(); //EVENTS KBEvent.getInstance(Key.A).addKeyDown(() => { camera.transform.rotation.Y-= 10*timer.getDeltaTime(); //timer.getDeltaTime() is for FPS drop to move always the same speed }); KBEvent.getInstance(Key.D).addKeyDown(() => { camera.transform.rotation.Y+= 10 * timer.getDeltaTime(); }); KBEvent.getInstance(Key.W).addKeyDown(() => { camera.transform.rotation.X-= 10 * timer.getDeltaTime(); }); KBEvent.getInstance(Key.S).addKeyDown(() => { camera.transform.rotation.X+= 10 * timer.getDeltaTime(); }); KBEvent.getInstance(Key.Q).addKeyDown(() => { cam.transform.position.Z-=1 * timer.getDeltaTime(); }); KBEvent.getInstance(Key.E).addKeyDown(() => { cam.transform.position.Z += 1* timer.getDeltaTime(); }); KBEvent.getInstance(Key.Escape).addKeyDown(() => { window.getWindow().Exit(); }); MWheelEvent.getInstance().addScroll((y) => { cam.transform.position.Z -= y * timer.getDeltaTime()*20; }); MMoveEvent.getInstance().addMove((x, y) => { camera.transform.rotation.Y += x * timer.getDeltaTime()*10; camera.transform.rotation.X += y * timer.getDeltaTime()*10; }); KBEvent.getInstance(Key.F12).addKeyPress(() => { if (GraphicsContext.CurrentContext == null) throw new GraphicsContextMissingException(); Bitmap bmp = new Bitmap(window.getWindow().ClientSize.Width, window.getWindow().ClientSize.Height); System.Drawing.Imaging.BitmapData data = bmp.LockBits(window.getWindow().ClientRectangle, System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); GL.ReadPixels(0, 0, window.getWindow().ClientSize.Width, window.getWindow().ClientSize.Height, OpenTK.Graphics.OpenGL.PixelFormat.Bgr, OpenTK.Graphics.OpenGL.PixelType.UnsignedByte, data.Scan0); bmp.UnlockBits(data); bmp.RotateFlip(RotateFlipType.RotateNoneFlipY); bmp.Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\Screenshot\" + DateTime.Now.ToString("yyy_MM_dd_h_mm_ss") + ".png"); }); //59 float resolution = 69; camera.transform.position = new Vector3(resolution / 2f -0.5f, resolution / 2f - 0.5f, resolution / 2f-0.5f); cam.transform.position.Z = resolution; //Window's onLoad event, OpenGL dependent code has to be here VoxelList list = new VoxelList(); Thread t = new Thread(delegate () { int R, G, B; R = G = B = 0; for (R = 0; R < resolution; R++) { for (G = 0; G < resolution; G++) { for (B = 0; B < resolution; B++) { list = list.Add(new VoxelList(new int[] { R, G, B }, new float[] { R / resolution, G / resolution, B / resolution, 1 })); } } } Console.WriteLine("Done: "+VoxelList.length+" "+R+" "+G+" "+B); }); t.Start(); window.Load(() => { /* //glDepthMask(false); for(int R = 0; R < resolution; R++) { for (int G = 0; G < resolution; G++) { for (int B = 0; B < resolution; B++) { //Sample box setup GameObject box = new GameObject("Box "+R+"-"+G+"-"+B); box.transform.position = new Vector3(R, G, B); DefaultMat material = new DefaultMat(); //Creating material component material.setCullingEnabled(false); //Backface culling enabled material.setHasTransparency(true); box.transform.scale = new Vector3(0.999f, 0.999f, 0.999f); material.setColor(new Vector4(R/resolution, G/ resolution ,B/ resolution, 1)); //Setting the materials color Renderer m = new Renderer(Primitives.Cube(), material); //Creating renderer component -> Parameters Primitives.PRIMITIVE_NAME, material box.addComponent(m); //Assing renderer to the gameobject box.transform.createTransformationMatrix(); World.getInstance().assingGameObject(box); //Add gameobject to the world System.GC.Collect(); } } }*/ }); //Starting the rendering at 60 Update/s with 60 FPS window.Start(60,60); }
/// <summary> /// Adds models to the game. Add camera to the game. We'll do more with this later. /// </summary> protected override void LoadContent() { _spriteBatch = new SpriteBatch(GraphicsDevice); //Load camera. if (_cameraType == CameraType.TargetCamera) { _camera = new TargetCamera( (new Vector3(0, 500, 500)) * 3, Vector3.Zero, GraphicsDevice); } if (_cameraType == CameraType.FreeCamera) { _camera = new FreeCamera( (new Vector3(500, 600, 1300)) * 1, MathHelper.ToRadians(153), MathHelper.ToRadians(5), GraphicsDevice); } // Load Card texture. _cardTexture = Content.Load <Texture2D>("Cards\\Images\\cardlayout-2"); // Load some fonts. _basicFont = Content.Load <SpriteFont>("Fonts\\SpriteFont1"); _rulesTextFont = Content.Load <SpriteFont>("Fonts\\RulesTextFont"); _rulesTextItalicFont = Content.Load <SpriteFont>("Fonts\\RulesTextItalicFont"); _titleFont = Content.Load <SpriteFont>("Fonts\\TitleFont"); _typeFont = Content.Load <SpriteFont>("Fonts\\TypeFont"); _statFont = Content.Load <SpriteFont>("Fonts\\StatFont"); // Load models. _models.Add( new BasicModel( Content.Load <Model>("blueship"), Vector3.Zero, Quaternion.Identity, new Vector3(.01f), GraphicsDevice)); _movementDataReporter.PlayerShipSelected.Add("blueship", false); //Load sky box. _skybox = new Skybox(Content, GraphicsDevice, Content.Load <TextureCube>("Textures\\bluestreak")); //Load stars. Random r = new Random(); Vector3[] postions = new Vector3[30000]; float dispersalRate = 700000; float height = -400000; for (int i = 0; i < postions.Length; i++) { postions[i] = new Vector3((float)r.NextDouble() * dispersalRate - dispersalRate / 2, (float)r.NextDouble() * (height) - height / 2, (float)r.NextDouble() * dispersalRate - dispersalRate / 2); //postions[i] = new Vector3(10000, 400, 10000); } _stars = new BillboardSystem(GraphicsDevice, Content, Content.Load <Texture2D>("BillboardTextures\\flare-blue-purple1"), new Vector2(800), postions); // TEST DESERIALIZATION //_cards = CardCollection.Deserialize(File.ReadAllText("Content/Cards/Cards.json")); _cards = CardCollection.Deserialize(File.ReadAllText("Content/Cards/Cards.json")); FleetHackers.FleetHackersServer.FleetHackersServiceClient fhClient = new FleetHackers.FleetHackersServer.FleetHackersServiceClient(); string result = fhClient.GetData(1223); //this test works. //Appears we're experiencing some schema issues here. Will track down what the issue is. //cards = fhClient.GetCardData(new List<Card>()); //cards = fhClient.GetCardData(cards); // This stuff needs fixing. JSON is disabled in the meantime. fhClient.Close(); foreach (Card c in _cards) { Debug.WriteLine(c.Title); Debug.WriteLine(c.RulesText); } //initialize debug stuff DebugDraw._camera = _camera; DebugDraw._lineDrawer = _lineDrawer; }