/// <summary> /// Draw a line with specific value /// </summary> /// <param name="start"></param> /// <param name="end"></param> public void DrawLine(FxVector2f start, FxVector2f end, float value) { var dx = Math.Abs(end.x - start.x); var dy = Math.Abs(end.y - start.y); var sx = (start.x < end.x) ? 1 : -1; var sy = (start.y < end.y) ? 1 : -1; var err = dx - dy; int x0 = (int)start.x; int y0 = (int)start.y; int x1 = (int)end.x; int y1 = (int)end.y; while(!((x0 == x1) && (y0 == y1))) { this[x0, y0] = value; var e2 = 2 * err; if (e2 > -dy) { err -= dy; x0 += sx; } if ((x0 == x1) && (y0 == y1)) { this[x0, y0] = value; break; } if (e2 < -dx) { err -= dx; y0 += sy; } } }
public Form1() { InitializeComponent(); resize = new FxVector2f(targetRes.x / (float)origRes.x, targetRes.y / (float)origRes.y); // create a shop shopPlan = FxMatrixF.Load("Katopsi.jpg", ColorSpace.Grayscale); shopPlan = shopPlan.Resize(targetRes.x, targetRes.y); shop = new Shop("Unisol", shopPlan); // simulation = new SimulationSimple(shop, 10, simulationMethod1); simulationMethod2_Setup(); simulation = new SimulationSimple(shop, 1, simulationMethod2); // Defind entrance for the shop shop.entrancePositionsDirection.Add(new Tuple<FxVector2f, FxVector2f>(new FxVector2f(1800 * resize.x, 500 * resize.y), new FxVector2f(-1, 0))); // load a person image for the moving image imPerson = FxMatrixF.Load("person.jpg", ColorSpace.Grayscale); // imPerson.Exec(x => (x > 0.1) ? 0 : 1); imPerson.MedianFilt(); imPersonMask = imPerson < 0.5f; // Init the matrix to be HD mat = new FxMatrixF(targetRes.x, targetRes.y); mat.DrawMatrix(shopPlan, new FxVector2f(0, 0), new FxVector2f(mat.Width, mat.Height), FxMatrixF.DrawInterpolationMethod.NearestNeighbor); // Add image element to canvas to showing the matrix im = new ImageElement(mat); canvas1.AddElement(im, true); }
public SerialCamera(String portName, FxVector2f Position, FxVector2f Size) { // init the serial port serialPort = new SerialPort(); // Set the read/write timeouts serialPort.ReadTimeout = -1; serialPort.WriteTimeout = -1; serialPort.Parity = Parity.None; serialPort.DataBits = 8; serialPort.StopBits = StopBits.Two; serialPort.Handshake = Handshake.None; serialPort.BaudRate = 921600; serialPort.NewLine = "\r\n"; serialPort.PortName = portName; // Link the information of the camera to the place this.Position = Position; this.Size = Size; }
private void button_create_mesh_Click(object sender, EventArgs e) { if (firstTime) { firstTime = false; AddSphete(100, new Vector3(600, 80, 600), new Vector3(2, 2, 2), "Resources/lady2.jpg"); AddSphete(100, new Vector3(1100, 80, 2000), new Vector3(3, 3, 3), "Resources/lady.jpg"); ///////////////////////////////////////////////////////////// Init the Shader // create the shader ShaderSimple sh = new ShaderSimple(); /// add the shader to the list ShaderManager.AddShader("Shader12", sh); // add the textures for the shader sh.SetTexture("Resources/tmima.jpg", TextureType.Diffuse); sh.SetTexture("Resources/tmima.jpg", TextureType.Lightmap); sh.SetTexture("Resources/height.jpg", TextureType.Heightmap); sh.SetVariables(new Vector3(1, 1, 1), ShaderViariables.Ambient); List<Polygon> polygonList = new List<Polygon>(); FxVector2f p1 = new FxVector2f(0, 0); FxVector2f p2 = new FxVector2f(0, 100); FxVector2f p3 = new FxVector2f(100, 100); FxVector2f p4 = new FxVector2f(100, 0); float u1 = 0; float v1 = 0; Vertex ver1 = new Vertex(p1.X, -1, p1.Y, 0, 0, 0, u1, v1); u1 = 0; v1 = 1; Vertex ver2 = new Vertex(p2.X, -1, p2.Y, 0, 0, 0, u1, v1); u1 = 1; v1 = 1; Vertex ver3 = new Vertex(p3.X, -1, p3.Y, 0, 0, 0, u1, v1); u1 = 1; v1 = 0; Vertex ver4 = new Vertex(p4.X, -1, p4.Y, 0, 0, 0, u1, v1); polygonList.Add(new Polygon(ver1, ver2, ver3)); polygonList.Add(new Polygon(ver1, ver3, ver4)); ///////////////////////////////////////////////////////////// Init the Mesh /// make a new mesh Mesh mesh = new Mesh(); /// set to the new mesh the shader mesh.m_shader = ShaderManager.GetExistShader("Shader12"); // set the position mesh.SetPosition(new Vector3(0, 0, 0)); // scale it mesh.SetScale(new Vector3(40, 40, 40)); // add the polygons on mesh foreach (Polygon poly in polygonList) { // add the polygons to the mesh mesh.AddPolygon(poly, false); } /// create the mesh and download it to the card mesh.CreateMesh(); /// add the mesh to the engine mesh list Engine.g_MeshManager.AddMesh(mesh); sh.SetVariables(new Vector3(1, 1, 1), ShaderViariables.Ambient); ///////////////////////////////////////////////////////////// Change Camera position // Engine.g_MoveCamera. Engine.g_MoveCamera.SetViewParams(new Vector3(4500, 3500, 2000), new Vector3(200, 0, 200)); //////////////////////////////////////////////////// t.Interval = 200; t.Tick += t_Tick; t.Enabled = true; } else { if (selected_sphere != null) { Engine.g_MoveCamera.SetViewParams(selected_sphere.center, new Vector3(200, 0, 200)); selected_sphere.sh.SetVariables(new Vector3(1, 1, 1), ShaderViariables.Ambient); t.Enabled = false; } } }
/// <summary> /// Get the minimum distance from specific point. /// </summary> /// <param name="point"></param> /// <returns></returns> public float GetMinDist(FxVector2f point) { float minDist = float.MaxValue; FxVector2f tmpPoint = StartPoint; for (int i = 0; i < Count; i++) { var dist = tmpPoint.Distance(ref point); if (dist < minDist) minDist = dist; tmpPoint.x += ListComplex[i].r; tmpPoint.y += ListComplex[i].i; } return minDist; }
public FxContourChain(float x, float y) { // set the start point StartPoint = new FxVector2f(x, y); prevPoint = new FxVector2f(x, y); // create the complex list ListComplex = new List<FxComplexF>(); RectStart = new FxVector2f(x, y); RectSize = new FxVector2f(0, 0); }
/// <summary> /// Draw external matrix to this matrix. /// </summary> /// <param name="matrix">The matrix that store the copied image</param> /// <param name="start"></param> /// <param name="size"></param> public void DrawMatrix(FxMatrixF matrix, FxVector2f start, FxVector2f size, DrawInterpolationMethod method) { int h = matrix.Height; int w = matrix.Width; float stepW = (float)(w-1) / size.x; float stepH = (float)(h-1) / size.y; start.x = (float)Math.Floor(start.x); start.y = (float)Math.Floor(start.y); FxVector2f end = start + size; if (end.x > Width) end.x = Width - 1; if (end.y > Height) end.y = Height - 1; switch (method) { case DrawInterpolationMethod.NearestNeighbor: Parallel.For((int)start.y, (int)end.y, (j) => { int yp = (int)Math.Floor((j - start.y) * stepH); for (int i = (int)start.x, ix = 0; i < end.x; i++, ix++) { int xp = (int)Math.Floor(ix * stepW); this[i, j] = matrix[xp, yp]; } }); break; case DrawInterpolationMethod.Linear: Parallel.For((int)start.y, (int)end.y, (j) => { float yp = (j - start.y) * stepH; for (int i = (int)start.x, ix = 0; i < end.x; i++, ix++) { float xp = ix * stepW; if (xp < matrix.Width - 1) this[i, j] = matrix.Sample(xp, yp); } }); break; case DrawInterpolationMethod.Cubic: Parallel.For((int)start.y, (int)end.y, (j) => { float yp = (j - start.y) * stepH; for (int i = (int)start.x, ix = 0; i < end.x; i++, ix++) { float xp = ix * stepW; if (xp < matrix.Width - 1) this[i, j] = matrix.SampleCubic(xp, yp); } }); break; } }
private void addSamplePlaneToolStripMenuItem_Click(object sender, EventArgs e) { ///////////////////////////////////////////////////////////// Init the Shader // create the shader ShaderSimple sh = new ShaderSimple(); /// add the shader to the list ShaderManager.AddShader("Shader10", sh); // add the textures for the shader sh.SetTexture("Resources/diffuse.jpg", TextureType.Diffuse); sh.SetTexture("Resources/lightmap.jpg", TextureType.Lightmap); sh.SetTexture("Resources/height.jpg", TextureType.Heightmap); sh.SetVariables(new Vector3(1, 1, 1), ShaderViariables.Ambient); ///////////////////////////////////////////////////////////// Init the polygons of mesh List<Polygon> polygonList = new List<Polygon>(); FxVector2f p1 = new FxVector2f(0, 0); FxVector2f p2 = new FxVector2f(0, 100); FxVector2f p3 = new FxVector2f(100, 100); FxVector2f p4 = new FxVector2f(100, 0); float u = 0; float v = 0; Vertex ver1 = new Vertex(p1.X, 1, p1.Y, 0, 0, 0, u, v); u = 0; v = 1; Vertex ver2 = new Vertex(p2.X, 1, p2.Y, 0, 0, 0, u, v); u = 1; v = 1; Vertex ver3 = new Vertex(p3.X, 1, p3.Y, 0, 0, 0, u, v); u = 1; v = 0; Vertex ver4 = new Vertex(p4.X, 1, p4.Y, 0, 0, 0, u, v); polygonList.Add(new Polygon(ver1, ver2, ver3)); polygonList.Add(new Polygon(ver1, ver3, ver4)); ///////////////////////////////////////////////////////////// Init the Mesh /// make a new mesh Mesh mesh = new Mesh(); /// set to the new mesh the shader mesh.m_shader = ShaderManager.GetExistShader("Shader10"); // set the position mesh.SetPosition(new Vector3()); // scale it mesh.SetScale(new Vector3(10, 10, 5)); // add the polygons on mesh foreach (Polygon poly in polygonList) { // add the polygons to the mesh mesh.AddPolygon(poly, false); } /// create the mesh and download it to the card mesh.CreateMesh(); /// add the mesh to the engine mesh list Engine.g_MeshManager.AddMesh(mesh); ///////////////////////////////////////////////////////////// Change Camera position Engine.g_MoveCamera.SetViewParams(new Vector3(2000, 2000, 200), new Vector3(0, 0, 0)); }
public CanvasMouseClickEventArgs(MouseEventArgs mouseClick, CanvasElements hitElement, FxVector2f hitPoint, FxVector2f insidePoint) { this.mouseClick = mouseClick; this.hitElement = hitElement; this.hitPoint = hitPoint; this.insidePoint = insidePoint; }
public Rectangle(float start_x, float start_y, float end_x, float end_y) { m_start = new FxVector2f(start_x, start_y); m_end = new FxVector2f(end_x, end_y); }
public Rectangle(FxVector2f start, FxVector2f end) { m_start = start; m_end = end; }
public void simulationMethod2(List<Person> personList) { lock (shop) { FxVector2f filtered = new FxVector2f(); // move the blobs in smallest distance target foreach (var person in personList) { // move person // check the person position and moving FxVector2f nextPosition = person.Position + person.Speed * person.Direction; float value = shopPlan[person.Position]; float speedChange = (rand.Next(100) > 50 ? -0.2f : +0.2f) * rand.Next(1000) / 1000.0f; // select random target in the start if (person.Target.x == 0 && person.Target.y == 0) { person.Target = targetList.RandomSelectStruct(); } // check if the person arave to select target if (person.Target.Distance(ref person.Position) < 10) { if (person.waitInTarget && person.waitTime.ElapsedMilliseconds > person.waitTimeMs) { person.waitTime.Stop(); // select random target person.Target = targetList.RandomSelectStruct(); } else if (!person.waitInTarget) { person.waitInTarget = true; // select a new random wait time 0-2Sec person.waitTimeMs = (long)(rand.NextDouble() * 2000); person.waitTime = new Stopwatch(); person.waitTime.Start(); } else { continue; } } // We are 1% "lucky" change the target if(rand.Next(100) >= 100) { // select random target person.Target = targetList.RandomSelectStruct(); } // select the direction that you can go to the target var targetDirection = person.Target - nextPosition; float directionAngleChange = (rand.Next(100) >= 99 ? 0 : 1) * (-(float)person.Direction.Angle(ref targetDirection)); /* + (rand.Next(100) >= 50 ? -1 : +1)* // Select randomly the left right. (float)(rand.NextDouble() * Math.PI *(20f/360f)); // select the angle */ directionAngleChange *= (float)rand.NextDouble()/2; if (Math.Abs(directionAngleChange)>Math.PI/2) { Console.WriteLine("------------------------->"); /* if (directionAngleChange < 0) directionAngleChange = (float)(- directionAngleChange - Math.PI / 2); else directionAngleChange = (float)(- directionAngleChange + Math.PI / 2); * */ directionAngleChange = -directionAngleChange; } if (directionAngleChange!=0) { Console.WriteLine(directionAngleChange); } if (float.IsNaN(directionAngleChange)) directionAngleChange = 0; if (nextPosition.x > 0 && nextPosition.y > 0 && nextPosition.x < shopPlan.Width && nextPosition.y < shopPlan.Height) { float valueNext = shopPlan[nextPosition]; if (valueNext > 0.9f) { // calculate next position person.Path.Add(nextPosition); // calculate the position with kalman to pe more smooth the transaction filtered.x = person.kalmanX.Update(nextPosition.x, 50); filtered.y = person.kalmanY.Update(nextPosition.y, 50); person.Position = nextPosition; person.PathKalman.Add(filtered); } else { directionAngleChange = (rand.Next(100) > 50 ? -1 : +1) * (float)(Math.PI); // select random target person.Target = targetList.RandomSelectStruct(); } } else directionAngleChange = (rand.Next(100) > 50 ? -1 : +1) * (float)(Math.PI); // update the speed person.Speed += speedChange; // limit the max speed if (person.Speed > 8f) person.Speed = 8; // limit the min speed if (person.Speed < 1f) person.Speed = 1; // rotate the direction person.Direction.Rotation(directionAngleChange); } } }
private void simulationMethod1(List<Person> personList) { lock (shop) { FxVector2f filtered = new FxVector2f(); // move the blobs in random directions foreach (var person in personList) { float speedChange = 1 + (rand.Next(100) > 50 ? -0.1f : +0.1f) * rand.Next(1000) / 1000.0f; float directionAngleChange = (rand.Next(100) >= 90 ? 0 : 1) * // Select randomly if we are going to change the angle (rand.Next(100) >= 50 ? -1 : +1) * // Select randomly the left right. (float)(rand.NextDouble() * Math.PI / 8.0f); // select the angle // move person // check the person position and moving FxVector2f nextPosition = person.Position + person.Speed * person.Direction; float value = shopPlan[person.Position]; if (nextPosition.x > 0 && nextPosition.y > 0 && nextPosition.x < shopPlan.Width && nextPosition.y < shopPlan.Height) { float valueNext = shopPlan[nextPosition]; if (valueNext > 0.9f) { // calculate next position person.Path.Add(nextPosition); // calculate the position with kalman to pe more smooth the transaction filtered.x = person.kalmanX.Update(nextPosition.x, 50); filtered.y = person.kalmanY.Update(nextPosition.y, 50); person.Position = filtered; person.PathKalman.Add(filtered); } else directionAngleChange = (rand.Next(100) > 50 ? -1 : +1) * (float)(rand.NextDouble() * Math.PI); } else directionAngleChange = (rand.Next(100) > 50 ? -1 : +1) * (float)(rand.NextDouble() * Math.PI); // update the speed person.Speed *= speedChange; // limit the max speed if (person.Speed > 6f) person.Speed = 6; // rotate the direction person.Direction.Rotation(directionAngleChange); } } }
private void CreateVideo() { // Start a new video file VideoFileWriter vfw = new VideoFileWriter(); vfw.Open("Test.avi", mat.Width, mat.Height, 30, VideoCodec.Default); // create an image that we are going to use for the buffering of the next frame Bitmap bitmap = new Bitmap(mat.Width, mat.Height); FxMaths.Images.FxImages nextFrameImage = FxMaths.Images.FxTools.FxImages_safe_constructors(bitmap); // Start the simulation simulation.Start(); var imTarget = imPerson * 0.1f + 0.5f; for (int i = 0; i < 2000; i++) { // Set to zero value mat.DrawMatrix(shopPlan, new FxVector2f(0, 0), new FxVector2f(mat.Width, mat.Height), FxMatrixF.DrawInterpolationMethod.Linear); //mat.SetValue(1); // white // Draw the target points if(true) foreach(var t in targetList) { var size = new FxVector2f(20 * resize.x, 20 * resize.y); var center = size / 2; // Draw a circle per person mat.DrawMatrix(imTarget, imPersonMask, t - center, size, FxMatrixF.DrawInterpolationMethod.Linear); } lock (shop) { var size = new FxVector2f(50 * resize.x, 50 * resize.y); var center = size / 2; // move the blobs in random directions foreach (var person in shop.personList) { // Draw a circle per person mat.DrawMatrix(imPerson, imPersonMask, person.Position - center, size, FxMatrixF.DrawInterpolationMethod.Linear); } } // Update the bitmap that we write to image nextFrameImage.Load(mat, new FxMaths.Images.ColorMap(FxMaths.Images.ColorMapDefaults.Gray)); vfw.WriteVideoFrame(bitmap); // Update showing image im.UpdateInternalImage(mat, new FxMaths.Images.ColorMap(FxMaths.Images.ColorMapDefaults.Gray)); canvas1.ReDraw(); if (i % 10 == 0) Console.WriteLine("Write Frame:" + i.ToString()); } // Stop the simulation simulation.Stop(); vfw.Close(); }
private void addVideoSphereToolStripMenuItem_Click(object sender, EventArgs e) { ///////////////////////////////////////////////////////////// Start Video mp.Initialize(Engine.g_device); mp.SetFile("sample.avi"); difTex = mp.CreateTexture(); Engine.AppHandleKeys = (SharpDX.DirectInput.Key key) => { /// handle the keys that we want switch (key) { case SharpDX.DirectInput.Key.Up: mp.OnRender(difTex.texture2D, true); break; case SharpDX.DirectInput.Key.Down: mp.OnRender(difTex.texture2D, false); break; } return false; }; ///////////////////////////////////////////////////////////// Add the Spheres AddSphete(1000, new Vector3(0, 0, 0), new Vector3(20, 20, 20)); //AddSphete(100, new Vector3(1100, 80, 2000), new Vector3(3, 3, 3)); ///////////////////////////////////////////////////////////// Init the Shader #if false // create the shader ShaderSimple sh = new ShaderSimple(); /// add the shader to the list ShaderManager.AddShader("Shader12", sh); // add the textures for the shader sh.SetTexture("Resources/diffuse.jpg", TextureType.Diffuse); sh.SetTexture("Resources/lightmap.jpg", TextureType.Lightmap); sh.SetTexture("Resources/height.jpg", TextureType.Heightmap); sh.SetVariables(new Vector3(1, 1, 1), ShaderViariables.Ambient); List<Polygon> polygonList = new List<Polygon>(); FxVector2f p1 = new FxVector2f(0, 0); FxVector2f p2 = new FxVector2f(0, 100); FxVector2f p3 = new FxVector2f(100, 100); FxVector2f p4 = new FxVector2f(100, 0); float u1 = 0; float v1 = 0; Vertex ver1 = new Vertex(p1.X, -1, p1.Y, 0, 0, 0, u1, v1); u1 = 0; v1 = 1; Vertex ver2 = new Vertex(p2.X, -1, p2.Y, 0, 0, 0, u1, v1); u1 = 1; v1 = 1; Vertex ver3 = new Vertex(p3.X, -1, p3.Y, 0, 0, 0, u1, v1); u1 = 1; v1 = 0; Vertex ver4 = new Vertex(p4.X, -1, p4.Y, 0, 0, 0, u1, v1); polygonList.Add(new Polygon(ver1, ver2, ver3)); polygonList.Add(new Polygon(ver1, ver3, ver4)); ///////////////////////////////////////////////////////////// Init the Mesh /// make a new mesh Mesh mesh = new Mesh(); /// set to the new mesh the shader mesh.m_shader = ShaderManager.GetExistShader("Shader12"); // set the position mesh.SetPosition(new Vector3(0, 0, 0)); // scale it mesh.SetScale(new Vector3(40, 40, 40)); // add the polygons on mesh foreach (Polygon poly in polygonList) { // add the polygons to the mesh mesh.AddPolygon(poly, false); } /// create the mesh and download it to the card mesh.CreateMesh(); /// add the mesh to the engine mesh list Engine.g_MeshManager.AddMesh(mesh); sh.SetVariables(new Vector3(1, 1, 1), ShaderViariables.Ambient); #endif ///////////////////////////////////////////////////////////// Change Camera position // Engine.g_MoveCamera. Engine.g_MoveCamera.SetViewParams(new Vector3(2000, 2000, 200), new Vector3(0, 0, 0)); //////////////////////////////////////////////////// }
/// <summary> /// Zoom out. /// </summary> public void FitView() { if (ElementsList.Count == 0) return; // find boundary of the internal elements. FxVector2f min = new FxVector2f(float.MaxValue); FxVector2f max = new FxVector2f(float.MinValue); foreach (CanvasElements c in ElementsList) { if (c.Position.x < min.x) min.x = c.Position.x; if (c.Position.y < min.y) min.y = c.Position.y; var m = c.Position.x + c.Size.x; if (m > max.x) max.x = m; m = c.Position.y + c.Size.y; if (m > max.y) max.y = m; } // find the correct zoom factor var delta = max - min; var z = RenderArea.Width / delta.x; z = (z > RenderArea.Height / delta.y) ? RenderArea.Height / delta.y : z; this._Zoom.Width = z; this._Zoom.Height = z; this._ScreenOffset.X = 0; this._ScreenOffset.Y = 0; }
private void TranslatePoint( PointF point , out FxVector2f tpoint) { tpoint.x = (point.X - _ScreenOffset.X) / _Zoom.Width; tpoint.y = (point.Y - _ScreenOffset.Y) / _Zoom.Height; }
/// <summary> /// Draw Rectangle. /// </summary> /// <param name="Start"></param> /// <param name="Size"></param> public void DrawRect(FxVector2f start, FxVector2f size, float value) { DrawLine(start, new FxVector2f(start.x + size.x, start.y), value); DrawLine(new FxVector2f(start.x + size.x, start.y), new FxVector2f(start.x + size.x, start.y + size.y), value); DrawLine(new FxVector2f(start.x + size.x, start.y + size.y), new FxVector2f(start.x, start.y + size.y), value); DrawLine(new FxVector2f(start.x, start.y + size.y), start, value); }
/// <summary> /// Create given number of uniform random points /// on a given range(min,max) /// </summary> /// <param name="num">The number of the random points</param> /// <param name="min">The min position of the range that the points are going to generate</param> /// <param name="max">The max position of the range that the points are going to generate</param> public void CreateRandomPoints(int num, FxVector2f min, FxVector2f max) { // generate and add the points float x, y; Random rand = new Random(100); for (int i = 0; i < num; i++) { x = min.X + (float)(rand.NextDouble() * (max.X - min.X)); y = min.Y + (float)(rand.NextDouble() * (max.Y - min.Y)); //canvas1 add a new vertex listAllVertex.Add(new FxVector2f(x,y)); //listAllVertex.Add(new FxVector2f(num-i)); } WriteLine("Add " + num.ToString() + "to vertex list"); }
private void addCEIDToolStripMenuItem_Click(object sender, EventArgs e) { ///////////////////////////////////////////////////////////// Start Video mp.Initialize(Engine.g_device); mp.SetFile("sample.avi"); difTex = mp.CreateTexture(); Engine.AppHandleKeys = (SharpDX.DirectInput.Key key) => { /// handle the keys that we want switch (key) { case SharpDX.DirectInput.Key.Up: mp.OnRender(difTex.texture2D, true); break; case SharpDX.DirectInput.Key.Down: mp.OnRender(difTex.texture2D, false); break; case SharpDX.DirectInput.Key.Space: if (selected_sphere != null) { Engine.g_MoveCamera.SetViewParams(selected_sphere.center, new Vector3(2000, 0, 2000)); selected_sphere.sh.SetVariables(new Vector3(1, 1, 1), ShaderViariables.Ambient); selected_sphere = null; weAreIn = true; } break; case SharpDX.DirectInput.Key.LeftShift: Engine.g_MoveCamera.SetViewParams(new Vector3(6500, 4500, 2000), new Vector3(200, 0, 200)); weAreIn = false; break; } return false; }; ///////////////////////////////////////////////////////////// Add the Spheres // AddSphete(1000, new Vector3(0, 0, 0), new Vector3(2, 2, 2),"sample.avi"); AddSphere(100, new Vector3(1500, 110, 900), new Vector3(2.5f, 2.5f, 2.5f), "Resources/lady2.jpg"); AddSphere(100, new Vector3(2300, 80, 3000), new Vector3(2.5f, 2.5f, 2.5f), "Resources/lady.jpg"); AddSphere(100, new Vector3(2300, 110, 2300), new Vector3(2.5f, 2.5f, 2.5f), "Resources/lady3.jpg"); AddSphete(100, new Vector3(2300, 110, 1700), new Vector3(2.5f, 2.5f, 2.5f)); // AddSphete(100, new Vector3(1100, 80, 2000), new Vector3(3, 3, 3)); // create the shader ShaderSimple sh1 = new ShaderSimple(); /// add the shader to the list ShaderManager.AddShader("Shader11", sh1); // add the textures for the shader sh1.SetTexture("Resources/tmima2.png", TextureType.Diffuse); sh1.SetTexture("Resources/tmima2.png", TextureType.Lightmap); sh1.SetTexture("Resources/height.jpg", TextureType.Heightmap); List<Polygon> polygonList1 = new List<Polygon>(); FxVector2f p1 = new FxVector2f(0, 0); FxVector2f p2 = new FxVector2f(0, 100); FxVector2f p3 = new FxVector2f(100, 100); FxVector2f p4 = new FxVector2f(100, 0); float u1 = 0; float v1 = 0; Vertex ver1 = new Vertex(p1.X, -1, p1.Y, 0, 0, 0, u1, v1); u1 = 0; v1 = 1; Vertex ver2 = new Vertex(p2.X, -1, p2.Y, 0, 0, 0, u1, v1); u1 = 1; v1 = 1; Vertex ver3 = new Vertex(p3.X, -1, p3.Y, 0, 0, 0, u1, v1); u1 = 1; v1 = 0; Vertex ver4 = new Vertex(p4.X, -1, p4.Y, 0, 0, 0, u1, v1); polygonList1.Add(new Polygon(ver1, ver2, ver3)); polygonList1.Add(new Polygon(ver1, ver3, ver4)); /// make a new mesh Mesh mesh1 = new Mesh(); /// set to the new mesh the shader mesh1.m_shader = ShaderManager.GetExistShader("Shader11"); // set the position mesh1.SetPosition(new Vector3(0, 0, 0)); // scale it mesh1.SetScale(new Vector3(60, 60, 60)); // add the polygons on mesh foreach (Polygon poly in polygonList1) { // add the polygons to the mesh mesh1.AddPolygon(poly, false); } /// create the mesh and download it to the card mesh1.CreateMesh(); /// add the mesh to the engine mesh list Engine.g_MeshManager.AddMesh(mesh1); sh1.SetVariables(new Vector3(1, 1, 1), ShaderViariables.Ambient); }