public SkeletonHuman() { torso = new Bone(null, ModelControl.getModel("human/torso"), 0); head = new Bone(torso, ModelControl.getModel("human/head"), 0); legUpperLeft = new Bone(torso, ModelControl.getModel("human/upperLeg"), 0); legLowerLeft = new Bone(legUpperLeft, ModelControl.getModel("human/lowerLeg"), 0); legUpperRight = new Bone(torso, ModelControl.getModel("human/upperLeg"), 0); legLowerRight = new Bone(legUpperRight, ModelControl.getModel("human/lowerLeg"), 0); armUpperLeft = new Bone(torso, ModelControl.getModel("human/upperArm"), 0); armLowerLeft = new Bone(armUpperLeft, ModelControl.getModel("human/lowerArm"), 0); armUpperRight = new Bone(torso, ModelControl.getModel("human/upperArm"), 0); armLowerRight = new Bone(armUpperRight, ModelControl.getModel("human/lowerArm"), 0); footLeft = new Bone(legLowerLeft, ModelControl.getModel("human/foot"), 0); footRight = new Bone(legLowerRight, ModelControl.getModel("human/foot"), 0); updateMatrices(); bones.Add(torso); bones.Add(head); bones.Add(legUpperLeft); bones.Add(legLowerLeft); bones.Add(legUpperRight); bones.Add(legLowerRight); bones.Add(armUpperLeft); bones.Add(armLowerLeft); bones.Add(armUpperRight); bones.Add(armLowerRight); bones.Add(footLeft); bones.Add(footRight); }
void onLoad(object sender, EventArgs e) { Console.Out.WriteLine("onLoad"); gameWindow.VSync = VSyncMode.On; Console.WriteLine("OpenGL version: {0}", GL.GetString(StringName.Version)); Console.WriteLine("Current GLSL version: {0}", GL.GetString(StringName.ShadingLanguageVersion)); TryGL.Call(() => GL.ClearColor(0.2f, 0.0f, 0.2f, 1.0f)); TryGL.Call(() => GL.Enable(EnableCap.DepthTest)); TryGL.Call(() => GL.Enable(EnableCap.CullFace)); TryGL.Call(() => GL.CullFace(CullFaceMode.Back)); TryGL.Call(() => GL.Enable(EnableCap.Blend)); resetBlending(); TryGL.Call(() => GL.BlendEquation(BlendEquationMode.FuncAdd)); int VAO = GL.GenVertexArray(); GL.BindVertexArray(VAO); shader = new ShaderProgram(); shader.LoadAndCompileProrgam(dirShaders + "world.vert.glsl", dirShaders + "world.frag.glsl"); TextureControl.loadTextures(); heavyThread.Start(); loadedMap = new Map(this, "debugMap"); player = new ActorPlayer(); loadedMap.newActor(player); //loadedMap.newActor(new ActorPlayer(loadedMap.actorMaker)); //loadedMap.newActor(new ActorPlayer(loadedMap.actorMaker)); matrixProjection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver2, (float)gameWindow.Width / (float)gameWindow.Height, NEAR, FAR); matrixModel = Matrix4.Identity; matrixCamera = Matrix4.Identity; player.position.X = 64; player.position.Y = 128; player.position.Z = 64; player.target = player.position; hud.onLoad(); markerModel = ModelControl.getModel("marker"); }
void consoleExecute(string line) { if (line.StartsWith("p")) { string[] words = line.Split(' '); if (words.Length == 3) { string modelName = words[1]; Prop p; if (words[0].Contains("i")) { p = new PropInteractable(ModelControl.getModel(modelName), words[0].Contains("s")); } else { p = new Prop(ModelControl.getModel(modelName), words[0].Contains("s")); } Vector3 hit; Chunk chunk; if (findTerrainWithRay(ref lookOrigin, ref lookDirection, out hit, out chunk)) { p.position = hit; p.setupModelMatrix(); p.textureIndex = TextureControl.arrayProps.names.IndexOf(words[2]); chunk.props.Add(p); Console.WriteLine("Success"); return; } Console.WriteLine("Failed: Mouse in sky"); return; } } Console.WriteLine("Unknown command"); }
public static void loadChunk(Chunk chunk) { Console.WriteLine("Loading Chunk: {0}, {1}", chunk.Location.X, chunk.Location.Y); string path; string letters = "abcdefghijklmnopqrstuvwxyz"; bool loadedLetter = true; for (int i = 0; i < 26 && loadedLetter; i++) { loadedLetter = false; for (int fc = 0; fc < 2; fc++) { for (int st = 0; st < 2; st++) { path = Game.dirMaps + chunk.map.name + "/htmp."; path += chunk.Location.X.ToString(); path += "."; path += chunk.Location.Y.ToString(); path += "."; path += fc == 0 ? "f" : "c"; //floor, ceiling path += "."; path += st == 0 ? "s" : "d"; //solid, decorative path += "."; path += letters[i]; path += ".png"; try { if (File.Exists(path)) { Console.WriteLine("Try to load Heightmap: {0}", path); using (Image img = Image.FromFile(path)) { using (Bitmap bmp = new Bitmap(img)) { if (bmp.Width != Chunk.CHUNK_SIZE_X + 2 || bmp.Height != Chunk.CHUNK_SIZE_Z + 2) { throw new FormatException(String.Format("Image size not equal to {0}x{1}, is instead {2}x{3}", Chunk.CHUNK_SIZE_X + 2, Chunk.CHUNK_SIZE_Z + 2, bmp.Width, bmp.Height)); } HeightMap htmp = new HeightMap(letters[i]); htmp.isFloor = fc == 0; htmp.isSolid = st == 0; htmp.min = float.MaxValue; htmp.max = float.MinValue; for (int x = 0; x < Chunk.CHUNK_SIZE_X + 2; x++) { for (int z = 0; z < Chunk.CHUNK_SIZE_Z + 2; z++) { Color c = bmp.GetPixel(x, z); htmp.tiles[x, z] = c.R; htmp.heights[x, z] = c.B / chunk.resolution; htmp.min = Math.Min(htmp.heights[x, z], htmp.min); htmp.max = Math.Max(htmp.heights[x, z], htmp.max); } } chunk.terrain.Add(htmp); loadedLetter = true; Console.WriteLine("Loaded Heightmap: {0}", path); } } } } catch (OutOfMemoryException) { Console.WriteLine("Out of memory"); return; } } } } path = Game.dirMaps + chunk.map.name + "/props."; path += chunk.Location.X.ToString(); path += "."; path += chunk.Location.Y.ToString(); path += ".txt"; if (File.Exists(path)) { Console.WriteLine("Loading Prop File: {0}", path); Dictionary <string, string> modelTex = new Dictionary <string, string>(); string[] lines = File.ReadAllLines(path); foreach (string line in lines) { if (line.StartsWith("set ", StringComparison.Ordinal)) { string[] split = line.Split(' '); if (split[1].Equals("tex") && split.Length == 4) { modelTex[split[2]] = split[3]; } } else if (line.StartsWith("p", StringComparison.Ordinal)) { string[] split = line.Split(' '); string name = split[1]; float x = float.Parse(split[2]); float z = float.Parse(split[4]); float y = 0; bool yset = false; foreach (HeightMap htmp in chunk.terrain) { if (htmp.letter == split[3][0]) { htmp.getHeightAtPosition(new Vector2(x, z), out y); if (split[3].Substring(1).Length > 0) { y += float.Parse(split[3].Substring(1)); } yset = true; break; } } if (!yset) { y = float.Parse(split[3]); } float xr = MathHelper.DegreesToRadians(float.Parse(split[5])); float yr = MathHelper.DegreesToRadians(float.Parse(split[6])); float zr = MathHelper.DegreesToRadians(float.Parse(split[7])); Prop p; if (split[0].Contains("i")) { p = new PropInteractable(ModelControl.getModel(name), split[0].Contains("s")); } else { p = new Prop(ModelControl.getModel(name), split[0].Contains("s")); } p.position = new Vector3(x, y, z); p.rotation = new Vector3(xr, yr, zr); p.setupModelMatrix(); p.textureIndex = TextureControl.arrayProps.names.IndexOf(modelTex[p.model.name]); //p.setupFrame(); after model loads chunk.props.Add(p); Console.WriteLine("New prop at: {0}", p.position); } } Console.WriteLine("Loaded Prop File: {0}", path); } Console.WriteLine("Loaded Chunk: {0}, {1}", chunk.Location.X, chunk.Location.Y); }