/// <summary> /// Initializes the program. /// </summary> public void InitProgram() { string texturesPath = "Model/Textures/"; string objPath = "Model/BodyParts/"; GL.GenBuffers(1, out ibo_elements); shaders.Add("default", new ShaderProgram("Model/Shaders/vs.glsl", "Model/Shaders/fs.glsl", true)); shaders.Add("textured", new ShaderProgram("Model/Shaders/vs_tex.glsl", "Model/Shaders/fs_tex.glsl", true)); activeShader = "textured"; // Add every boddy parts to the list of objects that will be displayed and load their respective textures. foreach (string s in Directory.EnumerateFiles(objPath)) { string partName = Path.GetFileNameWithoutExtension(s); ObjVolume obj = ObjVolume.LoadFromFile(s); textures.Add(partName, LoadImage(texturesPath + partName + ".png")); obj.TextureID = textures[partName]; objects.Add(obj); } camera.Position += new Vector3(0f, 0f, 4f); }
private ComplexObject LoadLamp() { ComplexObject lamp = new ComplexObject(); var lampModel = ObjVolume.LoadFromFile("Graphics\\Resources\\Models\\street_lamp.obj"); lampModel.Material = new Material(new Vector3(0.1f), new Vector3(1), new Vector3(0.2f), 5); lampModel.Position = new Vector3(0, 0, 0); lampModel.Rotation = new Vector3(0, -(float)Math.PI / 2, 0); lampModel.ColorData = Enumerable.Repeat(new Vector3(0.5f, 0.3f, 0.3f), lampModel.ColorDataCount).ToArray(); lampModel.Scale = new Vector3(0.15f, 0.15f, 0.15f); lampModel.CalculateNormals(); lamp.Primitives.Add(lampModel); Light lampLight = new Light(new Vector3(0, 2, 1.1f), new Vector3(1, 0.85f, 0.8f), 1, 0) { Rotation = new Vector3((float)Math.PI / 2, 0, 0), ConeAngle = 80f, ConeExponent = 5, Type = LightType.Spot }; lamp.Lights.Add(lampLight); return(lamp); }
private ComplexObject LoadRedCar() { ComplexObject car = new ComplexObject(); Camera carCamera = new Camera() { Name = "RedCarCamera", Position = new Vector3(0, 1.5f, 1), Rotation = new Vector3((float)Math.PI / 6, (float)Math.PI, 0), }; car.Cameras.Add(carCamera); var carModel = ObjVolume.LoadFromFile("Graphics\\Resources\\Models\\racing_car.obj"); var c = carModel.faces.Min(x => x.Item3.Position.Y); carModel.Material = new Material(new Vector3(0.1f), new Vector3(1), new Vector3(0.3f), 32); carModel.Position = new Vector3(0, -0.07f, 0); carModel.Rotation = new Vector3(0, 0.415f, 0); var red = new Vector3(0.8f, 0.1f, 0.1f); var blue = new Vector3(0.1f, 0.6f, 0.8f); var black = new Vector3(0, 0, 0); var white = new Vector3(0.9f, 0.9f, 1f); var colorData = new List <Vector3>(); colorData.AddRange(Enumerable.Repeat(black, 320 * 3)); colorData.AddRange(Enumerable.Repeat(red, 88 * 6)); colorData.AddRange(Enumerable.Repeat(white, 182 * 6)); colorData.AddRange(Enumerable.Repeat(red, 161 * 6)); colorData.AddRange(Enumerable.Repeat(blue, 10 * 6)); //glass colorData.AddRange(Enumerable.Repeat(blue, 4 * 6)); //light colorData.AddRange(Enumerable.Repeat(white, 168 * 6)); //wheel out colorData.AddRange(Enumerable.Repeat(black, 672)); //wheel in colorData.AddRange(Enumerable.Repeat(white, 168 * 6)); //wheel out colorData.AddRange(Enumerable.Repeat(black, 672)); //wheel in carModel.ColorData = colorData.ToArray(); carModel.Scale = new Vector3(0.003f, 0.003f, 0.003f); carModel.CalculateNormals(); car.Primitives.Add(carModel); Light light1 = new Light(new Vector3(0.1f, 0.1f, -0.5f), new Vector3(1, 1, 1), 1f, 0) { Rotation = new Vector3(0, (float)Math.PI * 15 / 16, 0), ConeAngle = 60, Type = LightType.Spot }; car.Lights.Add(light1); Light light2 = new Light(new Vector3(-0.1f, 0.1f, -0.5f), new Vector3(1, 1, 1), 1f, 0f) { Rotation = new Vector3(0, (float)Math.PI * 17 / 16, 0), ConeAngle = 60, Type = LightType.Spot }; car.Lights.Add(light2); return(car); }
private void LoadBalls(ComplexObject map) { var ball = ObjVolume.LoadFromFile("Graphics\\Resources\\Models\\ball.obj"); ball.Material = new Material(new Vector3(0.1f), new Vector3(1), new Vector3(0.2f), 5); ball.Position = new Vector3(0, -0.015f, 0); ball.ColorData = Enumerable.Repeat(new Vector3(0.33f, 0.33f, 0.33f), ball.ColorDataCount).ToArray(); ball.Scale = new Vector3(0.15f, 0.15f, 0.15f); map.Primitives.Add(ball); var ball2 = ball.Clone(); ball2.Position += new Vector3(0.6f, 0, 0); map.Primitives.Add(ball2); var ball3 = ball.Clone(); ball3.Position += new Vector3(-0.6f, 0, 0); map.Primitives.Add(ball3); for (int i = 0; i < 4; i++) { int x = 1; int y = 1; if (i / 2 == 0) { x = -x; } if (i % 2 == 0) { y = -y; } var ball5 = ball.Clone(); ball5.Position += new Vector3(x * 1.25f, 0, y * 0.2f); ball5.Scale *= new Vector3(0.5f, 0.5f, 0.5f); map.Primitives.Add(ball5); var ball4 = ball.Clone(); ball4.Position += new Vector3(x * 1.05f, 0, y * 0.55f); ball4.Scale *= new Vector3(0.5f, 0.5f, 0.5f); map.Primitives.Add(ball4); var ball6 = ball.Clone(); ball6.Position += new Vector3(x * 0.2f, 0, y * 0.7f); ball6.Scale *= new Vector3(0.5f, 0.5f, 0.5f); map.Primitives.Add(ball6); var ball7 = ball.Clone(); ball7.Position += new Vector3(x * 0.65f, 0, y * 0.7f); ball7.Scale *= new Vector3(0.5f, 0.5f, 0.5f); map.Primitives.Add(ball7); var ball8 = ball.Clone(); ball8.Position += new Vector3(x * 0.8f, 0, y * 0.7f); ball8.Scale *= new Vector3(0.5f, 0.5f, 0.5f); map.Primitives.Add(ball6); } }