public void Select(JLoader loader) { JModelTexture texture = new JModelTexture(loader.loadTexture(SphereTexturePathSelected)); SphereTexturedModel = new JTexturedModel(SphereModel, texture); SphereEntity = new JEntity(SphereTexturedModel, SphereEntity.Position, new Vector3(0, 0, 1), 0.5f); }
public JEntity(JTexturedModel model, Vector3 position, Vector3 orientation, float scale) { TexturedModel = model; Position = position; Scale = scale; Orientation = orientation; }
/// <summary> /// Load the model and texture of the JBoundingSphere if we want to render it in the world. /// </summary> /// <param name="loader"></param> public void LoadSphereModel(JLoader loader) { SphereModelData = JObjFileLoader.LoadObj(SphereModelPath); SphereModel = loader.LoadToVAO(SphereModelData.Vertices, SphereModelData.TextureCoords, SphereModelData.Normals, SphereModelData.Indices); JModelTexture texture = new JModelTexture(loader.loadTexture(SphereTexturePathUnselected)); SphereTexturedModel = new JTexturedModel(SphereModel, texture); SphereEntity = new JEntity(SphereTexturedModel, new Vector3(50, 0, -50), new Vector3(0, 0, 1), 0.5f); }
/// <summary> /// JBoundedEntity has a JBoundingSphere which allows selection of the JBoundedEntity with a mouse click. /// </summary> /// <param name="model"></param> /// <param name="position"></param> /// <param name="rotX"></param> /// <param name="rotY"></param> /// <param name="rotZ"></param> /// <param name="scale"></param> /// <param name="loader"></param> public JBoundedEntity(JTexturedModel model, Vector3 position, Vector3 orientation, float scale, JLoader loader) : base(model, position, orientation, scale) { BoundingSphere = new JBoundingSphere(); BoundingSphere.LoadSphereModel(loader); IsSelected = false; IsAtDestination = true; Destination = new JVector3(); }
private void prepareTexturedModel(JTexturedModel texturedModel) { JRawModel rawModel = texturedModel.RawModel; GL.BindVertexArray(rawModel.vaoID); enableAttribArrays(); JModelTexture texture = texturedModel.Texture; Shader.LoadShineVariables(texture.ShineDamper, texture.Reflectivity); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, texturedModel.Texture.TextureID); }
public void Render(JTexturedModel texturedModel) { JRawModel model = texturedModel.RawModel; GL.BindVertexArray(model.vaoID); GL.EnableVertexAttribArray(0); GL.EnableVertexAttribArray(1); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, texturedModel.Texture.TextureID); GL.DrawElements(PrimitiveType.Triangles, model.vertexCount, DrawElementsType.UnsignedInt, 0); GL.DisableVertexAttribArray(0); GL.DisableVertexAttribArray(1); GL.BindVertexArray(0); }
public void ProcessEntity(JEntity entity) { JTexturedModel texturedModel = entity.TexturedModel; try { List <JEntity> batch = Entities[texturedModel]; batch.Add(entity); } catch (KeyNotFoundException e) { List <JEntity> newBatch = new List <JEntity> { entity }; Entities.Add(texturedModel, newBatch); } }
public JNoiseWindow() : base(WIDTH, HEIGHT, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8), "JNoiseWindow", GameWindowFlags.Default, DisplayDevice.Default, 3, 0, GraphicsContextFlags.ForwardCompatible) { Loader = new JLoader(); Renderer = new JRenderer2D(); shader = new JStaticShader2D(); float[] vertices = { -0.5f, 0.5f, 0f, //v0 -0.5f, -0.5f, 0f, //v1 0f, -0.5f, 0f, //v2 0f, 0.5f, 0f, //v3 }; uint[] indices = { 0, 1, 3, //top left triangle (v0, v1, v3) 3, 1, 2 //bottom right triangle (v3, v1, v2) }; float[] textureCoords = { 0, 0, 0, 1, 1, 1, 1, 0 }; float[,] test = JNoise.GenerateNoiseMap(100, 100, 27.6f, 4, 0.5f, 1.87f); model = Loader.LoadToVAO(vertices, textureCoords, indices); //JModelTexture mt = new JModelTexture(Loader.loadTexture(JFileUtils.GetPathToFile("Cowboy\\CowboyTexture.png"))); JModelTexture mt = new JModelTexture(Loader.LoadColorBitmapTexture(test)); tm = new JTexturedModel(model, mt); }
/// <summary> /// /// </summary> /// <returns></returns> public List <JEntity> GenerateTrees() { Console.WriteLine("Generating Trees..."); List <JEntity> TreeEntities = new List <JEntity>(); string TreeTexturePath = JFileUtils.GetPathToResFile("Tree\\tree_texture_green_brown.png"); string TreeModelPath = JFileUtils.GetPathToResFile("Tree\\tree.obj"); JModelData TreeModelData = JObjFileLoader.LoadObj(TreeModelPath); JRawModel TreeModel = Loader.LoadToVAO(TreeModelData.Vertices, TreeModelData.TextureCoords, TreeModelData.Normals, TreeModelData.Indices); JModelTexture TreeTexture = new JModelTexture(Loader.loadTexture(TreeTexturePath)); JTexturedModel TreeTexturedModel = new JTexturedModel(TreeModel, TreeTexture); Random r = new Random(); for (int i = 0; i < 200; i++) { float posX = (float)r.NextDouble() * 800; float posZ = -(float)r.NextDouble() * 800; float posY = Terrain.GetHeightOfTerrain(posX, posZ); while (posY < WaterTile.Height) { posX = (float)r.NextDouble() * 800; posZ = -(float)r.NextDouble() * 800; posY = Terrain.GetHeightOfTerrain(posX, posZ); } Vector3 orientation = new Vector3((float)r.NextDouble(), 0, (float)r.NextDouble()); orientation.NormalizeFast(); JEntity entity = new JEntity(TreeTexturedModel, new Vector3(posX, posY, posZ), orientation, 0.25f); TreeEntities.Add(entity); } return(TreeEntities); }
/// <summary> /// GraphicsMode used for anitaliasing. /// </summary> public JGameWindow() : base(WIDTH, HEIGHT, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8), "JModelViewer", GameWindowFlags.Default, DisplayDevice.Default, 3, 0, GraphicsContextFlags.ForwardCompatible) { PlayerTexturePath = JFileUtils.GetPathToResFile("Cowboy\\CowboyTexture.png"); PlayerModelPath = JFileUtils.GetPathToResFile("Cowboy\\Cowboy.obj"); Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; DateTime buildDate = new DateTime(2000, 1, 1).AddDays(version.Build).AddSeconds(version.Revision * 2); string displayVersion = $"{version} ({buildDate})"; Console.WriteLine("JGameEngine v." + displayVersion); Console.WriteLine("OpenGL version: " + GL.GetString(StringName.Version)); Loader = new JLoader(); PlayerModelData = JObjFileLoader.LoadObj(PlayerModelPath); Console.WriteLine("Using .obj file: " + PlayerModelPath); PlayerModel = Loader.LoadToVAO(PlayerModelData.Vertices, PlayerModelData.TextureCoords, PlayerModelData.Normals, PlayerModelData.Indices); Console.WriteLine("Using .png texture file: " + PlayerTexturePath + "..."); JModelTexture texture = new JModelTexture(Loader.loadTexture(PlayerTexturePath)); TexturedModel = new JTexturedModel(PlayerModel, texture); Light = new JLight(new Vector3(0, 0, 0), new Vector3(1, 1, 1)); JTerrainTexture textureWaterDeep = new JTerrainTexture(Loader.loadTexture(JFileUtils.GetPathToResFile("Terrain\\WaterDeep.png"))); JTerrainTexture textureWaterShallow = new JTerrainTexture(Loader.loadTexture(JFileUtils.GetPathToResFile("Terrain\\WaterShallow.png"))); JTerrainTexture textureSand = new JTerrainTexture(Loader.loadTexture(JFileUtils.GetPathToResFile("Terrain\\Sand.png"))); JTerrainTexture textureGrassNatural = new JTerrainTexture(Loader.loadTexture(JFileUtils.GetPathToResFile("Terrain\\GrassNatural.png"))); JTerrainTexture textureGrassLush = new JTerrainTexture(Loader.loadTexture(JFileUtils.GetPathToResFile("Terrain\\GrassLush.png"))); JTerrainTexture textureMountainNatural = new JTerrainTexture(Loader.loadTexture(JFileUtils.GetPathToResFile("Terrain\\MountainNatural.png"))); JTerrainTexture textureMountainRocky = new JTerrainTexture(Loader.loadTexture(JFileUtils.GetPathToResFile("Terrain\\MountainRocky.png"))); JTerrainTexture textureSnow = new JTerrainTexture(Loader.loadTexture(JFileUtils.GetPathToResFile("Terrain\\Snow.png"))); JTerrainTexturePack texturePack = new JTerrainTexturePack(); texturePack.AddTerrainTexture(textureWaterDeep, 0.1f); texturePack.AddTerrainTexture(textureWaterShallow, 0.15f); texturePack.AddTerrainTexture(textureSand, 0.18f); texturePack.AddTerrainTexture(textureGrassNatural, 0.35f); texturePack.AddTerrainTexture(textureGrassLush, 0.45f); texturePack.AddTerrainTexture(textureMountainNatural, 0.6f); texturePack.AddTerrainTexture(textureMountainRocky, 0.7f); texturePack.AddTerrainTexture(textureSnow, 0.8f); MasterRenderer = new JMasterRenderer(texturePack); WaterBuffer = new JWaterFrameBuffer(this); WaterShader = new JWaterShader(); waterTiles = new List <JWaterTile>(); WaterTile = new JWaterTile(400, -400, 8, textureWaterShallow); waterTiles.Add(WaterTile); waterRenderer = new JWaterRenderer(Loader, WaterShader, MasterRenderer.projectionMatrix, WaterBuffer, WaterTile); terrain = new JPerlinTerrain(0, -1, Loader, texturePack); Entity = new JBoundedEntity(TexturedModel, new Vector3(50, 0, -50), new Vector3(0, 0, 1), 0.1f, Loader); Entity2 = new JBoundedEntity(TexturedModel, new Vector3(100, 0, -50), new Vector3(0, 0, 1), 0.1f, Loader); EntityList = new List <JBoundedEntity>(); EntityList.Add(Entity); EntityList.Add(Entity2); // Generate Trees JEntityGenerator entityGenerator = new JEntityGenerator(Loader, terrain, WaterTile); StaticEntities = entityGenerator.GenerateTrees(); Camera = new JCameraFree(); picker = new JMousePicker(Camera, MasterRenderer.projectionMatrix, terrain, this); LastFrameTime = GetCurrentTime(); }