Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: core/World.cs
- ===================================================================
- --- core/World.cs (revision 76)
- +++ core/World.cs (working copy)
- @@ -10,6 +10,10 @@
- using System.Diagnostics;
- using System.Windows.Forms;
- using System.Windows;
- +using PF1S3._10.core.utils;
- +using PF1S3._10.core.CML.converter;
- +using System.Drawing;
- +using System.Drawing.Imaging;
- namespace PF1S3._10.core
- {
- @@ -103,12 +107,48 @@
- /// <summary>Pomjeraj broda gore/dole.</summary>
- private float shipMove;
- + /// <summary>
- + /// Parser loader
- + /// </summary>
- + private ObjLoaderFactory loader;
- + /// <summary>
- + /// Parser data
- + /// </summary>
- + private ParsedData pData;
- +
- /// <summary>Kamera.</summary>
- private Camera camera = null;
- + /// <summary>
- + /// VBO buffers
- + /// </summary>
- + private int[] mVertexBuffer = new int[1];
- + private int[] mTextureBuffer = new int[1];
- + private int[] mIndexBuffer = new int[1];
- + private int[] mNormalBuffer = new int[1];
- + /// <summary>
- + /// Texture objects
- + /// </summary>
- + public enum TextureType { Water = 0, Sand, Brick, Rust };
- + /// <summary>
- + /// Texture count
- + /// </summary>
- + private readonly int m_textureCount = Enum.GetNames(typeof(TextureType)).Length;
- +
- + /// <summary>
- + /// Texture IDs
- + /// </summary>
- + private int[] m_textures = null;
- + private int[] m_tent_textures = null;
- +
- + /// <summary>
- + /// Texture resources
- + /// </summary>
- + private string[] m_textureFiles = { "..//..//images//water.jpg", "..//..//images//sand.jpg", "..//..//images//brick.jpg", "..//..//images//rust.jpg" };
- +
- #endregion Atributi
- #region Properties
- @@ -214,13 +254,24 @@
- this.m_scene_jeep = new AssimpScene(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "3D_Models\\Jeep"), "Jeep.3DS");
- // Sator preko Assimp-a
- - //this.m_scene_tent = new AssimpScene(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "3D_Models\\Tent"), "soccerball.obj");
- + // this.m_scene_tent = new AssimpScene(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "3D_Models\\Tent"), "Tent.obj");
- + // Parser [start]
- + loader = new ObjLoaderFactory();
- + var parser = loader.Create();
- + FileStream fileStream = new FileStream(@"Tent.obj", FileMode.Open);
- + var result = parser.Load(fileStream);
- + pData = new ParsedData(result);
- + m_tent_textures = new int[1];
- + // Parser [end]
- +
- // Korisnicka inicijalizacija OpenGL parametara
- Initialize();
- // Podesi projekciju i viewport
- Resize();
- +
- + // testParser();
- }
- #endregion
- @@ -232,9 +283,7 @@
- Gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Boja pozadine
- // Pozicioniraj kameru
- - camera.Position(0.0f, 0.0f, 1.0f,
- - 0.0f, 0.0f, 0.0f,
- - 0.0f, 1.0f, 0.0f);
- + camera.Position(0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
- Gl.glEnable(Gl.GL_DEPTH_TEST); // Ukljuci depth testing
- Gl.glEnable(Gl.GL_CULL_FACE); // Sakrivanje nalicja poligona
- @@ -255,6 +304,86 @@
- // Color tracking, ukljucivanje i podesavanje
- Gl.glEnable(Gl.GL_COLOR_MATERIAL);
- Gl.glColorMaterial(Gl.GL_FRONT, Gl.GL_AMBIENT_AND_DIFFUSE);
- +
- + // Texture
- + Gl.glEnable(Gl.GL_TEXTURE_2D);
- + Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_DECAL);
- +
- + Gl.glGenTextures(m_textureCount, m_textures);
- +
- + Bitmap image;
- + Rectangle rect;
- + BitmapData imageData;
- +
- + for (int i = 0; i < m_textureCount; ++i)
- + {
- + // Pridruzi teksturu odgovarajucem identifikatoru
- + Gl.glBindTexture(Gl.GL_TEXTURE_2D, m_textures[i]);
- +
- + // Ucitaj sliku i podesi parametre teksture
- + image = new Bitmap(m_textureFiles[i]);
- + // rotiramo sliku zbog koordinantog sistema opengl-a
- + image.RotateFlip(RotateFlipType.RotateNoneFlipY);
- + rect = new Rectangle(0, 0, image.Width, image.Height);
- + // RGBA format (dozvoljena providnost slike tj. alfa kanal)
- + imageData = image.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
- +
- + Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, (int)Gl.GL_RGBA8, image.Width, image.Height, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, imageData.Scan0);
- +
- + //TODO 3: texture wrapping GL_REPEAT i linearno filtriranje
- + Gl.glTexParameteri((int)Gl.GL_TEXTURE_2D, (int)Gl.GL_TEXTURE_MIN_FILTER, (int)Gl.GL_LINEAR); // Linear Filtering
- + Gl.glTexParameteri((int)Gl.GL_TEXTURE_2D, (int)Gl.GL_TEXTURE_MAG_FILTER, (int)Gl.GL_LINEAR); // Linear Filtering
- + Gl.glTexParameteri((int)Gl.GL_TEXTURE_2D, (int)Gl.GL_TEXTURE_WRAP_S, (int)Gl.GL_REPEAT);
- + Gl.glTexParameteri((int)Gl.GL_TEXTURE_2D, (int)Gl.GL_TEXTURE_WRAP_T, (int)Gl.GL_REPEAT);
- +
- + image.UnlockBits(imageData);
- + image.Dispose();
- + }
- +
- + Gl.glGenTextures(1, m_tent_textures);
- + Gl.glBindTexture(Gl.GL_TEXTURE_2D, m_tent_textures[0]);
- +
- + image = new Bitmap(Path.Combine(tent_path, m_tent.findTextureFile()));
- +
- + BitmapData textureData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
- + Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, textureData.Width, textureData.Height, 0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, textureData.Scan0);
- +
- + // Podesavanje filtriranja teksture.
- + Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
- + Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
- + Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT);
- + Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT);
- +
- + image.UnlockBits(textureData);
- + image.Dispose();
- +
- + //texture
- + Gl.glGenBuffers(1, mTextureBuffer);
- + Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, mTextureBuffer[0]);
- + Gl.glBufferData(Gl.GL_ARRAY_BUFFER,
- + (IntPtr)(pData.textures.Length * sizeof(float)), pData.textures, Gl.GL_STATIC_DRAW);
- +
- + //normale
- + Gl.glGenBuffers(1, mNormalBuffer);
- + Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, mNormalBuffer[0]);
- + Gl.glBufferData(Gl.GL_ARRAY_BUFFER,
- + (IntPtr)(pData.normals.Length * sizeof(float)), pData.normals, Gl.GL_STATIC_DRAW);
- +
- + //vertexi
- + Gl.glGenBuffers(1, mVertexBuffer);
- + Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, mVertexBuffer[0]);
- + Gl.glBufferData(Gl.GL_ARRAY_BUFFER,
- + (IntPtr)(pData.vertices.Length * sizeof(float)), pData.vertices, Gl.GL_STATIC_DRAW);
- +
- + //indexi
- + Gl.glGenBuffers(1, mIndexBuffer);
- + Gl.glBindBuffer(Gl.GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer[0]);
- + Gl.glBufferData(Gl.GL_ELEMENT_ARRAY_BUFFER,
- + (IntPtr)(pData.vertexIndices.Length * sizeof(uint)), pData.vertexIndices, Gl.GL_STATIC_DRAW);
- +
- + //unbindujemo
- + Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, 0);
- + Gl.glBindBuffer(Gl.GL_ELEMENT_ARRAY_BUFFER, 0);
- }
- public void Resize()
- @@ -491,6 +620,14 @@
- cf_flag = true; // setujemo flag nakon iscrtavanja teksta
- }
- + /// <summary>
- + /// Initialize textures
- + /// </summary>
- + private void initTextures()
- + {
- +
- + }
- +
- #endregion
- #region IDisposable metode
- @@ -518,31 +655,60 @@
- #region Metoda za testiranje parsera
- - public void init()
- + public void testParser()
- {
- - var pi = new ObjLoaderFactory();
- - var objLoader = pi.Create();
- + var objLoaderFactory = new ObjLoaderFactory();
- + var objLoader = objLoaderFactory.Create();
- + FileStream fileStream = new FileStream(@"Tent.obj", FileMode.Open);
- + var result = objLoader.Load(fileStream);
- - FileStream str = new FileStream(@"model.obj", FileMode.Open);
- + var log = new sLog("Log initiated!");
- - var result = objLoader.Load(str);
- -
- foreach (var v in result.Vertices)
- {
- Console.WriteLine("Vertex X: " + v.X + " " + " Y: " + v.Y + " " + " Z: " + v.Z);
- + log.LogWrite("Vertex X: " + v.X + " " + " Y: " + v.Y + " " + " Z: " + v.Z);
- }
- foreach (var n in result.Normals)
- {
- Console.WriteLine("Normal X: " + n.X + " " + " Y: " + n.Y + " " + " Z: " + n.Z);
- + log.LogWrite("Normal X: " + n.X + " " + " Y: " + n.Y + " " + " Z: " + n.Z);
- }
- foreach (var g in result.Groups)
- {
- Console.WriteLine("Faces: " + g.Faces + " - Name: " + g.Name);
- + log.LogWrite("Faces: " + g.Faces + " - Name: " + g.Name);
- }
- + foreach (var t in result.Textures)
- + Console.WriteLine("Texture X: " + t.X + " " + " Texture Y: " + t.Y);
- +
- + Console.WriteLine("MATERIALS INFO!");
- + foreach (var m in result.Materials)
- + {
- + Console.WriteLine("Name: " + m.Name + System.Environment.NewLine + " Ambient color [Ka] (x, y, z): (" + m.AmbientColor.X + ", " + m.AmbientColor.Y + ", " + m.AmbientColor.Z + ")" + System.Environment.NewLine + " Ambient color texture map: " + m.AmbientTextureMap + System.Environment.NewLine + " Diffuse color [Kd] (x, y, z): (" + m.DiffuseColor.X + ", " + m.DiffuseColor.Y + ", " + m.DiffuseColor.Z + ")" + System.Environment.NewLine + " Diffuese color texture map: " + m.DiffuseTextureMap + System.Environment.NewLine + " Specular color [Ks] (x, y, z): " + m.SpecularColor.X + ", " + m.SpecularColor.Y + ", " + m.SpecularColor.Z + System.Environment.NewLine + " Specular color coef [Ns] (0 - 1000): " + m.SpecularCoefficient + System.Environment.NewLine + " Specular color texture map: " + m.SpecularTextureMap + System.Environment.NewLine + " Specular color highlight texture map [map_Ns]: " + m.SpecularHighlightTextureMap + System.Environment.NewLine + " Bump texture map: " + m.BumpMap + System.Environment.NewLine + " Dissolve factor (pseudo-transparency) [d]: " + m.Transparency + System.Environment.NewLine + " Refraction index [Ni]: " + m.RefractionIndex + System.Environment.NewLine + " Illum (0, 1 or 2): " + m.IlluminationModel);
- + }
- +
- + ParsedData pd = new ParsedData(result);
- +
- + /* for (int i = 0; i < pd.vertices.Length; i++)
- + Console.WriteLine("float vertices: " + pd.vertices[i]);
- +
- + for (int i = 0; i < pd.normals.Length; i++)
- + Console.WriteLine("float normals: " + pd.normals[i]);
- +
- + for (int i = 0; i < pd.textures.Length; i++)
- + Console.WriteLine("float textures: " + pd.textures[i]); */
- +
- + for (int i = 0; i < pd.vertexIndices.Length; i++)
- + Console.WriteLine("float vertexIndices: " + pd.vertexIndices[i]);
- +
- Console.ReadLine();
- +
- +
- +
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement