public void AddNewBoid(Boid boid) { //return; try { SceneNode boidNode = base.sceneMgr.RootSceneNode.CreateChildSceneNode("Node" + count); //Entity boidEntity = base.sceneMgr.CreateEntity("Boid"+count, "myBoid_" + boid.Color); //boidNode.AttachObject(boidEntity); ManualObject boidObj = BoidMesh.CreateBoidObject("Boid" + count, base.sceneMgr, boid.Color); boidNode.AttachObject(boidObj); boidNodesList.Add(boidNode); MoveBoid(boidNode, boid); count++; } catch (Exception e) { Console.WriteLine(e); } }
public void AddNewBoid(Boid boid) { //return; try { SceneNode boidNode = base.sceneMgr.RootSceneNode.CreateChildSceneNode("Node" + count); //Entity boidEntity = base.sceneMgr.CreateEntity("Boid"+count, "myBoid_" + boid.Color); //boidNode.AttachObject(boidEntity); ManualObject boidObj = BoidMesh.CreateBoidObject("Boid" + count, base.sceneMgr, boid.Color); boidNode.AttachObject(boidObj); boidNodesList.Add(boidNode); MoveBoid(boidNode, boid); count++; } catch (Exception e) { Console.WriteLine(e); } }
/// <summary> /// Boid movement is a rotation and a translation, which use /// the current boid velocity and position. /// </summary> private void MoveBoid(SceneNode boidNode, Boid b) { boidNode.Position = b.Position; Vector3 direction = b.Velocity; direction.Normalise(); // Test for opposite vectors float d = 1.0f + Vector3.UNIT_Z.DotProduct(direction); if (System.Math.Abs(d) < 0.00001) { // Diametrically opposed vectors Quaternion orientation = new Quaternion(); orientation.FromAxes(Vector3.NEGATIVE_UNIT_X, Vector3.UNIT_Y, Vector3.NEGATIVE_UNIT_Z); boidNode.Orientation = orientation; } else { boidNode.Orientation = Vector3.UNIT_Z.GetRotationTo(direction); } }
/// <summary> /// Boid movement is a rotation and a translation, which use /// the current boid velocity and position. /// </summary> private void MoveBoid(SceneNode boidNode, Boid b) { boidNode.Position = b.Position; Vector3 direction = b.Velocity; direction.Normalise(); // Test for opposite vectors float d = 1.0f + Vector3.UNIT_Z.DotProduct(direction); if (System.Math.Abs(d) < 0.00001) { // Diametrically opposed vectors Quaternion orientation = new Quaternion(); orientation.FromAxes(Vector3.NEGATIVE_UNIT_X, Vector3.UNIT_Y, Vector3.NEGATIVE_UNIT_Z); boidNode.Orientation = orientation; } else { boidNode.Orientation = Vector3.UNIT_Z.GetRotationTo(direction); } }