SceneNode CreateAnnotation(Vector3 start, Vector3 end, Vector3 offset, String text) { var line = GeometryBuilder.CreateLine(start + offset, end + offset); var mesh = FontManager.Instance().CreateMesh(text); var textNode = new PrimitiveSceneNode(mesh, null); float scale = 0.015f; textNode.SetTransform(Matrix4.makeRotationAxis(Vector3.UNIT_X, 3.14159f * 0.5f) * Matrix4.makeScale(scale, scale, 1)); textNode.ComputeBoundingBox(Matrix4.Identity); float halfW = textNode.GetWorldBBox().getHalfSize().x; var dist = end.distanceTo(start); float ratio = (dist * 0.5f - halfW) / dist; textNode.SetTransform(Matrix4.makeTranslation((start + end) * ratio + offset) * textNode.GetTransform()); var line2 = GeometryBuilder.CreateLine(start, start + offset + new Vector3(0, 0, -2)); var line3 = GeometryBuilder.CreateLine(end, end + offset + new Vector3(0, 0, -2)); GroupSceneNode group = new GroupSceneNode(); group.AddNode(new PrimitiveSceneNode(line, null)); group.AddNode(new PrimitiveSceneNode(line2, null)); group.AddNode(new PrimitiveSceneNode(line3, null)); group.AddNode(textNode); return(group); }
public void Create(RenderControl render) { // 随便构造些点 float offset = 10.0f; for (int ii = 0; ii < 10; ++ii) { for (int jj = 0; jj < ii; ++jj) { mPoints.Add(new Vector3(jj * offset, 100, ii * offset)); } } mMotionTrail = new ParticleSceneNode((uint)mPoints.Count, ColorTable.Green, 3.0f); mCurrentIdx = 0; render.ShowSceneNode(mMotionTrail); var lineMaterial = BasicMaterial.Create("myline"); lineMaterial.SetColor(ColorTable.Hex(0xFF0000)); var line = GeometryBuilder.CreateLine(Vector3.Zero, new Vector3(1, 0, 0)); mLineNode = new PrimitiveSceneNode(line, lineMaterial); mLineNode.SetTransform(MakeTransform(mStart, mPoints[0])); mLineNode.RequstUpdate(); render.ShowSceneNode(mLineNode); }