public void Evaluate(int SpreadMax) { if (this.FWorld.PluginIO.IsConnected) { this.FHit.SliceCount = SpreadMax; List <double> fraction = new List <double>(); List <Vector3D> position = new List <Vector3D>(); List <Vector3D> normal = new List <Vector3D>(); List <SoftBody> body = new List <SoftBody>(); List <int> bodyid = new List <int>(); List <int> qidx = new List <int>(); List <int> nidx = new List <int>(); List <EFeature> feat = new List <EFeature>(); List <Node> nodes = new List <Node>(); for (int i = 0; i < SpreadMax; i++) { Vector3 from = this.FFrom[i].ToBulletVector(); Vector3 to = this.FTo[i].ToBulletVector(); List <SoftBody> sbs = this.FWorld[0].SoftBodies; //List<SRayCast> results = new List<SRayCast>(); SRayCast closest = null; for (int ib = 0; ib < sbs.Count; ++ib) { SoftBody psb = sbs[ib]; SRayCast res = new SRayCast(); if (psb.RayTest(from, to, res)) { if (closest == null) { closest = res; } else { if (res.Fraction < closest.Fraction) { closest = res; } } } } if (closest != null) { this.FHit[i] = true; fraction.Add(closest.Fraction); Vector3 pos = from + (to - from) * closest.Fraction; position.Add(pos.ToVVVVector()); body.Add(closest.Body); qidx.Add(i); SoftBodyCustomData sd = (SoftBodyCustomData)closest.Body.UserObject; bodyid.Add(sd.Id); feat.Add(closest.Feature); int nodeidx = closest.Index; Node fnode = null; if (closest.Feature == EFeature.Face) { var f = closest.Body.Faces[closest.Index]; Node node = f.N[0]; for (int ni = 1; ni < 3; ++ni) { if ((node.X - pos).LengthSquared() > (f.N[ni].X - pos).LengthSquared()) { fnode = f.N[ni]; } } } if (closest.Feature == EFeature.Node) { fnode = closest.Body.Nodes[nodeidx]; } nidx.Add(nodeidx); nodes.Add(fnode); } else { this.FHit[i] = false; } } this.FId.AssignFrom(bodyid); this.FHitFraction.AssignFrom(fraction); this.FHitPosition.AssignFrom(position); this.FQueryIndex.AssignFrom(qidx); this.FBody.AssignFrom(body); this.FHitFeature.AssignFrom(feat); this.FHitIndex.AssignFrom(nidx); this.FNode.AssignFrom(nodes); } else { this.FHit.SliceCount = 0; this.FId.SliceCount = 0; this.FHitFraction.SliceCount = 0; this.FHitPosition.SliceCount = 0; this.FHitFeature.SliceCount = 0; this.FHitIndex.SliceCount = 0; this.FBody.SliceCount = 0; this.FNode.SliceCount = 0; } }
protected override void OnHandleInput() { base.OnHandleInput(); if (Input.MousePressed == MouseButtons.Right) { results.Fraction = 1; if (pickConstraint == null) { Vector3 rayFrom = Freelook.Eye; Vector3 rayTo = GetRayTo(Input.MousePoint, Freelook.Eye, Freelook.Target, FieldOfView); Vector3 rayDir = (rayTo - rayFrom); rayDir.Normalize(); AlignedSoftBodyArray sbs = ((SoftRigidDynamicsWorld)PhysicsContext.World).SoftBodyArray; for (int ib = 0; ib < sbs.Count; ++ib) { SoftBody psb = sbs[ib]; SRayCast res = new SRayCast(); if (psb.RayTest(rayFrom, rayTo, res)) { results = res; } } if (results.Fraction < 1) { impact = rayFrom + (rayTo - rayFrom) * results.Fraction; drag = !(PhysicsContext as Physics).cutting; lastMousePos = Input.MousePoint; node = null; switch (results.Feature) { case EFeature.Tetra: { Tetra tet = results.Body.Tetras[results.Index]; node = tet.Nodes[0]; for (int i = 1; i < 4; ++i) { if ((node.X - impact).LengthSquared() > (tet.Nodes[i].X - impact).LengthSquared()) { node = tet.Nodes[i]; } } break; } case EFeature.Face: { Face f = results.Body.Faces[results.Index]; node = f.N[0]; for (int i = 1; i < 3; ++i) { if ((node.X - impact).LengthSquared() > (f.N[i].X - impact).LengthSquared()) { node = f.N[i]; } } } break; } if (node != null) { goal = node.X; } //return; } } } else if (Input.MouseReleased == MouseButtons.Right) { if ((!drag) && (PhysicsContext as Physics).cutting && (results.Fraction < 1)) { ImplicitSphere isphere = new ImplicitSphere(impact, 1); results.Body.Refine(isphere, 0.0001f, true); } results.Fraction = 1; drag = false; } // Mouse movement if (Input.MouseDown == MouseButtons.Right) { if (node != null && (results.Fraction < 1)) { if (!drag) { int x = Input.MousePoint.X - lastMousePos.X; int y = Input.MousePoint.Y - lastMousePos.Y; if ((x * x) + (y * y) > 6) { drag = true; } } if (drag) { lastMousePos = Input.MousePoint; } } } (PhysicsContext as Physics).HandleInput(Input, FrameDelta); }