public static void AddPhysicsInformations(CCamera cam) { foreach (CModel model in modelsList) { model.AddTrianglesToPhysics(cam); } }
public static void PreDraw(CCamera camera, GameTime gameTime) { foreach (CWater water in listWater) { water.PreDraw(camera, gameTime); } }
public static void LoadXMLTrees(CCamera cam, ContentManager content, List <Game.LevelInfo.MapModels_Tree> trees) { foreach (Game.LevelInfo.MapModels_Tree tree in trees) { AddTree(cam, content, tree); } }
public CWater(ContentManager content, GraphicsDevice graphics, Vector3 position, Vector3 deepestPoint, Vector2 size, float alpha) { this.content = content; this.graphics = graphics; this._waterPosition = position; this._waterSize = size; this._waterDeepestPoint = deepestPoint; waterMesh = new CModel(content.Load <Model>("3D/plane"), position, Vector3.Zero, new Vector3(size.X, 1, size.Y), graphics); waterEffect = content.Load <Effect>("Effects/WaterEffect"); waterMesh.SetModelEffect(waterEffect, false); waterEffect.Parameters["viewportWidth"].SetValue(graphics.Viewport.Width); waterEffect.Parameters["viewportHeight"].SetValue(graphics.Viewport.Height); waterEffect.Parameters["WaterNormalMap"].SetValue(content.Load <Texture2D>("Textures/water_normal")); this.WaterAlpha = alpha; reflectionTarg = new RenderTarget2D(graphics, graphics.Viewport.Width, graphics.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.Depth24); reflectionCamera = new CCamera(graphics, Vector3.Zero, Vector3.Zero, 0.1f, 10000.0f, true); pickWorld = Matrix.CreateTranslation(Vector3.Zero); GenerateBoundingBoxes(); }
/// <summary> /// Pre-draw the water effect: gets the reflection image /// </summary> /// <param name="camera">The camera class</param> /// <param name="gameTime">GameTime snapshot</param> public void PreDraw(CCamera camera, GameTime gameTime) { isInView = camera.BoundingVolumeIsInView(RealBoundingBox); if (isInView) { renderReflection(camera, gameTime); waterEffect.Parameters["Time"].SetValue((float)gameTime.TotalGameTime.TotalSeconds); } }
public static void AddTree(CCamera cam, ContentManager content, Game.LevelInfo.MapModels_Tree tree) { if (!_tProfiles.ContainsKey(tree.Profile)) { _tProfiles.Add(tree.Profile, content.Load <TreeProfile>(tree.Profile)); } _tTrees.Add(new Tree(cam, tree.Profile, tree.Position.Vector3, tree.Rotation.Vector3, tree.Scale.Vector3, tree.Seed, tree.Wind, tree.Branches)); }
/// <summary> /// Generates collision box from the base trunk /// </summary> public void GenerateCollisions(CCamera cam) { if (_totalTriangles != null && _totalTriangles.Count > 0) { // Unload every triangles from physics cam._physicsMap._triangleList.RemoveAll(tri => _totalTriangles.Contains(tri)); } _totalTriangles = new List <Triangle>(); _boundingBoxes = new List <BoundingBox>(); Matrix[] transforms = new Matrix[_tree.Skeleton.Bones.Count]; _tree.Skeleton.CopyAbsoluteBoneTranformsTo(transforms, _tree.AnimationState.BoneRotations); for (int x1 = 0; x1 < _tree.Skeleton.Bones.Count - 1; x1++) { BoundingSphere b1 = new BoundingSphere(transforms[x1].Translation + transforms[x1].Up * _tree.Skeleton.Bones[x1].Length, _tree.Skeleton.Branches[x1].StartRadius).Transform(_worldMatrix); BoundingSphere b2 = new BoundingSphere(transforms[x1 + 1].Translation + transforms[x1 + 1].Up * _tree.Skeleton.Bones[x1 + 1].Length, _tree.Skeleton.Branches[x1 + 1].StartRadius).Transform(_worldMatrix); BoundingBox CollisionBox = BoundingBox.CreateMerged(BoundingBox.CreateFromSphere(b1), BoundingBox.CreateFromSphere(b2)); _boundingBoxes.Add(CollisionBox); if (x1 == 0) { Vector3[] bbox = CollisionBox.GetCorners(); List <Triangle> triangleList = new List <Triangle>(); List <Vector3> triangleNormal = new List <Vector3>(); int[,] trianglesPos = { { 0, 1, 2 }, { 0, 3, 2 }, { 4, 0, 3 }, { 4, 7, 3 }, { 4, 7, 6 }, { 4, 5, 6 }, { 5, 6, 2 }, { 5, 1, 2 }, { 4, 0, 1 }, { 4, 5, 1 }, { 7, 3, 2 }, { 7, 6, 2 }, }; for (int i = 0; i < 12; i++) { Triangle tri = new Triangle(bbox[trianglesPos[i, 0]], bbox[trianglesPos[i, 1]], bbox[trianglesPos[i, 2]]); triangleList.Add(tri); // Compute normal Vector3 Normal = Vector3.Cross(tri.V0 - tri.V1, tri.V0 - tri.V2); Normal.Normalize(); triangleNormal.Add(Normal); } cam._physicsMap._triangleList.AddRange(triangleList); cam._physicsMap._triangleNormalsList.AddRange(triangleNormal); _totalTriangles.AddRange(triangleList); } } }
public static void Draw(CCamera cam, GameTime gameTime) { for (int i = 0; i < _pickups.Count; i++) { _pickups[i].Draw(cam, gameTime); if (selectedPickupId == i) { CSimpleShapes.AddBoundingSphere(_pickups[i]._Model.BoundingSphere, Color.Black); } } }
public void Draw(CCamera cam, GameTime gameTime) { if (shouldDrawPos && cam.BoundingVolumeIsInView(posGizmo.BoundingSphere)) { posGizmo._modelScale = Vector3.Distance(cam._cameraPos, posGizmo._modelPosition) * gizmoSize; posGizmo.Draw(cam._view, cam._projection, cam._cameraPos); } else if (shouldDrawRot && cam.BoundingVolumeIsInView(rotGizmo.BoundingSphere)) { rotGizmo._modelScale = Vector3.Distance(cam._cameraPos, rotGizmo._modelPosition) * gizmoSize; rotGizmo.Draw(cam._view, cam._projection, cam._cameraPos); } else if (shouldDrawScale && cam.BoundingVolumeIsInView(scaleGizmo.BoundingSphere)) { scaleGizmo._modelScale = Vector3.Distance(cam._cameraPos, rotGizmo._modelPosition) * gizmoSize; scaleGizmo.Draw(cam._view, cam._projection, cam._cameraPos); } }
/// <summary> /// Renders the reflection image /// </summary> /// <param name="camera">Camera class</param> /// <param name="gameTime">GameTime snapshot</param> public void renderReflection(CCamera camera, GameTime gameTime) { // Reflect the camera's properties across the water plane Vector3 reflectedCameraPosition = camera._cameraPos; reflectedCameraPosition.Y = -reflectedCameraPosition.Y + waterMesh._modelPosition.Y * 2; Vector3 reflectedCameraTarget = camera._cameraTarget; reflectedCameraTarget.Y = -reflectedCameraTarget.Y + waterMesh._modelPosition.Y * 2; // Create a temporary camera to render the reflected scene reflectionCamera._cameraPos = reflectedCameraPosition; reflectionCamera._cameraTarget = reflectedCameraTarget; reflectionCamera.Update(gameTime); // Set the reflection camera's view matrix to the water effect waterEffect.Parameters["ReflectedView"].SetValue(reflectionCamera._view); // Create the clip plane Vector4 clipPlane = new Vector4(0, 1, 0, -waterMesh._modelPosition.Y); // Set the render target graphics.SetRenderTarget(reflectionTarg); graphics.Clear(Color.Black); // Draw all objects with clip plane foreach (IRenderable renderable in Objects) { renderable.SetClipPlane(clipPlane); renderable.Draw(reflectionCamera._view, reflectionCamera._projection, reflectedCameraPosition); renderable.SetClipPlane(null); } graphics.SetRenderTarget(Display2D.C2DEffect.renderTarget); // Set the reflected scene to its effect parameter in // the water effect waterEffect.Parameters["ReflectionMap"].SetValue(reflectionTarg); }
public static void Draw(CCamera cam, GameTime gameTime) { for (int i = 0; i < _tTrees.Count; i++) { _tTrees[i]._tree.DrawTrunk(_tTrees[i]._worldMatrix, cam._view, cam._projection); if (selectedTreeId == i) { CSimpleShapes.AddBoundingSphere(_tTrees[i]._boundingSphere, Color.Black); } } // We draw leaves at the end for (int i = 0; i < _tTrees.Count; i++) { if (_tTrees[i]._useBranches) { _tTrees[i]._tree.DrawLeaves(_tTrees[i]._worldMatrix, cam._view, cam._projection); } } }
public static void DrawSelect(SpriteBatch spriteBatch, CCamera cam) { spriteBatch.Begin(); for (int i = 0; i < lights.Count; i++) { Vector3 Pos = Display2D.C2DEffect._graphicsDevice.Viewport.Project(lights[i].Position, cam._projection, cam._view, Matrix.Identity); if (Pos.Z < 1) { Color col = lights[i].Color; if (selectedLight != i) { col *= 0.2f; } spriteBatch.Draw(textureLight, new Vector2(Pos.X, Pos.Y), null, col, 0, Vector2.Zero, scaleTexture, SpriteEffects.None, 0); } } spriteBatch.End(); }
public static void Draw(CCamera cam, GameTime gameTime) { //renderer.ShadowLightPosition = CLightsManager.lights[0].Position; //renderer.ShadowLightTarget = new Vector3(renderer.ShadowLightTarget.X, renderer.ShadowLightTarget.Y - 0.1f, renderer.ShadowLightTarget.Z); foreach (CModel model in modelsList) { if (cam.BoundingVolumeIsInView(model.BoundingSphere)) { model.Draw(cam._view, cam._projection, cam._cameraPos); if (selectModelId != -1 && modelsList[selectModelId] == model) { CSimpleShapes.AddBoundingBox(modelsList[selectModelId]._boundingBox, Color.Black); } if (DebugActivated) { Matrix worldMatrix = model.GetModelMatrix(); foreach (Triangle tri in model._trianglesPositions) { Triangle realTri = tri.NewByMatrix(worldMatrix); CSimpleShapes.AddTriangle(realTri.V0, realTri.V1, realTri.V2, Color.Black); } } } } /*for (int i = 0; i < cam._physicsMap._triangleList.Count; i++) // Debug triangles collision * CSimpleShapes.AddTriangle(cam._physicsMap._triangleList[i].V0, cam._physicsMap._triangleList[i].V1, cam._physicsMap._triangleList[i].V2, Color.Blue); * for (int i = 0; i < cam._physicsMap._triangleNormalsList.Count; i++) // Debug triangles collision * CSimpleShapes.AddLine(cam._physicsMap._triangleNormalsList[i], cam._physicsMap._triangleNormalsList[i] * 2, Color.Red);*/ /*Matrix modelMatrix = modelsList[0].GetModelMatrix(); * for (int i = 0; i < modelsList[0]._trianglesPositions.Count; i++) * CSimpleShapes.AddTriangle(Vector3.Transform(modelsList[0]._trianglesPositions[i].V0, modelMatrix), * Vector3.Transform(modelsList[0]._trianglesPositions[i].V1, modelMatrix), * Vector3.Transform(modelsList[0]._trianglesPositions[i].V2, modelMatrix), Color.Red);*/ }
public static bool PointClicksLight(Vector2 pos, CCamera cam, out int clickedLight) { clickedLight = -1; for (int i = 0; i < lights.Count; i++) { Vector3 PosLight = Display2D.C2DEffect.softwareViewport.Project(lights[i].Position, cam._projection, cam._view, Matrix.Identity); if (PosLight.Z < 1) { if (pos.X >= PosLight.X && pos.X <= PosLight.X + textureLight.Width * scaleTexture) { if (pos.Y >= PosLight.Y && pos.Y <= PosLight.Y + textureLight.Height * scaleTexture) { clickedLight = i; return(true); } } } } return(false); }
private float rotateIntensity = 50; // The more the value is, the more sensitive it is public CGizmos(ContentManager Content, GraphicsDevice GraphicsDevice, CCamera cam) { Dictionary <string, Texture2D> guizmoTexture = new Dictionary <string, Texture2D>(); guizmoTexture.Add("R", Content.Load <Texture2D>("Textures/Guizmo")); posGizmo = new Display3D.CModel(Content.Load <Model>("Models/Guizmo"), Vector3.Zero, new Vector3(-MathHelper.PiOver2, MathHelper.PiOver2, 0), Vector3.One, GraphicsDevice, guizmoTexture, 0, 1); posGizmo.AddTrianglesToPhysics(cam, false); Dictionary <string, Texture2D> guizmoTexture2 = new Dictionary <string, Texture2D>(); guizmoTexture2.Add("R", Content.Load <Texture2D>("Textures/RotationGuizmo")); rotGizmo = new Display3D.CModel(Content.Load <Model>("Models/RotationGuizmo"), Vector3.Zero, Vector3.Zero, Vector3.One, GraphicsDevice, guizmoTexture2, 0, 1); rotGizmo.AddTrianglesToPhysics(cam, false); Dictionary <string, Texture2D> guizmoTexture3 = new Dictionary <string, Texture2D>(); guizmoTexture3.Add("R", Content.Load <Texture2D>("Textures/ScalingGuizmo")); scaleGizmo = new Display3D.CModel(Content.Load <Model>("Models/ScalingGuizmo"), Vector3.Zero, new Vector3(-MathHelper.PiOver2, MathHelper.PiOver2, 0), Vector3.One, GraphicsDevice, guizmoTexture3, 0, 1); scaleGizmo.AddTrianglesToPhysics(cam, false); GenerateBoundingBoxes(); gizmoSize = new Vector3(0.12f); }
public Tree(CCamera cam, string profile, Vector3 coordinates, Vector3 rotation, Vector3 scale, int seed = 0, bool wind = false, bool branches = true) { _profile = profile; _seed = seed; _position = coordinates; _rotation = rotation; _scale = scale; _useWind = wind; _useBranches = branches; _camera = cam; if (seed == 0) { GenerateTree(); } else { GenerateTree(seed); } GenerateWorldMatrix(); _boundingSphere = _tree.TrunkMesh.BoundingSphere.Transform(_worldMatrix); }
public void AddTrianglesToPhysics(CCamera cam, bool haveCollisionInfos = true) { _camera = cam; AddTrianglesToPhysics(haveCollisionInfos); }
public void Draw(CCamera cam, GameTime gameTime) { _Model.Draw(cam._view, cam._projection, cam._cameraPos); }
public void Drag(int posX, int posY, CCamera cam) { Vector3 gizmoPosition = posGizmo._modelPosition; if (shouldDrawRot) { gizmoPosition = rotGizmo._modelPosition; } else if (shouldDrawScale) { gizmoPosition = scaleGizmo._modelPosition; } Ray ray; float? distance = null; Plane axisPlane; Vector3 contactPoint = Vector3.Zero; if (shouldDrawPos || shouldDrawScale) { // We get the normal of the mouse Vector3 nearSourceCursor = Display2D.C2DEffect.softwareViewport.Unproject(new Vector3(posX, posY, Display2D.C2DEffect.softwareViewport.MinDepth), cam._projection, cam._view, Matrix.Identity); Vector3 farSourceCursor = Display2D.C2DEffect.softwareViewport.Unproject(new Vector3(posX, posY, Display2D.C2DEffect.softwareViewport.MaxDepth), cam._projection, cam._view, Matrix.Identity); Vector3 directionCursor = farSourceCursor - nearSourceCursor; directionCursor.Normalize(); // First, we create a plane for the axis we're dragging if (axisDragging == 0 || axisDragging == 1) // X/Z { axisPlane = new Plane(gizmoPosition + Vector3.UnitX, gizmoPosition, gizmoPosition + Vector3.UnitZ); } else { Matrix rotation = Matrix.CreateFromYawPitchRoll(cam._yaw, 0, 0); axisPlane = new Plane(gizmoPosition, gizmoPosition + Vector3.Up, gizmoPosition + Vector3.Transform(Vector3.Left, rotation)); } ray = new Ray(nearSourceCursor, directionCursor); distance = ray.Intersects(axisPlane); if (distance.HasValue) { contactPoint = ray.Position + ray.Direction * distance.Value; } } if (distance.HasValue || shouldDrawRot) { if (eltTypeDragging == "model") { if (shouldDrawPos) { Vector3 diff = contactPoint - initial3DPoint; if (axisDragging == 1) { CModelManager.modelsList[eltIdDragging]._modelPosition = new Vector3(initialPosValue.X + diff.X, CModelManager.modelsList[eltIdDragging]._modelPosition.Y, CModelManager.modelsList[eltIdDragging]._modelPosition.Z); } else if (axisDragging == 2) { CModelManager.modelsList[eltIdDragging]._modelPosition = new Vector3(CModelManager.modelsList[eltIdDragging]._modelPosition.X, initialPosValue.Y + diff.Y, CModelManager.modelsList[eltIdDragging]._modelPosition.Z); } else if (axisDragging == 0) { CModelManager.modelsList[eltIdDragging]._modelPosition = new Vector3(CModelManager.modelsList[eltIdDragging]._modelPosition.X, CModelManager.modelsList[eltIdDragging]._modelPosition.Y, initialPosValue.Z + diff.Z); } posGizmo._modelPosition = CModelManager.modelsList[eltIdDragging]._modelPosition; rotGizmo._modelPosition = CModelManager.modelsList[eltIdDragging]._modelPosition; scaleGizmo._modelPosition = CModelManager.modelsList[eltIdDragging]._modelPosition; } else if (shouldDrawRot) { Vector2 diff = new Vector2(posX, posY) - initialMousePos; if (axisDragging == 2) { CModelManager.modelsList[eltIdDragging]._modelRotation = new Vector3(initialRotValue.X + diff.X / 20, CModelManager.modelsList[eltIdDragging]._modelRotation.Y, CModelManager.modelsList[eltIdDragging]._modelRotation.Z); } else if (axisDragging == 0) { CModelManager.modelsList[eltIdDragging]._modelRotation = new Vector3(CModelManager.modelsList[eltIdDragging]._modelRotation.X, initialRotValue.Y + diff.X / rotateIntensity, CModelManager.modelsList[eltIdDragging]._modelRotation.Z); } else if (axisDragging == 1) { CModelManager.modelsList[eltIdDragging]._modelRotation = new Vector3(CModelManager.modelsList[eltIdDragging]._modelRotation.X, CModelManager.modelsList[eltIdDragging]._modelRotation.Y, initialRotValue.Z + diff.Y / rotateIntensity); } scaleGizmo._modelRotation = CModelManager.modelsList[eltIdDragging]._modelRotation; } else if (shouldDrawScale) { Vector3 diff = contactPoint - initial3DPoint; Vector3 uniDist = new Vector3(Math.Sign(diff.X) * diff.Length()) / 20; if (axisDragging == 1) { CModelManager.modelsList[eltIdDragging]._modelScale = new Vector3(initialScaleValue.X - diff.X, CModelManager.modelsList[eltIdDragging]._modelScale.Y, CModelManager.modelsList[eltIdDragging]._modelScale.Z); } else if (axisDragging == 2) { CModelManager.modelsList[eltIdDragging]._modelScale = new Vector3(CModelManager.modelsList[eltIdDragging]._modelScale.X, initialScaleValue.Y + diff.Y, CModelManager.modelsList[eltIdDragging]._modelScale.Z); } else if (axisDragging == 0) { CModelManager.modelsList[eltIdDragging]._modelScale = new Vector3(CModelManager.modelsList[eltIdDragging]._modelScale.X, CModelManager.modelsList[eltIdDragging]._modelScale.Y, initialScaleValue.Z - diff.Z); } else if (axisDragging == 3) // Uni { CModelManager.modelsList[eltIdDragging]._modelScale = new Vector3(initialScaleValue.X + uniDist.X, initialScaleValue.Y + uniDist.Y, initialScaleValue.Z + uniDist.Z); } } } else if (eltTypeDragging == "tree") { if (shouldDrawPos) { Vector3 diff = contactPoint - initial3DPoint; if (axisDragging == 1) { TreeManager._tTrees[eltIdDragging].Position = new Vector3(initialPosValue.X + diff.X, TreeManager._tTrees[eltIdDragging].Position.Y, TreeManager._tTrees[eltIdDragging].Position.Z); } else if (axisDragging == 2) { TreeManager._tTrees[eltIdDragging].Position = new Vector3(TreeManager._tTrees[eltIdDragging].Position.X, initialPosValue.Y + diff.Y, TreeManager._tTrees[eltIdDragging].Position.Z); } else if (axisDragging == 0) { TreeManager._tTrees[eltIdDragging].Position = new Vector3(TreeManager._tTrees[eltIdDragging].Position.X, TreeManager._tTrees[eltIdDragging].Position.Y, initialPosValue.Z + diff.Z); } posGizmo._modelPosition = TreeManager._tTrees[eltIdDragging].Position; rotGizmo._modelPosition = TreeManager._tTrees[eltIdDragging].Position; scaleGizmo._modelPosition = TreeManager._tTrees[eltIdDragging].Position; } else if (shouldDrawRot) { Vector2 diff = new Vector2(posX, posY) - initialMousePos; if (axisDragging == 2) { TreeManager._tTrees[eltIdDragging].Rotation = new Vector3(initialRotValue.X + diff.X / rotateIntensity, TreeManager._tTrees[eltIdDragging].Rotation.Y, TreeManager._tTrees[eltIdDragging].Rotation.Z); } else if (axisDragging == 0) { TreeManager._tTrees[eltIdDragging].Rotation = new Vector3(TreeManager._tTrees[eltIdDragging].Rotation.X, initialRotValue.Y + diff.X / rotateIntensity, TreeManager._tTrees[eltIdDragging].Rotation.Z); } else if (axisDragging == 1) { TreeManager._tTrees[eltIdDragging].Rotation = new Vector3(TreeManager._tTrees[eltIdDragging].Rotation.X, TreeManager._tTrees[eltIdDragging].Rotation.Y, initialRotValue.Z + diff.Y / rotateIntensity); } } else if (shouldDrawScale) { Vector3 diff = contactPoint - initial3DPoint; Vector3 uniDist = new Vector3(Math.Sign(diff.X) * diff.Length()) / 20; if (axisDragging == 1) { TreeManager._tTrees[eltIdDragging].Scale = new Vector3(initialScaleValue.X - diff.X, TreeManager._tTrees[eltIdDragging].Scale.Y, TreeManager._tTrees[eltIdDragging].Scale.Z); } else if (axisDragging == 2) { TreeManager._tTrees[eltIdDragging].Scale = new Vector3(TreeManager._tTrees[eltIdDragging].Scale.X, initialScaleValue.Y + diff.Y, TreeManager._tTrees[eltIdDragging].Scale.Z); } else if (axisDragging == 0) { TreeManager._tTrees[eltIdDragging].Scale = new Vector3(TreeManager._tTrees[eltIdDragging].Scale.X, TreeManager._tTrees[eltIdDragging].Scale.Y, initialScaleValue.Z - diff.Z); } else if (axisDragging == 3) // Uni { CModelManager.modelsList[eltIdDragging]._modelScale = new Vector3(initialScaleValue.X + uniDist.X, initialScaleValue.Y + uniDist.Y, initialScaleValue.Z + uniDist.Z); } } } else if (eltTypeDragging == "pickup") { if (shouldDrawPos) { Vector3 diff = contactPoint - initial3DPoint; Vector3 oldPos = CPickUpManager._pickups[eltIdDragging]._Model._modelPosition; if (axisDragging == 1) { CPickUpManager._pickups[eltIdDragging]._Model._modelPosition = new Vector3(initialPosValue.X + diff.X, oldPos.Y, oldPos.Z); } else if (axisDragging == 2) { CPickUpManager._pickups[eltIdDragging]._Model._modelPosition = new Vector3(oldPos.X, initialPosValue.Y + diff.Y, oldPos.Z); } else if (axisDragging == 0) { CPickUpManager._pickups[eltIdDragging]._Model._modelPosition = new Vector3(oldPos.X, oldPos.Y, initialPosValue.Z + diff.Z); } posGizmo._modelPosition = CPickUpManager._pickups[eltIdDragging]._Model._modelPosition; rotGizmo._modelPosition = CPickUpManager._pickups[eltIdDragging]._Model._modelPosition; scaleGizmo._modelPosition = CPickUpManager._pickups[eltIdDragging]._Model._modelPosition; } else if (shouldDrawRot) { Vector3 oldPos = CPickUpManager._pickups[eltIdDragging]._Model._modelRotation; Vector2 diff = new Vector2(posX, posY) - initialMousePos; if (axisDragging == 2) { CPickUpManager._pickups[eltIdDragging]._Model._modelRotation = new Vector3(initialRotValue.X + diff.X / rotateIntensity, oldPos.Y, oldPos.Z); } else if (axisDragging == 0) { CPickUpManager._pickups[eltIdDragging]._Model._modelRotation = new Vector3(oldPos.X, initialRotValue.Y + diff.X / rotateIntensity, oldPos.Z); } else if (axisDragging == 1) { CPickUpManager._pickups[eltIdDragging]._Model._modelRotation = new Vector3(oldPos.X, oldPos.Y, initialRotValue.Z + diff.Y / rotateIntensity); } } else if (shouldDrawScale) { Vector3 diff = contactPoint - initial3DPoint; Vector3 oldPos = CPickUpManager._pickups[eltIdDragging]._Model._modelScale; Vector3 uniDist = new Vector3(Math.Sign(diff.X) * diff.Length()) / 20; if (axisDragging == 1) { CPickUpManager._pickups[eltIdDragging]._Model._modelScale = new Vector3(initialScaleValue.X - diff.X, oldPos.Y, oldPos.Z); } else if (axisDragging == 2) { CPickUpManager._pickups[eltIdDragging]._Model._modelScale = new Vector3(oldPos.X, initialScaleValue.Y + diff.Y, oldPos.Z); } else if (axisDragging == 0) { CPickUpManager._pickups[eltIdDragging]._Model._modelScale = new Vector3(oldPos.X, oldPos.Y, initialScaleValue.Z - diff.Z); } else if (axisDragging == 3) // Uni { CModelManager.modelsList[eltIdDragging]._modelScale = new Vector3(initialScaleValue.X + uniDist.X, initialScaleValue.Y + uniDist.Y, initialScaleValue.Z + uniDist.Z); } } } else if (eltTypeDragging == "water") { if (shouldDrawPos) { Vector3 diff = contactPoint - initial3DPoint; Vector3 oldPos = CWaterManager.listWater[eltIdDragging].waterPosition; if (axisDragging == 1) { CWaterManager.listWater[eltIdDragging].waterPosition = new Vector3(initialPosValue.X + diff.X, oldPos.Y, oldPos.Z); } else if (axisDragging == 2) { CWaterManager.listWater[eltIdDragging].waterPosition = new Vector3(oldPos.X, initialPosValue.Y + diff.Y, oldPos.Z); } else if (axisDragging == 0) { CWaterManager.listWater[eltIdDragging].waterPosition = new Vector3(oldPos.X, oldPos.Y, initialPosValue.Z + diff.Z); } posGizmo._modelPosition = CWaterManager.listWater[eltIdDragging].waterPosition; rotGizmo._modelPosition = CWaterManager.listWater[eltIdDragging].waterPosition; scaleGizmo._modelPosition = CWaterManager.listWater[eltIdDragging].waterPosition; } else if (shouldDrawScale) { Vector3 diff = contactPoint - initial3DPoint; Vector2 oldPos = CWaterManager.listWater[eltIdDragging].waterSize; Vector3 uniDist = new Vector3(Math.Sign(diff.X) * diff.Length()) / 20; if (axisDragging == 1) { CWaterManager.listWater[eltIdDragging].waterSize = new Vector2(initialScaleValue.X - diff.X, oldPos.Y); } else if (axisDragging == 0) { CWaterManager.listWater[eltIdDragging].waterSize = new Vector2(oldPos.X, initialScaleValue.Z - diff.Z); } else if (axisDragging == 3) // Uni { CModelManager.modelsList[eltIdDragging]._modelScale = new Vector3(initialScaleValue.X + uniDist.X, initialScaleValue.Y + uniDist.Y, initialScaleValue.Z + uniDist.Z); } } } else if (eltTypeDragging == "light") { if (shouldDrawPos) { Vector3 diff = contactPoint - initial3DPoint; Vector3 oldPos = CLightsManager.lights[eltIdDragging].Position; if (axisDragging == 1) { CLightsManager.lights[eltIdDragging].Position = new Vector3(initialPosValue.X + diff.X, oldPos.Y, oldPos.Z); } else if (axisDragging == 2) { CLightsManager.lights[eltIdDragging].Position = new Vector3(oldPos.X, initialPosValue.Y + diff.Y, oldPos.Z); } else if (axisDragging == 0) { CLightsManager.lights[eltIdDragging].Position = new Vector3(oldPos.X, oldPos.Y, initialPosValue.Z + diff.Z); } posGizmo._modelPosition = CLightsManager.lights[eltIdDragging].Position; rotGizmo._modelPosition = CLightsManager.lights[eltIdDragging].Position; scaleGizmo._modelPosition = CLightsManager.lights[eltIdDragging].Position; } } else if (eltTypeDragging == "bot") { if (shouldDrawPos) { Vector3 diff = contactPoint - initial3DPoint; if (axisDragging == 1) { Game.CEnemyManager._enemyList[eltIdDragging]._position = new Vector3(initialPosValue.X + diff.X, Game.CEnemyManager._enemyList[eltIdDragging]._position.Y, Game.CEnemyManager._enemyList[eltIdDragging]._position.Z); } else if (axisDragging == 2) { Game.CEnemyManager._enemyList[eltIdDragging]._position = new Vector3(Game.CEnemyManager._enemyList[eltIdDragging]._position.X, initialPosValue.Y + diff.Y, Game.CEnemyManager._enemyList[eltIdDragging]._position.Z); } else if (axisDragging == 0) { Game.CEnemyManager._enemyList[eltIdDragging]._position = new Vector3(Game.CEnemyManager._enemyList[eltIdDragging]._position.X, Game.CEnemyManager._enemyList[eltIdDragging]._position.Y, initialPosValue.Z + diff.Z); } posGizmo._modelPosition = Game.CEnemyManager._enemyList[eltIdDragging]._position; rotGizmo._modelPosition = Game.CEnemyManager._enemyList[eltIdDragging]._position; scaleGizmo._modelPosition = Game.CEnemyManager._enemyList[eltIdDragging]._position; } else if (shouldDrawRot) { Vector3 newRot = Vector3.Zero; Vector2 diff = new Vector2(posX, posY) - initialMousePos; /*float Yaw, Pitch, Roll; * RotationMatrixToYawPitchRoll(ref Game.CEnemyManager._enemyList[eltIdDragging]._rotation, out Yaw, out Pitch, out Roll);*/ //if (axisDragging == 2) //newRot = new Vector3(initialRotValue.X + diff.X / 20, Pitch, Roll); Game.CEnemyManager._enemyList[eltIdDragging].rotationValue = initialRotValue.X + diff.X / 20; /*else if (axisDragging == 0) * newRot = new Vector3(Yaw, initialRotValue.Y + diff.X / rotateIntensity, Roll); * else if (axisDragging == 1) * newRot = new Vector3(Yaw, Pitch, initialRotValue.Z + diff.Y / rotateIntensity);*/ //Game.CEnemyManager._enemyList[eltIdDragging]._rotation = Matrix.CreateFromYawPitchRoll(newRot.X, newRot.Y, newRot.Z); //scaleGizmo._modelRotation = CModelManager.modelsList[eltIdDragging]._modelRotation; } else if (shouldDrawScale) { Vector3 diff = contactPoint - initial3DPoint; Vector3 uniDist = new Vector3(Math.Sign(diff.X) * diff.Length()) / 20; if (axisDragging == 1) { Game.CEnemyManager._enemyList[eltIdDragging]._scale = new Vector3(initialScaleValue.X - diff.X); } else if (axisDragging == 2) { Game.CEnemyManager._enemyList[eltIdDragging]._scale = new Vector3(initialScaleValue.Y + diff.Y); } else if (axisDragging == 0) { Game.CEnemyManager._enemyList[eltIdDragging]._scale = new Vector3(initialScaleValue.Z - diff.Z); } else if (axisDragging == 3) // Uni { Game.CEnemyManager._enemyList[eltIdDragging]._scale = new Vector3(initialScaleValue.X + uniDist.X); } Game.CEnemyManager._enemyList[eltIdDragging]._model._scale = Game.CEnemyManager._enemyList[eltIdDragging]._scale.X; } } else if (eltTypeDragging == "spawnpoint") { if (shouldDrawPos) { Vector3 diff = contactPoint - initial3DPoint; Vector3 oldPos = CModelManager.SpawnPoint._modelPosition; if (axisDragging == 1) { CModelManager.SpawnPoint._modelPosition = new Vector3(initialPosValue.X + diff.X, oldPos.Y, oldPos.Z); } else if (axisDragging == 2) { CModelManager.SpawnPoint._modelPosition = new Vector3(oldPos.X, initialPosValue.Y + diff.Y, oldPos.Z); } else if (axisDragging == 0) { CModelManager.SpawnPoint._modelPosition = new Vector3(oldPos.X, oldPos.Y, initialPosValue.Z + diff.Z); } posGizmo._modelPosition = CModelManager.SpawnPoint._modelPosition; } } } }
public void StartDrag(int axis, string eltType, int eltId, System.Windows.Point mousePos, CCamera cam) { axisDragging = axis; eltTypeDragging = eltType; eltIdDragging = eltId; posGizmo.shouldNotUpdateTriangles = true; rotGizmo.shouldNotUpdateTriangles = true; scaleGizmo.shouldNotUpdateTriangles = true; initialMousePos = new Vector2((float)mousePos.X, (float)mousePos.Y); Vector3 nearSourceCursor = Display2D.C2DEffect.softwareViewport.Unproject(new Vector3(initialMousePos.X, initialMousePos.Y, Display2D.C2DEffect.softwareViewport.MinDepth), cam._projection, cam._view, Matrix.Identity); Vector3 farSourceCursor = Display2D.C2DEffect.softwareViewport.Unproject(new Vector3(initialMousePos.X, initialMousePos.Y, Display2D.C2DEffect.softwareViewport.MaxDepth), cam._projection, cam._view, Matrix.Identity); Vector3 directionCursor = farSourceCursor - nearSourceCursor; directionCursor.Normalize(); Plane axisPlane; if (axisDragging == 0 || axisDragging == 1) // X/Z { axisPlane = new Plane(posGizmo._modelPosition + Vector3.UnitX, posGizmo._modelPosition, posGizmo._modelPosition + Vector3.UnitZ); } else { Matrix rotation = Matrix.CreateFromYawPitchRoll(cam._yaw, 0, 0); axisPlane = new Plane(posGizmo._modelPosition, posGizmo._modelPosition + Vector3.Up, posGizmo._modelPosition + Vector3.Transform(Vector3.Left, rotation)); } Ray initialRay = new Ray(nearSourceCursor, directionCursor); float?distance = initialRay.Intersects(axisPlane); if (distance.HasValue) { initial3DPoint = initialRay.Position + initialRay.Direction * distance.Value; } if (eltType == "model") { initialPosValue = CModelManager.modelsList[eltIdDragging]._modelPosition; initialRotValue = CModelManager.modelsList[eltIdDragging]._modelRotation; initialScaleValue = CModelManager.modelsList[eltIdDragging]._modelScale; } else if (eltType == "tree") { initialPosValue = TreeManager._tTrees[eltIdDragging].Position; initialRotValue = TreeManager._tTrees[eltIdDragging].Rotation; initialScaleValue = TreeManager._tTrees[eltIdDragging].Scale; } else if (eltType == "pickup") { initialPosValue = CPickUpManager._pickups[eltIdDragging]._Model._modelPosition; initialRotValue = CPickUpManager._pickups[eltIdDragging]._Model._modelRotation; initialScaleValue = CPickUpManager._pickups[eltIdDragging]._Model._modelScale; } else if (eltType == "water") { initialPosValue = CWaterManager.listWater[eltIdDragging].waterPosition; initialRotValue = Vector3.Zero; initialScaleValue = new Vector3(CWaterManager.listWater[eltIdDragging].waterSize.X, 1, CWaterManager.listWater[eltIdDragging].waterSize.Y); } else if (eltType == "light") { initialPosValue = CLightsManager.lights[eltIdDragging].Position; initialRotValue = Vector3.Zero; initialScaleValue = Vector3.Zero; } else if (eltType == "bot") { initialPosValue = Game.CEnemyManager._enemyList[eltIdDragging]._position; initialRotValue = new Vector3(Game.CEnemyManager._enemyList[eltIdDragging].rotationValue, 0, 0); initialScaleValue = Game.CEnemyManager._enemyList[eltIdDragging]._scale; } else if (eltType == "spawnpoint") { initialPosValue = Display3D.CModelManager.SpawnPoint._modelPosition; } }