static void SetBoneSize(Scene scene, CreateBonePointInfo pointInfo, Point currentScreen, bool isRelativeBone) { if (isRelativeBone) pointInfo.HasSize = false; else { var beginScreen = scene.Convert3dToScreen(pointInfo.BeginWorld); var endScreen = pointInfo.EndScreen; var currentToEndScreenSize = (endScreen - currentScreen).GetSizeSquared(); var beginToEndScreen = endScreen - beginScreen; var size = (float)Math.Sqrt(Math.Min ( Math.Max(currentToEndScreenSize, MinimalBoneSize * MinimalBoneSize), beginToEndScreen.GetSizeSquared() )); var flip = Point.GetInnerProduct(new Point(-beginToEndScreen.Y, beginToEndScreen.X, 0), currentScreen - beginScreen) < 1; var rad = Math.Atan2(beginToEndScreen.Y, beginToEndScreen.X) + MathHelper.PiOver2 * (flip ? -1 : 1); var scr = new Point(beginScreen.X + (float)Math.Cos(rad) * size, beginScreen.Y + (float)Math.Sin(rad) * size, beginScreen.Z); pointInfo.Flip = flip; pointInfo.SizeWorld = scene.ConvertScreenTo3d(ref scr); pointInfo.HasSize = true; } }
/// <summary> /// 面の向きが表かどうか調べる /// bool IsFrontFace(MQScene scene, MQObject obj, int face_index) /// </summary> /// <param name="scene">シーン</param> /// <param name="faceIndex">面</param> /// <returns>向きが表かどうか</returns> public bool IsFrontFace(Scene scene, int faceIndex) { var num = this.GetFacePointCount(faceIndex); var vertIndex = new int[num]; this.GetFacePointArray(faceIndex, vertIndex); var sp = new Point[num]; for (int i = 0; i < num; i++) { sp[i] = scene.Convert3dToScreen(this.GetVertex(vertIndex[i])); if (sp[i].Z <= 0) return false; } if (num >= 3) { if ((sp[1].X - sp[0].X) * (sp[2].Y - sp[1].Y) - (sp[1].Y - sp[0].Y) * (sp[2].X - sp[1].X) < 0) return true; else if (num >= 4) if ((sp[2].X - sp[0].X) * (sp[3].Y - sp[2].Y) - (sp[2].Y - sp[0].Y) * (sp[3].X - sp[2].X) < 0) return true; } else if (num > 0) return true; return false; }