public override void GenericRender(Camera3D camera, GraphicsDevice graphicsDevice) { RenderEffect.SetMatrices(GlobalTransform, camera.View, camera.Projection); if (m_Parent.BoneMatrices != null) RenderEffect.SetBones(m_Parent.BoneMatrices); // Set camera position RenderEffect.SetCameraPosition(camera.transform.Position); // Apply the Render Effect RenderEffect.Apply(); // Switch cull mode RenderManager.Instance.SetCullMode(CullMode.CullClockwiseFace); RenderManager.Instance.SetDepthStencilState(DepthStencilState.DepthRead); graphicsDevice.SetVertexBuffer(m_MeshPart.VertexBuffer, m_MeshPart.VertexOffset); graphicsDevice.Indices = m_MeshPart.IndexBuffer; graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, m_MeshPart.NumVertices, m_MeshPart.StartIndex, m_MeshPart.PrimitiveCount); // Switch cull mode RenderManager.Instance.SetDepthStencilState(DepthStencilState.Default); RenderManager.Instance.SetCullMode(CullMode.CullCounterClockwiseFace); }
private void PlaceEntity() { Camera3D camera = this.RenderManager.ActiveCamera3D; if (camera != null) { transform.LocalPosition = camera.Transform.Position + (camera.Transform.WorldTransform.Forward * this.PlaceDistance); } }
public GameplayLoop(TitleLoop titleLoop = null) : base(LoopTypes.Gameplay) { // TODO: Pull relevant objects from the title loop (likely camera and maybe scene). camera = new Camera3D(); var accessor = Properties.Access(); physicsMaxIterations = accessor.GetInt("physics.max.iterations"); }
private void ShowInfo() { Camera3D camera = this.RenderManager.ActiveCamera3D; if (AllowInfo && camera != null) { // Show Planet Info } }
public void DrawAll(GraphicsDevice device, Camera3D camera) { foreach (KeyValuePair <int, BaseEntity> KeyPair in All) { BaseEntity entity = KeyPair.Value; entity.Schematic.RenderBasic.Draw(device, camera, entity.Position, entity.Schematic.RenderOffset, entity.Rotation, entity.Scale); } }
public GameScreen( ScreenManager screenManager, GeometryManager geometryManager, GameState gameState ) : base(screenManager) { _camera = new Camera3D(); _gameState = gameState; _game = new Beardgame(gameState); _geometries = geometryManager; }
/// <inheritdoc/> protected override void Start() { base.Start(); // Create GazeProvider Camera3D cam = this.Managers.EntityManager.FindFirstComponentOfType <Camera3D>(); cam.Owner.AddComponent(new GazeProvider()); }
public VertexPositionTextureDrawer( Camera3D camera3D, IGraphicsDeviceService graphicsDeviceService ) { this._graphicsDeviceService = graphicsDeviceService; this._camera = camera3D.NotNull(); this._camera.Changed += this.UpdateBasicEffect; this._graphicsDeviceService.DeviceCreated += this.RecreateBassicEffect; this.CreateBasicEffect(); }
protected override void OnActivated() { base.OnActivated(); this.boundingSphere = new BoundingSphere(this.transform3D.Position, (this.transform3D.Scale.X / 2) + 0.5f); this.activeCamera3D = this.Owner.Scene.Managers.RenderManager.ActiveCamera3D; this.mouseDispatcher = activeCamera3D.Display.MouseDispatcher; }
public VertexPositionColorDrawer( IGraphicsDeviceService deviceService, Camera3D camera3D ) { this._camera = camera3D.NotNull(); this._camera.Changed += this.UpdateBasicEffect; this._graphicsDeviceService = deviceService; this._graphicsDeviceService.DeviceCreated += this.RecreateBassicEffect; this.CreateBasicEffect(); this.CreateBasicEffect(); }
public void Draw(GraphicsDevice device, Camera3D camera) { if (_previewData.GetAllVertsTranslated(Vector3.Zero).Count() > 0) { device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, _previewData.GetAllVertsTranslated(_keyboardCursor.WorldLocation), 0, _previewData.GetAllVertsTranslated(Vector3.Zero).Count(), _previewData.GetAllIndices(), 0, _previewData.GetAllIndices().Count() / 3); } }
private void AddSecurityCamera(Viewport viewport, ProjectionParameters projectionParameters) { Transform3D transform = new Transform3D(new Vector3(50, 10, 10), Vector3.Zero, Vector3.Zero, -Vector3.UnitX, Vector3.UnitY); Camera3D camera3D = new Camera3D("security camera 1", ActorType.Camera, transform, projectionParameters, viewport); camera3D.AttachController(new SecurityCameraController("scc1", ControllerType.Security, 15, 2, Vector3.UnitX)); this.cameraManager.Add(camera3D); }
public override float CalcDistanceToCamera(Camera3D camera) { if (Widget == null) { return(0f); } var p = GlobalTransform.TransformVector((Vector3)(Widget.Position * new Vector2(1, -1))); return(camera.View.TransformVector(p).Z); }
protected AbstractRenderer3D(Camera3D camera, GlobalLight3D light) { Debug.Assert(camera != null, "3D renderers must be created with a non-null camera."); Debug.Assert(light != null, "3D renderers must be created with a non-null global light class."); Camera = camera; Light = light; keys = new List <K>(); map = new Dictionary <K, List <V> >(); }
/// <summary> /// Get a ray positioned at the mouse's location on the screen - used for picking /// </summary> /// <param name="camera"></param> /// <returns></returns> public Microsoft.Xna.Framework.Ray GetMouseRay(Camera3D camera) { //get the positions of the mouse in screen space Vector3 near = new Vector3(newState.X, newState.Y, 0); //convert from screen space to world space near = camera.Viewport.Unproject(near, camera.Projection, camera.View, Matrix.Identity); return(GetMouseRayFromNearPosition(camera, near)); }
/// <summary> /// カメラ、ライトの更新が行われます /// </summary> static public void Update() { Camera3D.Update(); if (Camera3D.IsUpdated || isLightUpdate_) { viewSpaceLightPos_ = Vector4.Transform(lightPos_, Camera3D.ViewMatrix); isLightUpdate_ = false; } }
/// <summary> /// Get a ray from a user-defined near position in world space and the mouse pointer /// </summary> /// <param name="camera"></param> /// <param name="near"></param> /// <returns></returns> public Microsoft.Xna.Framework.Ray GetMouseRayFromNearPosition(Camera3D camera, Vector3 near) { //get the positions of the mouse in screen space Vector3 far = new Vector3(newState.X, newState.Y, 1); //convert from screen space to world space far = camera.Viewport.Unproject(far, camera.Projection, camera.View, Matrix.Identity); //generate a ray to use for intersection tests return(new Microsoft.Xna.Framework.Ray(near, Vector3.Normalize(far - near))); }
public override void Draw(Camera3D camera) { PointBatch.Begin(Matrix.Identity, camera); for (int i = 0; i < starCount; i++) { PointBatch.Draw(points[i], starRadius, new Color(brightnesses[i], brightnesses[i], brightnesses[i])); } PointBatch.End(); }
public Skybox(Engine engine) : base(engine) { CameraTarget = Vector3.Forward; camera = new Camera3D(engine); camera.Target = new Vector3(1, 0, 0); effect = engine.Content.Load <Effect>(@"Shaders\Effects"); skyboxModel = LoadModel(@"Skyboxes\Space", out skyboxTextures); Engine.AddComponent(this); }
private void AddTrack3DCamera(Viewport viewport, ProjectionParameters projectionParameters) { //doesnt matter where the camera starts because we reset immediately inside the Transform3DCurveController Transform3D transform = Transform3D.Zero; Camera3D camera3D = new Camera3D("curve camera 1", ActorType.Camera, transform, projectionParameters, viewport); camera3D.AttachController(new Track3DController("tcc1", ControllerType.Track, this.track3DDictionary["push forward 1"], PlayStatusType.Play)); this.cameraManager.Add(camera3D); }
/// <summary> /// Update camera using vr provider data /// </summary> /// <param name="camera">The camera</param> /// <param name="eyeIndex">The eye index</param> private void UpdateCamera(Camera3D camera, int eyeIndex) { var eyeProperties = this.vrProvider.EyesProperties[eyeIndex]; var eyeTexture = eyeProperties.Texture; var eyePose = eyeProperties.Pose; camera.RenderTarget = eyeTexture.RenderTarget; camera.Viewport = eyeTexture.Viewport; camera.Transform.LocalPosition = this.Monoscopic ? this.CenterEyeAnchorTransform.LocalPosition : eyePose.Position; camera.Transform.LocalOrientation = this.Monoscopic ? this.CenterEyeAnchorTransform.LocalOrientation : eyePose.Orientation; }
public override void Load(ContentManager content) { Graphics = SceneManager.Game.GraphicsDevice; Effect = new BasicEffect(Graphics); Effect.VertexColorEnabled = true; Rasterizer = new RasterizerState(); Rasterizer.CullMode = CullMode.None; Rasterizer.FillMode = FillMode.WireFrame; Camera = new Camera3D(); base.Load(content); }
private void AddFlightCamera(Viewport viewport, ProjectionParameters projectionParameters) { Transform3D transform = new Transform3D(new Vector3(0, 10, 30), Vector3.Zero, Vector3.Zero, -Vector3.UnitZ, Vector3.UnitY); Camera3D camera3D = new Camera3D("flight camera 1", ActorType.Camera, transform, projectionParameters, viewport); camera3D.AttachController(new FlightCameraController("flight camera controller 1", ControllerType.Flight, AppData.CameraMoveKeys_Alt1, AppData.CameraMoveSpeed, AppData.CameraStrafeSpeed, AppData.CameraRotationSpeed, this.inputManagerParameters, this.screenCentre)); this.cameraManager.Add(camera3D); }
/// <inheritdoc/> protected override void Start() { base.Start(); // Create GazeProvider Camera3D cam = this.Managers.EntityManager.FindFirstComponentOfType <Camera3D>(); cam.Owner.AddComponent(new GazeProvider() { CollisionCategoryMask = this.CursorCollisionCategoryMask & ~this.CursorCollisionCategory }); }
private void AddRailCamera(Viewport viewport, ProjectionParameters projectionParameters) { //doesnt matter where the camera starts because we reset immediately inside the RailController Transform3D transform = Transform3D.Zero; Camera3D camera3D = new Camera3D("rail camera 1", ActorType.Camera, transform, projectionParameters, viewport); camera3D.AttachController(new RailController("rc1", ControllerType.Rail, this.drivableModelObject, this.railDictionary["battlefield 1"])); this.cameraManager.Add(camera3D); }
/// <summary> /// Initializes a new instance of the <see cref="ThirdCameraBehavior" /> class. /// </summary> /// <param name="entity">The entity.</param> /// <exception cref="System.ArgumentNullException">If entity is null.</exception> public ThirdCameraBehavior(Entity entity) : base("ThirdCameraBehavior") { if (entity == null) { throw new ArgumentNullException("entity", "The entity cannot be null"); } this.Camera = null; this.entity = entity; this.CameraDistance = new Vector3(0f, -5f, -15f); this.TargetPosition = Vector3.Zero; }
/// <inheritdoc/> protected override bool OnAttached() { var attached = base.OnAttached(); this.UpdateOrder = this.MainCursor.UpdateOrder + 0.1f; // Ensure this is executed always after the main Cursor this.cam = this.Managers.RenderManager.ActiveCamera3D; this.handrayTexture = this.LineMesh.DiffuseTexture; this.lineMeshTransform = this.LineMesh.Owner.FindComponent <Transform3D>(); return(attached); }
public ModelRenderer(Camera3D camera, GlobalLight3D light, uint bufferCapacity = 0, uint indexCapacity = 0) : base(camera, light, bufferCapacity, indexCapacity) { shader = new Shader(); shader.Attach(ShaderTypes.Vertex, "ModelShadow.vert"); shader.Attach(ShaderTypes.Fragment, "ModelShadow.frag"); shader.AddAttribute <float>(3, GL_FLOAT); shader.AddAttribute <float>(2, GL_FLOAT); shader.AddAttribute <float>(1, GL_FLOAT); shader.AddAttribute <float>(3, GL_FLOAT); Bind(bufferId, indexId); }
//This method gets called just before the window is shown, and the device is created protected override void Initialise() { //draw targets usually need a camera. //create a 3D camera with default parameters Camera3D camera = new Camera3D(); //create the draw target. drawToScreen = new DrawTargetScreen(this, camera); //Set the screen clear colour to blue //(Draw targets have a built in ClearBuffer object) drawToScreen.ClearBuffer.ClearColour = Color.CornflowerBlue; }
public DebugPlayScreen(GraphicsDevice graphics, GameWindow gameWindow, ContentManager content) { camera = new Camera3D(gameWindow.ClientBounds, new Vector3(0, 13, 0), Vector2.Zero, Vector3.Up); worldGraphics = new WorldGraphics(graphics, gameWindow, content, camera); movementController = new DebugMovementController(camera, gameWindow); fogController = new DebugFogController(worldGraphics); PushScreenElement(worldGraphics); PushMouseListener(movementController); PushKeyboardListener(movementController); PushKeyboardListener(fogController); }
/// <summary> /// Get a ray positioned at the screen position - used for picking when we have a centred reticule /// </summary> /// <param name="camera"></param> /// <param name="screenPosition"></param> /// <returns></returns> public Vector3 GetMouseRayDirection(Camera3D camera, Vector2 screenPosition) { //get the positions of the mouse in screen space Vector3 near = new Vector3(screenPosition.X, screenPosition.Y, 0); Vector3 far = new Vector3(Position, 1); //convert from screen space to world space near = camera.Viewport.Unproject(near, camera.Projection, camera.View, Matrix.Identity); far = camera.Viewport.Unproject(far, camera.Projection, camera.View, Matrix.Identity); //generate a ray to use for intersection tests return(Vector3.Normalize(far - near)); }
/// <inheritdoc/> protected override void Update(TimeSpan gameTime) { Camera3D cam = this.Managers.RenderManager.ActiveCamera3D; this.transform.Orientation = cam.Transform.Orientation; if (this.scale) { Vector3 direction = this.transform.Position - cam.Transform.Position; float t = Math.Max(1, direction.Length()); this.transform.Scale = Vector3.One * (t / 1f); } }
protected override void Initialise() { Camera3D camera = new Camera3D(); camera.LookAt(new Vector3(0, 0, 4), new Vector3(3, 4, 4), new Vector3(0, 0, 1)); //create the draw target. drawToScreen = new DrawTargetScreen(this, camera); drawToScreen.ClearBuffer.ClearColour = Color.CornflowerBlue; //NEW CODE //create the actor instance drawToScreen.Add(new Actor(this.Content)); }
public override void ReconstructShading(GameTime deltaTime, Camera3D camera, Matrix view, Matrix projection, GraphicsDevice graphicsDevice) { // this pass uses the light accumulation texture and reconstruct the mesh's shading // our parameters were already filled in the first pass RenderEffect.SetCurrentTechnique(1); RenderEffect.SetMatrices(GlobalTransform, view, projection); // Apply the Render Effect RenderEffect.Apply(); graphicsDevice.SetVertexBuffer(m_MeshPart.VertexBuffer, m_MeshPart.VertexOffset); graphicsDevice.Indices = m_MeshPart.IndexBuffer; graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, m_MeshPart.NumVertices, m_MeshPart.StartIndex, m_MeshPart.PrimitiveCount); }
public void Draw(Camera3D pCamera) { Matrix[] pTransforms = new Matrix[m_pModel.Bones.Count]; m_pModel.CopyAbsoluteBoneTransformsTo(pTransforms); foreach (ModelMesh pMesh in m_pModel.Meshes) { foreach (BasicEffect pEffect in pMesh.Effects) { pEffect.EnableDefaultLighting(); pEffect.World = pTransforms[pMesh.ParentBone.Index] * (pCamera.getWorld(m_pPosition, m_pRotation, m_fScale)); pEffect.View = pCamera.getView(); pEffect.Projection = pCamera.getProjection(); } pMesh.Draw(); } }
public override void RenderToGBuffer(Camera3D camera, GraphicsDevice graphicsDevice) { RenderEffect.SetCurrentTechnique(0); RenderEffect.SetMatrices(GlobalTransform, camera.View, camera.Projection); //our first pass is responsible for rendering into GBuffer RenderEffect.SetFarClip(camera.FarPlane); if (m_Parent.BoneMatrices != null) RenderEffect.SetBones(m_Parent.BoneMatrices); RenderEffect.Apply(); graphicsDevice.SetVertexBuffer(m_MeshPart.VertexBuffer, m_MeshPart.VertexOffset); graphicsDevice.Indices = m_MeshPart.IndexBuffer; // Draw indexed primitives for this sub mesh graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, m_MeshPart.NumVertices, m_MeshPart.StartIndex, m_MeshPart.PrimitiveCount); }
protected override void CreateScene() { // Lights DirectionalLight light = new DirectionalLight("light", new Vector3(-10f, 7f, -5f)); EntityManager.Add(light); RenderManager.FrustumCullingEnabled = false; // Game Behavior GameBehavior gameBehavior = new GameBehavior(); // Create Player this.Player = this.modelFactoryService.CreatePlayer(gameBehavior); EntityManager.Add(this.Player); // Create Camera var camera = new FixedCamera("mainCamera", Vector3.Zero, Vector3.Zero); // Setted in GameBehavior Init camera.BackgroundColor = Color.CornflowerBlue; this.GameCamera = camera.Entity.FindComponent<Camera3D>(); EntityManager.Add(camera); // Add Scene Behavior this.AddSceneBehavior(gameBehavior, SceneBehavior.Order.PostUpdate); }
public virtual void RenderToGBuffer(Camera3D camera, GraphicsDevice graphicsDevice) { }
public virtual void ReconstructShading(GameTime deltaTime, Camera3D camera, Matrix view, Matrix projection, GraphicsDevice graphicsDevice) { }
public virtual void GenericRender(Camera3D camera, GraphicsDevice graphicsDevice) { }
public virtual void ReflectionRender(GameTime deltaTime, List<AbstractMesh> meshes, Camera3D camera, GraphicsDevice graphicsDevice) { }
public FollowCameraBehavior(Entity cameraEntity) : base("FollowCamera") { this.camera = cameraEntity.FindComponent<Camera3D>(); }
/// <summary> /// Update camera using vr provider data /// </summary> /// <param name="camera">The camera</param> /// <param name="eyeIndex">The eye index</param> private void UpdateCamera(Camera3D camera, int eyeIndex) { var eyeTexture = this.vrProvider.EyeTextures[eyeIndex]; var eyePose = this.vrProvider.EyePoses[eyeIndex]; var rt = eyeTexture.RenderTarget; camera.RenderTarget = rt; camera.Viewport = eyeTexture.Viewport; ////camera.View = eyePose.View; camera.Transform.LocalPosition = this.Monoscopic ? this.CenterEyeAnchorTransform.LocalPosition : eyePose.Position; camera.Transform.LocalOrientation = this.Monoscopic ? this.CenterEyeAnchorTransform.LocalOrientation : eyePose.Orientation; }
public override void ReflectionRender(GameTime deltaTime, List<AbstractMesh> meshes, Camera3D camera, GraphicsDevice graphicsDevice) { if ((graphicsDevice != null) && (m_ReflectionTarget != null) && (m_RefractionTarget != null)) { // Now we have access to all the "default" meshes inside the water sub mesh object :) if (meshes.Count > 0) { // For now hack in a water height const float waterHeight = 1.0f; /* Reimers */ Vector3 cameraFinalTarget = (camera.transform.Position + camera.transform.WorldMatrix.Forward); // Obtain the camera reflection position Vector3 reflectionCamPosition = camera.transform.Position; reflectionCamPosition.Y = -camera.transform.Position.Y + waterHeight * 2; // Obtain the target of camera B Vector3 reflectionTargetPos = cameraFinalTarget; reflectionTargetPos.Y = -cameraFinalTarget.Y + waterHeight * 2; // Get the up vector of camera B Vector3 invUpVector = Vector3.Cross(camera.transform.WorldMatrix.Right, (reflectionTargetPos - reflectionCamPosition)); // Create the camera B reflection view matrix Matrix reflectionViewMatrix = Matrix.CreateLookAt(reflectionCamPosition, reflectionTargetPos, invUpVector); Matrix reflectionProjectionMatrix = camera.Projection; // Generate a reflection plane Plane reflectionPlane = CreatePlane(camera, (waterHeight - 0.5f), new Vector3(0, -1, 0), reflectionViewMatrix, true); Plane refractionPlane = CreatePlane(camera, ((waterHeight + 4) - 0.5f), new Vector3(0, -1, 0), camera.View, false); /*Vector4 testPlane = new Vector4(0, 1, 0, -(waterHeight - 0.5f)); reflectionPlane.Normal = new Vector3(testPlane.X, testPlane.Y, testPlane.Z); reflectionPlane.D = testPlane.W;*/ // Reflection render graphicsDevice.SetRenderTarget(m_ReflectionTarget); // Clear to black graphicsDevice.Clear(Color.Black); foreach (SubMesh mesh in meshes) { mesh.RenderEffect.SetReflectionClipPlane(reflectionPlane); // Some how render these objects into the reflection target ( need to decide on this still ) mesh.ReconstructShading(deltaTime, camera, reflectionViewMatrix, reflectionProjectionMatrix, graphicsDevice); // Set to null now were done with it mesh.RenderEffect.SetReflectionClipPlane(new Plane(Vector4.Zero)); } graphicsDevice.SetRenderTarget(null); // Refraction Render graphicsDevice.SetRenderTarget(m_RefractionTarget); // Clear to black graphicsDevice.Clear(Color.Black); foreach (SubMesh mesh in meshes) { mesh.RenderEffect.SetRefractionClipPlane(refractionPlane); // Some how render these objects into the reflection target ( need to decide on this still ) mesh.ReconstructShading(deltaTime, camera, camera.View, camera.Projection, graphicsDevice); // Set to null now were done with it mesh.RenderEffect.SetRefractionClipPlane(new Plane(Vector4.Zero)); } graphicsDevice.SetRenderTarget(null); // Set the water view projection to the water mesh shader EffectParameter waterViewProj = RenderEffect.GetParameter("xWaterViewProjection"); if (waterViewProj != null) waterViewProj.SetValue(reflectionViewMatrix * reflectionProjectionMatrix); } } }
public override void ReconstructShading(GameTime deltaTime, Camera3D camera, Matrix view, Matrix projection, GraphicsDevice graphicsDevice) { // Set scroll time offset RenderEffect.SetScrollTime((float)deltaTime.TotalGameTime.TotalSeconds); // Set camera position RenderEffect.SetCameraPosition(camera.transform.Position); // Render as per normal base.ReconstructShading(deltaTime, camera, view, projection, graphicsDevice); }
public CameraBehavior() : base("CameraBehavior") { Camera = null; }
public override void terminate() { camera = null; player = null; }
public override void ReconstructShading(GameTime deltaTime, Camera3D camera, Matrix view, Matrix projection, Microsoft.Xna.Framework.Graphics.GraphicsDevice graphicsDevice) { base.GenericRender(camera, graphicsDevice); }
/// <summary> /// Initializes a new instance of the <see cref="FreeCameraBehavior" /> class. /// </summary> public FreeCameraBehavior() : base("FreeCameraBehavior") { this.isDragging = false; this.Camera = null; }
public override void start() { background = new Objeto2D(Game1.self.Content.Load<Texture2D>("fundo")); background.posicao.X = 512; background.posicao.Y = 384; backgroundslow = new Objeto2D(Game1.self.Content.Load<Texture2D>("fundoslow")); backgroundslow.posicao.X = 512; backgroundslow.posicao.Y = 384; texture = Game1.self.Content.Load<Texture2D>("coracaovida"); zombie = Game1.self.Content.Load<Texture2D>("Zombie_Tank"); pausedTexture = Game1.self.Content.Load<Texture2D>("pause"); pausedRectangle = new Rectangle(0, 0, 1024, 768); slowmotionbar = Game1.self.Content.Load<Texture2D>("slowmotionbar"); slowposition = new Vector2(330, 600); slowRectangle = new Rectangle(0, 0, slowmotionbar.Width, slowmotionbar.Height); player = new Player(Game1.self.Content.Load<Model>("player")); InimigoManager.modeloInimigos = Game1.self.Content.Load<Model>("inimigo"); pontos = new Pontos(); TiroManager.Initialize(Game1.self.Content.Load<Model>("player")); camera = new Camera3D(); random = new Random(); //quantidadeInimigos = 4; InimigoManager.criarInimigo(quantidadeInimigos); }
public MouseInformation( Camera3D camera ) { this.MouseMoveDelta = Vector2.Zero; this._camera = camera; this._lefButtonChanged = new Subject<ButtonState>(); }
private Plane CreatePlane(Camera3D camera, float height, Vector3 planeNormalDirection, Matrix currentViewMatrix, bool clipSide) { planeNormalDirection.Normalize(); Vector4 planeCoeffs = new Vector4(planeNormalDirection, height); if (clipSide) planeCoeffs *= -1; Matrix worldViewProjection = (currentViewMatrix * camera.Projection); Matrix inverseWorldViewProjection = Matrix.Invert(worldViewProjection); inverseWorldViewProjection = Matrix.Transpose(inverseWorldViewProjection); planeCoeffs = Vector4.Transform(planeCoeffs, inverseWorldViewProjection); return new Plane(planeCoeffs); }
public FireBehavior() : base("FireBehavior") { Camera = null; }
// AIR does not yet show anything. why public ApplicationSprite() { // curityError: Error #2148: SWF file file:///X|/jsc.svn/examples/actionscript/synergy/Flare3DWaterShips/Flare3DWaterShips/bin/Debug/staging/Flare3DWaterShips.ApplicationSprite/web/Flare3DWaterShips.ApplicationSprite.swf cannot access local resource file:///X|/jsc.svn/examples/actionscript/synergy/Flare3DWaterShips/Flare3DWaterShips/bin/Debug/staging/Flare3DWaterShips.ApplicationSprite/web/Flare3DWaterShips.ApplicationSprite.swf/[[DYNAMIC]]/3. Only local-with-filesystem and trusted local SWF files may access local resources. //at flash.display::Loader/get content() //at flare.core::Texture3D/completeEvent()[Z:\projects\flare3d 2.5\src\flare\core\Texture3D.as:496] var scene = new Viewer3D(this, "", 0.2); scene.camera = new Camera3D(); scene.camera.setPosition(120, 40, -30); scene.camera.lookAt(0, 0, 0); #region mirrorCam var mirrorCam = new Camera3D(); var mirror = new Texture3D(new Point(512, 512)); mirror.mipMode = Texture3D.MIP_NONE; mirror.wrapMode = Texture3D.WRAP_CLAMP; mirror.upload(scene); #endregion #region oceanShader var Ocean = KnownEmbeddedResources.Default["assets/Flare3DWaterShips/ocean07.flsl.compiled"]; var oceanShader = new FLSLMaterial("oceanShader", Ocean.ToByteArrayAsset()); var oceanShader_params = oceanShader.@params as dynamic; // http://www.flare3d.com/docs/flare/core/Texture3D.html // http://wiki.flare3d.com/index.php?title=FLAR_Toolkit_integration oceanShader_params.skyMap.value = new Texture3D( KnownEmbeddedResources.Default[ "assets/Flare3DWaterShips/highlights.png" ].ToBitmapAsset(), false, Texture3D.FORMAT_CUBEMAP); oceanShader_params.normalMap.value = new Texture3D( KnownEmbeddedResources.Default["assets/Flare3DWaterShips/normalmap.jpg"].ToBitmapAsset()); oceanShader_params.mirrorMap.value = mirror; #endregion // http://www.flare3d.com/support/index.php?topic=142.0 var water = new Plane("water", 3000, 3000, oceanGridSize - 1, oceanShader, "+xz"); var skybox = new SkyBox( KnownEmbeddedResources.Default["assets/Flare3DWaterShips/skybox.png"].ToBitmapAsset(), SkyBox.HORIZONTAL_CROSS, null, 1); // http://www.flare3d.com/support/index.php?topic=63.0 // http://www.flare3d.com/docs/tutorials/loadFromBytes/ var ship0 = new Flare3DWaterShipComponent.ship(); // how to make it safe to provide 3rd party assetslibrary builder // code templates? which can be selected by KnownEmbeddedResources pattern match? // class XFileTemplate<T> where T like foo "*.zf3d" var ship1 = new Flare3DWaterShipComponent.ship(); ship1.x = 40; ship1.y = 10; var particles = new particles(); #region initWaves(): var bytes = new ByteArray(); bytes.endian = Endian.LITTLE_ENDIAN; bytes.length = oceanGridSize * oceanGridSize * 12; // 4 btyes * RGB = 12. // http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/ShaderData.html // public static class ShaderData // { // public ShaderData(ByteArray byteCode); // } var PBWater = KnownEmbeddedResources.Default["assets/Flare3DWaterShips/water.pbj"]; var shader = new Shader(PBWater.ToByteArrayAsset()); var shader_data = shader.data as dynamic; shader_data.src.input = bmp; var surf = new Surface3D("data"); // http://www.flare3d.com/docs/flare/core/Surface3D.html // public override int addVertexData(uint dataIndex, int size = -1, Vector<double> vector = null); surf.addVertexData(dataIndex: (uint)Surface3D.COLOR0, size: 3); surf.vertexBytes = bytes; surf.upload(scene); water.surfaces[0].sources[Surface3D.COLOR0] = surf; #endregion ship0.addChild(particles); scene.addChild(skybox); scene.addChild(water); scene.addChild(ship0); scene.addChild(ship1); var st = new Stopwatch(); st.Start(); ship1.setScale(2, 2, 2); scene.addEventListener(Scene3D.RENDER_EVENT, listener: new Action<Event>( delegate { // render the big waves. #region renderWaves() { var timer = st.ElapsedMilliseconds; point0.y = timer / 400; point1.y = timer / 640; // flash natives: apply params? bmp.perlinNoise(3, 3, 2, 0, false, true, 7, true, new[] { point0, point1 }); var job = new ShaderJob(shader, bytes, oceanGridSize, oceanGridSize); //job.addEventListener( ShaderEvent.COMPLETE, shaderCompleteEvent, false, 0, true ); job.complete += delegate { if (surf.vertexBuffer != null) surf.vertexBuffer.uploadFromByteArray(bytes, 0, 0, oceanGridSize * oceanGridSize); }; job.start(); } #endregion // copy from the main camera and invert in Y axis. mirrorCam.copyTransformFrom(scene.camera); mirrorCam.transform.appendScale(1, -1, 1); // setup the mirror cam to start rendering on the mirror texture. scene.setupFrame(mirrorCam); scene.context.setRenderToTexture(mirror.texture, true); scene.context.clear(0, 0, 0, 0); // get the pixel color height. var color = bmp.getPixel(oceanGridSize / 2, oceanGridSize / 2) & 0xff; // ! .0 marks it as double. otherwise ship will digitally step on water var height = color / 255.0 * 20 + 1; // draw objects into the mirror texture. ship0.y = -height; ship0.draw(); ship0.y = height; ship1.z = st.ElapsedMilliseconds * 0.001 - 100; ship1.y = -height; ship1.draw(); ship1.y = height; // get back to the main render. scene.context.setRenderToBackBuffer(); scene.setupFrame(scene.camera); } ).ToFunction() ); // http://www.flare3d.com/support/index.php?topic=1101.0 this.addChild(new net.hires.debug.Stats()); }
/// <summary> /// Initialize stereoscopic camera controller /// </summary> protected override void Initialize() { base.Initialize(); this.headTrack = WaveServices.GetService<HeadTrackSensor>(); this.leftLookAtEntity = this.Owner.FindChild("leftLookAt"); this.rightLookAtEntity = this.Owner.FindChild("rightLookAt"); this.leftEyeEntity = this.Owner.FindChild("leftEye"); this.rightEyeEntity = this.Owner.FindChild("rightEye"); this.leftEye = this.leftEyeEntity.FindComponent<Camera3D>(); this.rightEye = this.rightEyeEntity.FindComponent<Camera3D>(); this.leftLookAtTransform = this.leftLookAtEntity.FindComponent<Transform3D>(); this.rightLookAtTransform = this.rightLookAtEntity.FindComponent<Transform3D>(); this.leftEyeTransform = this.leftEyeEntity.FindComponent<Transform3D>(); this.rightEyeTransform = this.rightEyeEntity.FindComponent<Transform3D>(); // Left eye this.leftEye.Viewport = new Viewport(0, 0, 0.5f, 1); this.leftEye.FieldOfView = this.FieldOfView; this.leftEye.NearPlane = this.NearPlane; this.leftEye.FarPlane = this.FarPlane; // Right eye this.rightEye.Viewport = new Viewport(0.5f, 0, 0.5f, 1); this.rightEye.FieldOfView = this.FieldOfView; this.rightEye.NearPlane = this.NearPlane; this.rightEye.FarPlane = this.FarPlane; this.isInitialized = true; this.RefreshCameraCalibration(); }