/// <summary> /// Render propeller in modern opengl. /// </summary> /// <returns></returns> public static DepthRectNode Create() { var vs = new VertexShader(vertexCode); var fs = new FragmentShader(fragmentCode); var provider = new ShaderArray(vs, fs); var map = new AttributeMap(); map.Add(inPosition, RectModel.strPosition); map.Add(inUV, RectModel.strUV); var builder = new RenderMethodBuilder(provider, map); var node = new DepthRectNode(new RectModel(), RectModel.strPosition, builder); node.Initialize(); return(node); }
private void FormMain_Load(object sender, EventArgs e) { var position = new vec3(1, 0.6f, 1) * 16; var center = new vec3(0, 0, 0); var up = new vec3(0, 1, 0); var camera = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height); this.scene = new Scene(camera); this.scene.RootNode = GetRootNode(); // add lights. { var lightList = this.lights; float angle = 0; foreach (var light in lightList) { this.scene.Lights.Add(light); var node = LightPositionNode.Create(light, angle); angle += 360.0f / lightList.Count; this.scene.RootNode.Children.Add(node); } } { var list = new ActionList(); list.Add(new TransformAction(scene)); var shadowMappingAction = new ShadowMappingAction(scene); list.Add(shadowMappingAction); this.shadowMappingAction = shadowMappingAction; list.Add(new RenderAction(scene)); this.actionList = list; } { var node = DepthRectNode.Create(); node.TextureSource = this.shadowMappingAction.LightEquipment; this.scene.RootNode.Children.Add(node); } Match(this.trvScene, scene.RootNode); this.trvScene.ExpandAll(); var manipulater = new FirstPerspectiveManipulater(); manipulater.Bind(camera, this.winGLCanvas1); }
private SceneNodeBase GetRootNode() { var group = new GroupNode(); var filenames = new string[] { "floor.obj_", "dragon.obj_", }; var colors = new Color[] { Color.Green, Color.White, }; for (int i = 0; i < filenames.Length; i++) { string folder = System.Windows.Forms.Application.StartupPath; string filename = System.IO.Path.Combine(folder + @"\..\..\..\..\Infrastructure\CSharpGL.Models", filenames[i]); var parser = new ObjVNFParser(true); ObjVNFResult result = parser.Parse(filename); if (result.Error != null) { MessageBox.Show(result.Error.ToString()); } else { ObjVNFMesh mesh = result.Mesh; var model = new ObjVNF(mesh); var node = ShadowMappingNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize()); node.WorldPosition = new vec3(0, i * 5, 0); node.Color = colors[i].ToVec3(); node.Name = filename; group.Children.Add(node); } } { var rect = DepthRectNode.Create(); rect.Scale = new vec3(1, 1, 1) * 50; rect.WorldPosition = new vec3(1, 1, 1) * 27; group.Children.Add(rect); this.rect = rect; } return(group); }