public override void _Process(float delta) { if ((int)root.rpm != 0) { var curve = new Curve3D(); curve.UpVectorEnabled = true; for (int i = 0; i < 15; i += 5) { curve.AddPoint(new Vector3(Translation.x, root.height.GetNoise2d(Translation.x, Translation.z - i) * 20, Translation.z - i)); } var offset = ((root.rpm * (float)Math.PI * 2.0f) / 60.0f) * 0.60f * delta; Translation = curve.InterpolateBaked(offset); LookAt(Translation + curve.InterpolateBakedUpVector(offset).Rotated(Vector3.Right, -(float)Math.PI / 2), Vector3.Up); } else if (Input.IsKeyPressed((int)KeyList.Z)) { var curve = new Curve3D(); curve.UpVectorEnabled = true; for (int i = 0; i < 15; i += 5) { curve.AddPoint(new Vector3(Translation.x, root.height.GetNoise2d(Translation.x, Translation.z - i) * 20, Translation.z - i)); } Translation = curve.InterpolateBaked(32 * delta); LookAt(Translation + curve.InterpolateBakedUpVector(16 * delta).Rotated(Vector3.Right, -(float)Math.PI / 2), Vector3.Up); } }
public override string GetHandleName(int index) { Curve3D c = path.curve; if (!IsInstanceValid(c)) { GD.Print("Invalid Curve"); return(""); } if (index < c.GetPointCount()) { return(("Curve Point #") + index); } index = index - c.GetPointCount() + 1; int idx = index / 2; int t = index % 2; String n = ("Curve Point #") + idx; if (t == 0) { n += " In"; } else { n += " Out"; } return(n); }
void OnEnable() { _Path = serializedObject.targetObject as Curve3D; if (_Path.Keys == null || _Path.Keys.Length < 2) { _Path.Keys = new Keyframe3D[] { new Keyframe3D(0, _Path.transform.position), new Keyframe3D(1.0f, _Path.transform.position + Vector3.forward) } } ; _PreSmoothAmount = _Path.SmoothAmount = Mathf.Max(2, _Path.SmoothAmount); _PreUseWorldSpace = _Path.UseWorldSpace; _Path.ShowPath = false; RebuildPath(); CreateUI(); ValidateGrid(); _BtnRemove.IsEnabled = _Path.Keys.Length > 2; _GridPoints.SelectedIndex = _Path.SelectedIndex; _SimulationStarted = false; _SimulationSpeed = 1.0f; _SimulationCurrectTime = 0; } void OnDisable() { _Path.ShowPath = true; }
public void TestFollowCurve() { XNAGame game = new XNAGame(); Curve3D curve = Curve3D.CreateTestCurve(); game.SpectaterCamera.CameraDirection = Vector3.Normalize(new Vector3(-0.2f, -1f, -0.4f)); BoundingSphere sphere = curve.CalculateBoundingSphere(); sphere.Radius += 1.5f; game.SpectaterCamera.FitInView(sphere); float time = 0; game.DrawEvent += delegate { if (game.Keyboard.IsKeyPressed(Keys.V)) { game.SpectaterCamera.CameraDirection = Vector3.Normalize(new Vector3(-0.2f, -1f, -0.4f)); } Render(curve, game, Color.Red); game.LineManager3D.AddCenteredBox(curve.Evaluate(time), 0.2f, Color.Green); time += game.Elapsed; }; game.Run(); }
public void BasicBalTest() { Emitter emit; DX11Game game = new DX11Game(); game.InitDirectX(); var texPool = new TexturePool(game); var testTexture = GetTestTexture(); BallParticleCreater creater = new BallParticleCreater(); //SimpleParticleCreater creater = new SimpleParticleCreater(); EmitterParameters param = new EmitterParameters(); param.texture = testTexture; param.particleCreater = creater; emit = new Emitter(texPool, game, param, 800, 600);//note: again screen size //game.Wpf.CreateClassForm(param); Seeder seed = new Seeder(54); var curve = Curve3D.CreateTestCurve(); emit.Initialize(); emit.InitializeRender(); emit.CreateRenderData(); emit.SetRenderData(); emit.SetPosition(Vector3.Zero); float dist = 0; game.GameLoopEvent += delegate { // emit.setShader(); emit.Update(); if (dist > 100) { dist = 0; } else { dist += game.Elapsed * 1; } //emit.SetPosition(new Vector3(dist, 0, 0)); Temp(dist, emit, curve); //Draw part //game.GraphicsDevice.Clear(Color.Black); game.Device.ImmediateContext.Rasterizer.State = game.HelperStates.RasterizerShowAll; emit.Render(game.SpectaterCamera.ViewProjection, game.SpectaterCamera.ViewInverse); }; game.Run(); }
public override string GetStepParameters() { var parameters = new List <string>(); parameters.Add(Curve3D != null ? Curve3D.ToStepValue() : "$"); parameters.Add(AssociatedGeometry != null ? AssociatedGeometry.ToStepValue() : "$"); parameters.Add(MasterRepresentation != null ? MasterRepresentation.ToStepValue() : "$"); return(string.Join(", ", parameters.ToArray())); }
public TentacleTester(Scene scene) { this.scene = scene; var mesh = ContentCache.GetMesh("Tentacle.obj"); var points = mesh.Points; var vertices = mesh.Vertices; ivec2[] boneIndexes = new ivec2[vertices.Length]; vec2[] boneWeights = new vec2[vertices.Length]; float halfRange = (points.Max(p => p.x) - points.Min(p => p.x)) / 2; float segmentLength = halfRange * 2 / (Bones - 1); // Compute bone indexes and weights. for (int i = 0; i < vertices.Length; i++) { float x = points[vertices[i].x].x; float weight = 1 - ((x + halfRange) % segmentLength) / segmentLength; // Each segment spans two bones. int index = (int)Math.Floor((x + halfRange) / segmentLength); boneIndexes[i] = new ivec2(index, Math.Min(index + 1, Bones - 1)); boneWeights[i] = new vec2(weight, 1 - weight); } mesh.BoneIndexes = boneIndexes; mesh.BoneWeights = boneWeights; curve = new Curve3D(); // Compute the default pose. vec3[] defaultPose = new vec3[Bones]; for (int i = 0; i < Bones; i++) { defaultPose[i] = new vec3(-halfRange + segmentLength * i, 0, 0); } // Initialize springs. vec3 target = scene.GetEntities(EntityGroups.Player)[0].Position; vec3[] springPoints = { new vec3(halfRange * 2, HoverHeight, 0), new vec3(halfRange, HoverHeight, 0), new vec3(target.x, HoverHeight, target.z) }; springs = springPoints.Select(p => new SpringPoint3D(p, 0.85f, 0.85f)).ToArray(); skeleton = new Skeleton(mesh, defaultPose); scene.Renderer.Add(skeleton); }
public void Refresh(Curve3D path, float duration) { Debug.Assert(path != null, "Given path was null."); // TODO: Assign timer trigger function. timer.Duration = duration; timer.Tick = t => { Recompute(path.Evaluate(t)); }; }
public override void _EnterTree() { if (!IsInstanceValid(curve)) { curve = new Curve3D(); } if (!curve.IsConnected("changed", this, "update_gizmo")) { curve.Connect("changed", this, "update_gizmo"); } }
public void FlameTest() { Emitter emit; DX11Game game = new DX11Game(); game.InitDirectX(); FlameParticleCreater creater; //game.DrawFps = true; //var pool = new VertexDeclarationPool(); //pool.SetVertexElements<Emitter.ParticleVertex>(Emitter.ParticleVertex.VertexElements); var texPool = new TexturePool(game); var testTexture = GetTestTexture(); creater = new FlameParticleCreater(); EmitterParameters param = new EmitterParameters(); param.EffectName = "calculateFlame"; param.texture = testTexture; param.particleCreater = creater; emit = new Emitter(texPool, game, param, 800, 600); Seeder seed = new Seeder(54); var curve = Curve3D.CreateTestCurve(); //texPool.Initialize(game); //pool.Initialize(game); emit.Initialize(); emit.InitializeRender(); emit.CreateRenderData(); emit.SetRenderData(); //emit.AddParticles(creater,1); float dist = 0; game.GameLoopEvent += delegate { dist += game.Elapsed; // emit.setShader(); //Temp(dist, emit, curve); //setColors(emit); emit.Update(); emit.Render(game.SpectaterCamera.ViewProjection, game.SpectaterCamera.ViewInverse); }; game.Run(); }
public void _CloseCurve() { Curve3D c = path.curve; if (!IsInstanceValid(c)) { return; } if (c.GetPointCount() < 2) { return; } c.AddPoint(c.GetPointPosition(0), c.GetPointIn(0), c.GetPointOut(0)); }
} // Draw3DCurve /// <summary> /// Draws a curve in screen space. /// </summary> public static void Draw2DCurve(Curve3D curve, Color color, Vector2 position, int step = 50) { if (!hasBegun || !begin2D || primitiveType != PrimitiveType.LineList) { throw new InvalidOperationException("Line Manager: you have to call Begin in 2D mode and with PrimitiveType.LineList selected."); } AddVertex(new Vector2(curve.GetPoint(0).X, curve.GetPoint(0).Y) + position, color); for (float i = curve.CurveTotalTime / step; i < curve.CurveTotalTime; i = i + (curve.CurveTotalTime / step)) { AddVertex(new Vector2(curve.GetPoint(i).X, curve.GetPoint(i).Y) + position, color); AddVertex(new Vector2(curve.GetPoint(i).X, curve.GetPoint(i).Y) + position, color); } AddVertex(new Vector2(curve.GetPoint(curve.CurveTotalTime).X, curve.GetPoint(curve.CurveTotalTime).Y) + position, color); } // Draw2DCurve
public static Curve3D CreateTestObject1MovementCurve() { Curve3D curve1 = new Curve3D(); curve1.PostLoop = CurveLoopType.Cycle; curve1.AddKey(0, new Vector3(20, 2, 20)); curve1.AddKey(1, new Vector3(-20, 2, 80)); curve1.AddKey(3, new Vector3(-3, 2, -10)); curve1.AddKey(4, new Vector3(-20, 2, -50)); curve1.AddKey(5, new Vector3(-50, 2, -50)); curve1.AddKey(6, new Vector3(38, 2, -47)); curve1.AddKey(7, new Vector3(20, 2, 20)); return(curve1); }
public void Initialise(WaveParams waveParams) { // Instantiate the wave segments, and set the initial wave rotation WaveSegments = new WaveSegment[waveParams.SegmentCount]; var waveWidth = WaveSegment.SEGMENT_WIDTH * waveParams.SegmentCount; var leftOrigin = new Vector3(-waveWidth / 2, 0, 0); var leftControlPointInOrigin = new Vector3(-0.2f, 0, 0).Rotated(new Vector3(0, 0, 1), waveParams.LeftControlRotationRad); var leftControlPointOutOrigin = new Vector3(0.2f, 0, 0).Rotated(new Vector3(0, 0, 1), waveParams.LeftControlRotationRad); var rightOrigin = new Vector3(waveWidth / 2, 0, 0); var rightControlPointInOrigin = new Vector3(0.2f, 0, 0).Rotated(new Vector3(0, 0, 1), waveParams.RightControlRotationRad); var rightControlPointOutOrigin = new Vector3(-0.2f, 0, 0).Rotated(new Vector3(0, 0, 1), waveParams.RightControlRotationRad); var curve = new Curve3D(); var gap = rightOrigin - leftOrigin; // control point locations are relative to the curve point origin (i.e not global coordinates) curve.AddPoint(leftOrigin, SetControlPoint(gap.Length(), leftControlPointInOrigin), SetControlPoint(gap.Length(), leftControlPointOutOrigin)); curve.AddPoint(rightOrigin, SetControlPoint(gap.Length(), rightControlPointInOrigin), SetControlPoint(gap.Length(), rightControlPointOutOrigin)); // instantiate wave segments var segmentFraction = (float)1 / waveParams.SegmentCount; for (var i = 0; i < waveParams.SegmentCount; i++) { var waveSegment = WaveSegmentScene.Instance() as WaveSegment; // xOffset moves from leftOrigin to rightOrigin in a number of steps equal to the segment count var xOffset = leftOrigin.x + (rightOrigin.x - leftOrigin.x) * (i * segmentFraction); var yOffset = curve.Interpolate(0, i * segmentFraction + (segmentFraction / 2)); waveSegment.Translation = new Vector3(xOffset, yOffset.y, 0); AddChild(waveSegment); WaveSegments[i] = waveSegment; } Rotation = new Vector3(0, 0, waveParams.InitialRotationRad); RotationRateRad = waveParams.RotationRateRad; }
public void Render(Curve3D curve, IXNAGame game, Color color) { float segmentLength = 0.1f; float start = curve.GetStart(); float end = curve.GetEnd(); Vector3 lastPoint = curve.Evaluate(start); for (float i = start + segmentLength; i < end; i += segmentLength) { Vector3 newPoint = curve.Evaluate(i); game.LineManager3D.AddLine(lastPoint, newPoint, color); lastPoint = newPoint; } game.LineManager3D.AddLine(lastPoint, curve.Evaluate(end), color); }
public override object GetHandleValue(int index) { Curve3D c = path.curve; if (!IsInstanceValid(c)) { GD.Print("Invalid curve"); return(null); } if (index < c.GetPointCount()) { original = c.GetPointPosition(index); return(original); } index = index - c.GetPointCount() + 1; int idx = index / 2; int t = index % 2; Vector3 ofs; if (t == 0) { ofs = c.GetPointIn(idx); } else { ofs = c.GetPointOut(idx); } original = ofs + c.GetPointPosition(idx); return(ofs); }
public void RefreshTransforms(float aSpeed) { if (aSpeed <= 0) { aSpeed = 1; } if (myPoints != null) { myCompleteDuration = 0; for (int i = 0; i < myCurves.Length; i++) { if (myCurves[i] == null) { myCurves[i] = new Curve3D(); } myCurves[i].Set(myPoints[i * 2].position, myPoints[i * 2 + 1].position, myPoints[i * 2 + 2].position); myPartDuration[i] = myCurves[i].myLenght / aSpeed; myCompleteDuration += myPartDuration[i]; } } }
public CurveSnapItem3D(Curve3D Curve) { this.Curve = Curve; }
public override void SetHandle(int index, Camera camera, Vector2 point) { Curve3D c = path.curve; if (!IsInstanceValid(c)) { GD.Print("Invalid curve"); return; } Transform gt = path.GlobalTransform; Transform gi = gt.AffineInverse(); Vector3 ray_from = camera.ProjectRayOrigin(point); Vector3 ray_dir = camera.ProjectRayNormal(point); // Setting curve point positions if (index < c.GetPointCount()) { var org = gt.Xform(original); Plane pp = new Plane(); pp.Normal = camera.Transform.basis.GetColumn(2); pp.D = pp.Normal.Dot(org); Vector3?_inters = pp.IntersectRay(ray_from, ray_dir); if (_inters != null) { Vector3 _nnInters = (Vector3)_inters; if (plugin.snapEnabled) { _nnInters = _nnInters.Snapped(new Vector3(plugin.snapLength, plugin.snapLength, plugin.snapLength)); } _nnInters = plugin.RestrictPoint(org, _nnInters); Vector3 local = gi.Xform(_nnInters); c.SetPointPosition(index, local); } return; } index = index - c.GetPointCount() + 1; int idx = index / 2; int t = index % 2; var porig = gt.Xform(original); Vector3 basePos = c.GetPointPosition(idx); Plane p = new Plane(); p.Normal = camera.Transform.basis.GetColumn(2); p.D = p.Normal.Dot(porig); Vector3?inters = p.IntersectRay(ray_from, ray_dir); // Setting curve in/out positions if (inters != null) { Vector3 nnInters = (Vector3)inters; if (!plugin.handleClicked) { origInLength = c.GetPointIn(idx).Length(); origOutLenght = c.GetPointOut(idx).Length(); plugin.SetHandleClicked(true); } Vector3 orig = gi.Xform(porig) - basePos; Vector3 local = gi.Xform(nnInters) - basePos; if (plugin.snapEnabled) { local = local.Snapped(new Vector3(plugin.snapLength, plugin.snapLength, plugin.snapLength)); } local = plugin.RestrictPoint(orig, local); if (t == 0) { c.SetPointIn(idx, local); if (plugin.mirrorHandleAngle) { c.SetPointOut(idx, plugin.mirrorHandleLength ? -local : (-local.Normalized() * origOutLenght)); } } else { c.SetPointOut(idx, local); if (plugin.mirrorHandleAngle) { c.SetPointIn(idx, plugin.mirrorHandleLength ? -local : (-local.Normalized() * origInLength)); } } } }
public CameraPathData() { heads = new Curve3D(); targets = new Curve3D(); ups = new Curve3D(); }
public override Curve Curve(double tol) { return(Curve3D.Curve(tol)); }
public override bool ForwardSpatialGuiInput(Camera camera, InputEvent @event) { if (!IsInstanceValid(path)) { return(false); } Curve3D c = path.curve; if (!IsInstanceValid(c)) { return(false); } Transform gt = path.GlobalTransform; Transform it = gt.AffineInverse(); if (@event is InputEventMouseButton mb) { Vector2 mbPos = mb.Position; if (!mb.Pressed) { SetHandleClicked(false); } if (mb.Pressed && mb.ButtonIndex == (int)ButtonList.Left && (curveCreate.Pressed || (curveEdit.Pressed && mb.Control))) { //click into curve, break it down Vector3[] v3a = c.Tessellate(); int idx = 0; int rc = v3a.Length; int closestSeg = -1; Vector3 closestSegPoint = new Vector3(); float closest_d = float.MaxValue; if (rc >= 2) { if (camera.UnprojectPosition(gt.Xform(c.GetPointPosition(0))).DistanceTo(mbPos) < clickDist) { return(false); //nope, existing } for (int i = 0; i < c.GetPointCount() - 1; i++) { //find the offset and point index of the place to break up int j = idx; if (camera.UnprojectPosition(gt.Xform(c.GetPointPosition(i + 1))).DistanceTo(mbPos) < clickDist) { return(false); //nope, existing } while (j < rc && c.GetPointPosition(i + 1) != v3a[j]) { Vector3 from = v3a[j]; Vector3 to = v3a[j + 1]; float cdist = from.DistanceTo(to); from = gt.Xform(from); to = gt.Xform(to); if (cdist > 0) { Vector2[] s = new Vector2[2]; s[0] = camera.UnprojectPosition(from); s[1] = camera.UnprojectPosition(to); Vector2 inters = GetClosestPointToSegment2D(mbPos, s); float d = inters.DistanceTo(mbPos); if (d < 10 && d < closest_d) { closest_d = d; closestSeg = i; Vector3 ray_from = camera.ProjectRayOrigin(mbPos); Vector3 ray_dir = camera.ProjectRayNormal(mbPos); Vector3 ra, rb; GetClosestPointsBetweenSegments(ray_from, ray_from + ray_dir * 4096, from, to, out ra, out rb); closestSegPoint = it.Xform(rb); } } j++; } if (idx == j) { idx++; //force next } else { idx = j; //swap } if (j == rc) { break; } } } var ur = GetUndoRedo(); if (closestSeg != -1) { //subdivide ur.CreateAction("Split Path"); ur.AddDoMethod(c, "add_point", closestSegPoint, new Vector3(), new Vector3(), closestSeg + 1); ur.AddUndoMethod(c, "remove_point", closestSeg + 1); ur.CommitAction(); return(true); } else { Vector3 org; if (c.GetPointCount() == 0) { org = path.Transform.origin; } else { org = gt.Xform(c.GetPointPosition(c.GetPointCount() - 1)); } Plane p = new Plane(); p.Normal = camera.Transform.basis.GetColumn(2); p.D = p.Normal.Dot(org); Vector3 ray_from = camera.ProjectRayOrigin(mbPos); Vector3 ray_dir = camera.ProjectRayNormal(mbPos); Vector3?inters = p.IntersectRay(ray_from, ray_dir); if (inters != null) { ur.CreateAction("Add Point to Curve"); ur.AddDoMethod(c, "add_point", it.Xform((Vector3)inters), new Vector3(), new Vector3(), -1); ur.AddUndoMethod(c, "remove_point", c.GetPointCount()); ur.CommitAction(); return(true); } //add new at pos } } else if (mb.Pressed && ((mb.ButtonIndex == (int)ButtonList.Left && curveDel.Pressed) || (mb.ButtonIndex == (int)ButtonList.Right && curveEdit.Pressed))) { for (int i = 0; i < c.GetPointCount(); i++) { float dist_to_p = camera.UnprojectPosition(gt.Xform(c.GetPointPosition(i))).DistanceTo(mbPos); float dist_to_p_out = camera.UnprojectPosition(gt.Xform(c.GetPointPosition(i) + c.GetPointOut(i))).DistanceTo(mbPos); float dist_to_p_in = camera.UnprojectPosition(gt.Xform(c.GetPointPosition(i) + c.GetPointIn(i))).DistanceTo(mbPos); // Find the offset and point index of the place to break up. // Also check for the control points. var ur = GetUndoRedo(); if (dist_to_p < clickDist) { ur.CreateAction("Remove Path Point"); ur.AddDoMethod(c, "remove_point", i); ur.AddUndoMethod(c, "add_point", c.GetPointPosition(i), c.GetPointIn(i), c.GetPointOut(i), i); ur.CommitAction(); return(true); } else if (dist_to_p_out < clickDist) { ur.CreateAction(("Remove Out-Control Point")); ur.AddDoMethod(c, "set_point_out", i, new Vector3()); ur.AddUndoMethod(c, "set_point_out", i, c.GetPointOut(i)); ur.CommitAction(); return(true); } else if (dist_to_p_in < clickDist) { ur.CreateAction(("Remove In-Control Point")); ur.AddDoMethod(c, "set_point_in", i, new Vector3()); ur.AddUndoMethod(c, "set_point_in", i, c.GetPointOut(i)); ur.CommitAction(); return(true); } } } } return(false); }
public override Curve Curve() { return(Curve3D.Curve()); }
public override void _PhysicsProcess(float delta) { base._PhysicsProcess(delta); var ribbonCurve = new Curve3D(); // based on the gap between the two controllers, the control points move further away from the origin as the controllers are moved apart // without dynamically adjusting the control points, the curve would get straighter as the controllers moved apart. var gapWidth = (RightController.GlobalTransform.origin - LeftController.GlobalTransform.origin).Length(); // control point locations are offset from the origin point (i.e not global coordinates) ribbonCurve.AddPoint(LeftController.RibbonGlobalOrigin, AdjustControlPoint(LeftController.ControlPointInOffset, gapWidth), AdjustControlPoint(LeftController.ControlPointOutOffset, gapWidth)); ribbonCurve.AddPoint(RightController.RibbonGlobalOrigin, AdjustControlPoint(RightController.ControlPointInOffset, gapWidth), AdjustControlPoint(RightController.ControlPointOutOffset, gapWidth)); // figure out a vector at 90 degrees to origin and control point. Vector will be used to offset one side of the ribbon, and give it a consistent width and orientation // need this for both controllers, and then gradually rotate from one to the other over the course of the ribbon length // Curve points pass through the centre of the Ribbon, as it appears on-screen. // To get the vertices to draw, need to offset from curvePoints for the front and back edges of the Ribbon, as below RibbonPoints = ribbonCurve.Tessellate(); // will interpolate between these edges to give the ribbon a smooth "twist" over its length var leftRibbonFrontEdgeOffset = LeftController.RibbonFrontEdgeOffset; var leftRibbonBackEdgeOffset = LeftController.RibbonBackEdgeOffset; var rightRibbonFrontEdgeOffset = RightController.RibbonFrontEdgeOffset; var rightRibbonBackEdgeOffset = RightController.RibbonBackEdgeOffset; var triStripPoints = new Vector3[RibbonPoints.Length * 2]; var curvePointLengthFloat = (float)RibbonPoints.Length; for (var i = 0; i < RibbonPoints.Length; i++) { // Offset front and back from curvePoints, as curvePoints pass through the centre of the ribbon var frontEdgePoint = RibbonPoints[i] + leftRibbonFrontEdgeOffset.LinearInterpolate(rightRibbonFrontEdgeOffset, i / curvePointLengthFloat); var backEdgePoint = RibbonPoints[i] + leftRibbonBackEdgeOffset.LinearInterpolate(rightRibbonBackEdgeOffset, i / curvePointLengthFloat); triStripPoints[i * 2] = frontEdgePoint; triStripPoints[(i * 2) + 1] = backEdgePoint; } RibbonMesh.Clear(); // without Clear, triangles from previous loops accumulate on screen RibbonMesh.Begin(Mesh.PrimitiveType.TriangleStrip); for (var i = 0; i < triStripPoints.Length; i++) { // pass vertices to Normal function in anti-clockwise order // this will vary depending on which side of the ribbon the vertex is added, hence the i % 2... condition. i.e.: // - odd number: n, n-1, n-2 // - even number: n-2, n-1, n var normal = i < 3 ? GetTriangleNormal(triStripPoints[2], triStripPoints[1], triStripPoints[0]) : (i % 2 == 0 ? GetTriangleNormal(triStripPoints[i], triStripPoints[i - 1], triStripPoints[i - 2]) : GetTriangleNormal(triStripPoints[i - 2], triStripPoints[i - 1], triStripPoints[i])); RibbonMesh.SetNormal(normal); RibbonMesh.AddVertex(triStripPoints[i]); } RibbonMesh.End(); }
public void TestPhysicsQuadTreeOrdenObjects() { ClientPhysicsQuadTreeNode root = CreateTestClientPhysicsQuadtree(); List <ClientPhysicsTestSphere> spheres = new List <ClientPhysicsTestSphere>(); spheres.Add(new ClientPhysicsTestSphere(new Vector3(3, 0, 3), 1)); spheres.Add(new ClientPhysicsTestSphere(new Vector3(33, 0, -83), 1)); spheres.Add(new ClientPhysicsTestSphere(new Vector3(-25, 0, 40), 1)); spheres.Add(new ClientPhysicsTestSphere(new Vector3(-25, 0, -35), 1)); for (int i = 0; i < spheres.Count; i++) { root.OrdenObject(spheres[i]); } ClientPhysicsTestSphere movingSphere = new ClientPhysicsTestSphere(Vector3.Zero, 2); Curve3D curve = CreateTestObject1MovementCurve(); float time = 0; QuadTreeVisualizerXNA visualizer = new QuadTreeVisualizerXNA(); XNAGame game = new XNAGame(); game.UpdateEvent += delegate { time += game.Elapsed; movingSphere.Center = curve.Evaluate(time * (1 / 4f)); root.OrdenObject(movingSphere); }; game.DrawEvent += delegate { for (int i = 0; i < spheres.Count; i++) { game.LineManager3D.AddCenteredBox(spheres[i].Center, spheres[i].Radius, Color.Red); } game.LineManager3D.AddCenteredBox(movingSphere.Center, movingSphere.Radius, Color.Red); visualizer.RenderNodeGroundBoundig(game, root, delegate(ClientPhysicsQuadTreeNode node, out Color col) { col = Color.Green; return(node.PhysicsObjects.Count == 0); }); visualizer.RenderNodeGroundBoundig(game, root, delegate(ClientPhysicsQuadTreeNode node, out Color col) { col = Color.Orange; return(node.PhysicsObjects.Count > 0); }); }; game.Run(); }
public SpitMissle(LoadModel model, Vector3 targtPosition) : base(model) { float d = Vector2.Distance(new Vector2(model.Position.X, model.Position.Z), new Vector2(targtPosition.X, targtPosition.Z)); float time = d / 0.2f; points.Add(new PointInTime(model.Position, 0)); points.Add(new PointInTime(targtPosition,time)); trajectory = new Curve3D(points,CurveLoopType.Constant); }
public override void CommitHandle(int index, object restore, bool cancel) { Curve3D c = path.curve; if (!IsInstanceValid(c)) { return; } UndoRedo ur = plugin.GetUndoRedo(); if (index < c.GetPointCount()) { if (cancel) { c.SetPointPosition(index, (Vector3)restore); return; } ur.CreateAction(("Set Curve Point Position")); ur.AddDoMethod(c, "set_point_position", index, c.GetPointPosition(index)); ur.AddUndoMethod(c, "set_point_position", index, restore); ur.CommitAction(); return; } index = index - c.GetPointCount() + 1; int idx = index / 2; int t = index % 2; if (t == 0) { if (cancel) { c.SetPointIn(index, (Vector3)restore); return; } ur.CreateAction(("Set Curve In Position")); ur.AddDoMethod(c, "set_point_in", idx, c.GetPointIn(idx)); ur.AddUndoMethod(c, "set_point_in", idx, restore); if (plugin.mirrorHandleAngle) { ur.AddDoMethod(c, "set_point_out", idx, plugin.mirrorHandleLength ? -c.GetPointIn(idx) : (-c.GetPointIn(idx).Normalized() * origOutLenght)); ur.AddUndoMethod(c, "set_point_out", idx, plugin.mirrorHandleLength ? -(Vector3)restore : (-((Vector3)restore).Normalized() * origOutLenght)); } ur.CommitAction(); } else { if (cancel) { c.SetPointOut(idx, (Vector3)restore); return; } ur.CreateAction(("Set Curve Out Position")); ur.AddDoMethod(c, "set_point_out", idx, c.GetPointOut(idx)); ur.AddUndoMethod(c, "set_point_out", idx, restore); if (plugin.mirrorHandleAngle) { ur.AddDoMethod(c, "set_point_in", idx, plugin.mirrorHandleLength ? -c.GetPointOut(idx) : (-c.GetPointOut(idx).Normalized() * origInLength)); ur.AddUndoMethod(c, "set_point_in", idx, plugin.mirrorHandleLength ? -(Vector3)(restore) : (-((Vector3)restore).Normalized() * origInLength)); } ur.CommitAction(); } }
public CameraPathData(CurveLoopType CurveLoopType) { heads = new Curve3D(CurveLoopType); targets = new Curve3D(CurveLoopType); ups = new Curve3D(CurveLoopType); }
public override void Redraw( ) { Clear(); //GD.Print($"Redraw {GD.Randi()%100}"); var pathMaterial = gizmoPlugin.GetMaterial("path_material", this); var pathThinMaterial = gizmoPlugin.GetMaterial("path_thin_material", this); var handlesMaterial = gizmoPlugin.GetMaterial("handles", this); Curve3D c = path.curve; if (!IsInstanceValid(c)) { GD.Print("Invalid curve"); return; } var v3a = c.Tessellate(); //PoolVector<Vector3> v3a=c.get_baked_points(); int v3s = v3a.Length; if (v3s == 0) { return; } var v3p = new Vector3[v3s * 2]; int v3pCount = 0; // BUG: the following won't work when v3s, avoid drawing as a temporary workaround. for (int i = 0; i < v3s - 1; i++) { v3p = v3p.Add(ref v3pCount, v3a[i]); v3p = v3p.Add(ref v3pCount, v3a[i + 1]); //v3p.push_back(r[i]); //v3p.push_back(r[i]+Vector3(0,0.2,0)); } if (v3pCount > 1) { v3p = v3p.Trim(ref v3pCount); AddLines((Vector3[])v3p.Clone(), pathMaterial); AddCollisionSegments((Vector3[])v3p.Clone()); } if (plugin.path == path) { v3p = v3p.Clear(ref v3pCount, true); int pointCount = c.GetPointCount(); var handles = new Vector3[pointCount]; int handlesCount = 0; var secHandles = new Vector3[pointCount]; int secHandlesCount = 0; for (int i = 0; i < pointCount; i++) { Vector3 p = c.GetPointPosition(i); handles = handles.Add(ref handlesCount, p); if (i > 0) { v3p = v3p.Add(ref v3pCount, p); v3p = v3p.Add(ref v3pCount, p + c.GetPointIn(i)); secHandles = secHandles.Add(ref secHandlesCount, p + c.GetPointIn(i)); } if (i < pointCount - 1) { v3p = v3p.Add(ref v3pCount, p); v3p = v3p.Add(ref v3pCount, p + c.GetPointOut(i)); secHandles = secHandles.Add(ref secHandlesCount, p + c.GetPointOut(i)); } } v3p = v3p.Trim(ref v3pCount); handles = handles.Trim(ref handlesCount); secHandles = secHandles.Trim(ref secHandlesCount); if (v3pCount > 1) { AddLines(v3p, pathThinMaterial); } if (handlesCount > 0) { AddHandles(handles, handlesMaterial); } if (secHandlesCount > 0) { AddHandles(secHandles, handlesMaterial, false, true); } } }
public void TestEntityClientPhysis() { XNAGame game = new XNAGame(); Database.Database database = loadDatabaseServices(); EntityManagerService ems = new EntityManagerService(database); BoundingBox bb = new BoundingBox(); PhysicsEngine engine = new PhysicsEngine(); PhysicsDebugRendererXNA debugRenderer = null; TheWizards.Client.ClientPhysicsQuadTreeNode root; root = new ClientPhysicsQuadTreeNode( new BoundingBox( new Vector3(-16 * 16 / 2f, -100, -16 * 16 / 2f), new Vector3(16 * 16 / 2f, 100, 16 * 16 / 2f))); QuadTree.Split(root, 4); ClientPhysicsTestSphere sphere = new ClientPhysicsTestSphere(Vector3.Zero, 2); Curve3D curve1 = ClientTest.CreateTestObject1MovementCurve(); QuadTreeVisualizerXNA visualizer = new QuadTreeVisualizerXNA(); float time = 0; List <ClientPhysicsTestSphere> spheres = new List <ClientPhysicsTestSphere>(); List <EntityClientPhysics> entities = new List <EntityClientPhysics>(); game.InitializeEvent += delegate { engine.Initialize(); debugRenderer = new PhysicsDebugRendererXNA(game, engine.Scene); debugRenderer.Initialize(game); EntityFullData entityData; EntityClientPhysics entPhysics; entityData = CreatePyramidEntity(ems, 5); entityData.Transform = new Transformation( Vector3.One, Quaternion.Identity, new Vector3(10, 2, 20)); entPhysics = new EntityClientPhysics(entityData); entPhysics.LoadInClientPhysics(engine.Scene, root); entities.Add(entPhysics); entityData = CreatePyramidEntity(ems, 20); entityData.Transform = new Transformation( Vector3.One, Quaternion.Identity, new Vector3(-32, 0, -40)); entPhysics = new EntityClientPhysics(entityData); entPhysics.LoadInClientPhysics(engine.Scene, root); entities.Add(entPhysics); entityData = CreateTwoPyramidEntity(ems, 5, 3); entityData.ObjectFullData.Models[0].ObjectMatrix *= Matrix.CreateTranslation(new Vector3(-3, 0, 3)); entityData.ObjectFullData.Models[1].ObjectMatrix *= Matrix.CreateTranslation(new Vector3(3, 1, 2)); entityData.Transform = new Transformation( Vector3.One * 2, Quaternion.Identity, new Vector3(80, 0, -45)); entPhysics = new EntityClientPhysics(entityData); entPhysics.LoadInClientPhysics(engine.Scene, root); entities.Add(entPhysics); }; game.DrawEvent += delegate { debugRenderer.Render(game); visualizer.RenderNodeGroundBoundig(game, root, delegate(ClientPhysicsQuadTreeNode node, out Color col) { col = Color.Green; return(node.PhysicsObjects.Count == 0); }); visualizer.RenderNodeGroundBoundig(game, root, delegate(ClientPhysicsQuadTreeNode node, out Color col) { col = Color.Orange; return(node.PhysicsObjects.Count > 0); }); game.LineManager3D.AddCenteredBox(sphere.Center, sphere.Radius, Color.Red); for (int i = 0; i < entities.Count; i++) { game.LineManager3D.AddCenteredBox(entities[i].BoundingSphere.Center, entities[i].BoundingSphere.Radius * 2, Color.Black); } }; game.UpdateEvent += delegate { time += game.Elapsed; sphere.Move(root, curve1.Evaluate(time * (1 / 4f))); if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.F)) { ClientPhysicsTestSphere iSphere = new ClientPhysicsTestSphere(engine.Scene, game.SpectaterCamera.CameraPosition + game.SpectaterCamera.CameraDirection , 1); iSphere.InitDynamic(); iSphere.Actor.LinearVelocity = game.SpectaterCamera.CameraDirection * 10; spheres.Add(iSphere); } for (int i = 0; i < spheres.Count; i++) { spheres[i].Update(root, game); } engine.Update(game.Elapsed); }; game.Run(); }
public void TestPhysicsEnableDisable() { List <ClientPhysicsTestSphere> spheres = new List <ClientPhysicsTestSphere>(); ClientPhysicsQuadTreeNode root = CreateTestClientPhysicsQuadtree(); spheres.Add(new ClientPhysicsTestSphere(new Vector3(0, 0, 0), 2)); Curve3D curve1 = CreateTestObject1MovementCurve(); float time = 0; bool progressTime = true; QuadTreeVisualizerXNA visualizer = new QuadTreeVisualizerXNA(); XNAGame game = new XNAGame(); game.UpdateEvent += delegate { if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.P)) { progressTime = !progressTime; } if (progressTime) { time += game.Elapsed; } spheres[0].Move(root, curve1.Evaluate(time * (1 / 4f))); }; game.DrawEvent += delegate { for (int i = 0; i < spheres.Count; i++) { game.LineManager3D.AddCenteredBox(spheres[i].Center, spheres[i].Radius, Color.Red); } visualizer.RenderNodeGroundBoundig(game, root, delegate(ClientPhysicsQuadTreeNode node, out Color col) { col = Color.Green; return(node.DynamicObjectsCount == 0 && !node.PhysicsEnabled); }); visualizer.RenderNodeGroundBoundig(game, root, delegate(ClientPhysicsQuadTreeNode node, out Color col) { col = Color.Red; return(node.DynamicObjectsCount == 0 && node.PhysicsEnabled); }); visualizer.RenderNodeGroundBoundig(game, root, delegate(ClientPhysicsQuadTreeNode node, out Color col) { col = Color.Yellow; if (node.DynamicObjectsCount == 1) { col = Color.Orange; } return(node.DynamicObjectsCount > 0); }); visualizer.RenderNodeGroundBoundig(game, root, delegate(ClientPhysicsQuadTreeNode node, out Color col) { col = Color.Purple; return(node.DynamicObjectsCount < 0); }); }; game.Run(); }