/// <summary> /// Initializes a new instance of the <see cref="ProjectorWin"/> class. /// </summary> public ProjectorWin() { // Initial something. this.drawer = null; this.buildingModelCursor = null; texture_name = new uint[1]; renderbuffer_name = new uint[1]; framebuffer_name = new uint[1]; // Initial texture size. if (Screen.AllScreens.Count() >= 2) { this.TEXTURE_WIDTH = Screen.AllScreens[1].Bounds.Width; this.TEXTURE_HEIGHT = Screen.AllScreens[1].Bounds.Height; } else { this.TEXTURE_WIDTH = Screen.AllScreens[0].Bounds.Width; this.TEXTURE_HEIGHT = Screen.AllScreens[0].Bounds.Height; } fovy = 45.0f; System.Timers.Timer t = new System.Timers.Timer(10000); t.Elapsed += new System.Timers.ElapsedEventHandler(this.CalculateFPS); t.AutoReset = true; t.Enabled = true; fps = 0; // Initial form components. InitializeComponent(); }
/// <summary> /// For test... /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void openGLControl_KeyPress(object sender, KeyPressEventArgs e) { switch (e.KeyChar) { case 'i': case 'I': status.eye.z += 5.0f; break; case 'o': case 'O': status.eye.z -= 5.0f; break; case 'a': case 'A': status.eye.x += 5.0f; break; case 'D': case 'd': status.eye.x -= 5.0f; break; case 'W': case 'w': status.eye.y += 5.0f; break; case 's': case 'S': status.eye.y -= 5.0f; break; case 'K': case 'k': this.buildingModelCursor = buildingModelCursor.Move(DrawingEnumTypes.Movement.MenuOut, this.status); break; case 'L': case 'l': this.buildingModelCursor = buildingModelCursor.Move(DrawingEnumTypes.Movement.MenuIn, this.status); break; case 'Y': case 'y': this.buildingModelCursor = buildingModelCursor.Move(DrawingEnumTypes.Movement.MoveIn, this.status); break; case 'H': case 'h': this.buildingModelCursor = buildingModelCursor.Move(DrawingEnumTypes.Movement.MoveOut, this.status); break; case 'G': case 'g': this.buildingModelCursor = buildingModelCursor.Move(DrawingEnumTypes.Movement.MoveLeft, this.status); break; case 'J': case 'j': this.buildingModelCursor = buildingModelCursor.Move(DrawingEnumTypes.Movement.MoveRight, this.status); break; } }
public DrawingController() { projectorWin = new ProjectorWin(); projectorWin.status = new DrawingStatus(); loader = new _3DSLoaderByLib3DS(); loaderForFun = new _3DSLoaderByLib3DS(); loader.OpenFile("..\\Model\\Untitled.3ds"); loaderForFun.OpenFile("..\\Model\\miku.3ds"); buildingModel = loader.CreateBuildingModel(); buildingModel.CalculateLocation(); modelForFun = loaderForFun.CreateBuildingModel(); modelForFun.CalculateLocation(); drawer = new _3DSDrawerByLib3DS(); projectorWin.buildingModelCursor = buildingModel; projectorWin.buildingOutsideModel = buildingModel.GetChilds()["0"] as BuildingObjectLib3DS; projectorWin.modelForFun = modelForFun; projectorWin.drawer = drawer; projectorWin.Show(); }
/// <summary> /// Render texture with FBO and draw it to memory. /// </summary> private void RenderTexWithFBOandDraw() { OpenGL gl = openGLControl.OpenGL; // render to texture // adjust viewport and projection matrix to texture dimension gl.Viewport(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT); gl.MatrixMode(OpenGL.GL_PROJECTION); gl.LoadIdentity(); gl.Perspective(fovy, (double)Width / (double)Height, 0.01f, 100.0); gl.LookAt( status.eye.x + status.kinect.x, status.eye.y + status.kinect.y, status.eye.z + status.kinect.z, buildingModelCursor.GetCoordinate().x, buildingModelCursor.GetCoordinate().y, buildingModelCursor.GetCoordinate().z, 0, 1, 0 ); // with FBO // set the rendering destination to FBO gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, framebuffer_name[0]); gl.MatrixMode(OpenGL.GL_MODELVIEW); gl.LoadIdentity(); // clear buffer gl.ClearColor(0, 0, 0, 1); gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); // start to draw gl.PushMatrix(); // Load the identity matrix. gl.Enable(OpenGL.GL_TEXTURE_2D); drawer.DrawBuildingPart(gl, buildingModelCursor, DrawType.Full); if (status != null && buildingModelCursor != null) { switch (buildingModelCursor.GetBuildingType()) { case BuildingObjectType.Floor: drawer.DrawBuildingPart(gl, buildingOutsideModel, DrawType.WireFrame); drawer.DrawBuildingPart(gl, buildingModelCursor, DrawType.Full); break; case BuildingObjectType.Object: System.Collections.Hashtable childs = buildingModelCursor.Father.GetChilds(); foreach (System.Collections.DictionaryEntry childEntry in buildingModelCursor.Father.GetChilds()) { BuildingObjectLib3DS child = childEntry.Value as BuildingObjectLib3DS; if (child != buildingModelCursor) { drawer.DrawBuildingPart(gl, child, DrawType.WireFrame); } else { drawer.DrawBuildingPart(gl, child, DrawType.Full); } } break; case BuildingObjectType.Room: // TODO case BuildingObjectType.Outside: case BuildingObjectType.Building: drawer.DrawBuildingPart(gl, buildingModelCursor, DrawType.Full); break; } } //drawer.DrawBuildingPart(gl, modelForFun, DrawType.Full); gl.PopMatrix(); // back to normal window-system-provided framebuffer gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, 0); // unbind // trigger mipmaps generation explicitly // NOTE: If GL_GENERATE_MIPMAP is set to GL_TRUE, then glCopyTexSubImage2D() // triggers mipmap generation automatically. However, the texture attached // onto a FBO should generate mipmaps manually via glGenerateMipmapEXT(). gl.BindTexture(OpenGL.GL_TEXTURE_2D, texture_name[0]); gl.GenerateMipmapEXT(OpenGL.GL_TEXTURE_2D); //gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD); gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0); // TODO: without FBO, maybe need }