private void BoneDrawingHack(BoneNode b, Transformation parentTransformation, float frame, int maxFrames) { Transformation localTransformation = Transformation.Identity; localTransformation.Position = new Vector2(b.Position.X, b.Position.Z); if (b.Rotations != null) { if (frame >= b.Rotations.Count) { localTransformation.Rotation = 0; } else { int currentFrame = (int)frame; int nextFrame = (int)(frame + 1) % maxFrames; float lerpAmount = frame % 1; float r = Lerp(b.Rotations[currentFrame], b.Rotations[nextFrame], lerpAmount); localTransformation.Rotation = r; } } else { localTransformation.Rotation = 0f; } Transformation worldTrans = Transformation.Compose(parentTransformation, localTransformation); int imageInd = 0; if (b.Images != null && frame <= b.Images.Count) { imageInd = b.Images[(int)frame]; } Color highlight = Color.White; if (form.BoneTreeView.SelectedNode == b) { highlight = Color.Red; } DrawBone(b.Texture, b.Size, imageInd, b.Origin, worldTrans, highlight); if (b.Nodes.Count > 0) { foreach (BoneNode e in b.Nodes) { BoneDrawingHack(e, worldTrans, frame, maxFrames); } } }
/// <summary> /// This function is used to parse a .poule file. /// </summary> private void ParsePoule(Scene scene, string filename) { string[] lines = File.ReadAllLines(filename); foreach (string str in lines) { if (_pointLightReg.Match(str).Success) { string[] array = str.Split(' '); scene.Lights.Add(new PointLight(Transformation.Translation( float.Parse(array[1], CultureInfo.InvariantCulture.NumberFormat), float.Parse(array[2], CultureInfo.InvariantCulture.NumberFormat), float.Parse(array[3], CultureInfo.InvariantCulture.NumberFormat)), SampledSpectrum.White())); } else if (_diskLightReg.Match(str).Success) { string[] array = str.Split(' '); scene.Lights.Add(new PointLight(Transformation.Translation( float.Parse(array[1], CultureInfo.InvariantCulture.NumberFormat), float.Parse(array[2], CultureInfo.InvariantCulture.NumberFormat), float.Parse(array[3], CultureInfo.InvariantCulture.NumberFormat)), SampledSpectrum.White())); } else if (_cameraReg.Match(str).Success) { string[] array = str.Split(' '); _camera = new SimpleCamera(_screen, Transformation.Compose( Transformation.Translation( Convert.ToInt32(array[1]), Convert.ToInt32(array[2]), Convert.ToInt32(array[3]) ), Transformation.RotateX(float.Parse(array[4], CultureInfo.InvariantCulture.NumberFormat)), Transformation.RotateY(float.Parse(array[5], CultureInfo.InvariantCulture.NumberFormat)), Transformation.RotateZ(float.Parse(array[6], CultureInfo.InvariantCulture.NumberFormat)) )); } else if (_objReg.Match(str).Success == true) { string[] array = str.Split(' '); try { string path = array[1].Replace(@"\\", @"\"); ParsingObj parser = new ParsingObj(path); parser.AddToScene(scene); } catch (Exception e) { FileName.Text = e.Message; } } } }
public Form1() { InitializeComponent(); FileName.ForeColor = System.Drawing.Color.FromArgb((int)0xFF, (int)0x61, (int)0x61); FileName.Text = "No file selected."; _screen = new Screen((uint)RenderPicture.Width, (uint)RenderPicture.Height); _camera = new SimpleCamera(_screen, Transformation.Compose( Transformation.Translation(0, 0, -1000), Transformation.RotateX(0), Transformation.RotateY(0), Transformation.RotateZ(0) )); InitNewScene(); _pointLightReg = new Regex(@"^(PL( (-?|\+?)(\d)* (-?|\+?)(\d)* (-?|\+?)(\d)* (1|0)\.(\d)*$))", RegexOptions.Compiled); _diskLightReg = new Regex(@"^(DL( (-?|\+?)(\d)* (-?|\+?)(\d)* (-?|\+?)(\d)* (1|0)\.(\d)* (\d*\.)?(\d)*$))", RegexOptions.Compiled); _objReg = new Regex(@"^(O( [A-Z]:(\\([a-zA-Z]*[^*/\\.\[\]:;|=,])*)*\.obj$))", RegexOptions.Compiled); _cameraReg = new Regex(@"^(C( (-?|\+?)(\d)* (-?|\+?)(\d)* (-?|\+?)(\d)* (-?|\+?)(\d)* (-?|\+?)(\d)* (-?|\+?)(\d)*$))", RegexOptions.Compiled); }