/// <summary>
 /// Inizializza un oggetto Tastiera
 /// </summary>
 /// <param name="Handle"></param>
 public Keyboard(Control Handle)
 {
     try
     {
         keyboard = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard);
         movement = new VertexData(0, 0, 0);
         if (LogiX_Engine.Device.PresentationParameters.Windowed)
         {
             keyboard.SetCooperativeLevel(Handle, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
         }
         else
         {
             keyboard.SetCooperativeLevel(Handle, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.NonExclusive);
         }
         keyboard.SetDataFormat(DeviceDataFormat.Keyboard);
         keyboard.Acquire();
         correct = true;
     }
     catch
     {
         Error("OnCreateObject");
     }
 }
Example #2
0
 void APunto(VertexData a, int cicliLook, int cicliPos, float Distance)
 {
     if (timeSpeed !=0)
     {
         if (k == 0)
         {
             stop = true;
             I1 = timeSpeed / 20;
             oldTimeSpeed = timeSpeed;
             k++;
         }
         if (k >= 1)
         {
             stop = true;
             timeSpeed = timeSpeed - I1;
             k++;
         }
         if (k == 20)
         {
             timeSpeed = 0;
             stop = true;
             k = -1;
             i = 0;
             j = -1;
             l = -1;
         }
     }
     else
     {
         if (k == 0)
         {
             oldTimeSpeed = 0;
             k = -1;
             i = 0;
             j = -1;
             l = -1;
         }
     }
     if (i == 0)
     {
         stop = true;
         V1 = a - cam.Look;
         V2 = cam.Look - cam.Position;
         V1 = V1 / cicliLook;
         cam.Look = cam.Look + V1;
         i++;
     }
     if (i >= 1)
     {
         stop = true;
         cam.Look = cam.Look + V1;
         i++;
     }
     if (i == cicliLook)
     {
         stop = true;
         i = -1;
         j = 0;
         k = -1;
         l = -1;
     }
     if (j == 0)
     {
         stop = true;
         V1 = a - cam.Position - (VertexData.Normalize(V2)*Distance);
         V1 = V1 / cicliPos;
         cam.Position = cam.Position + V1;
         j++;
     }
     if (j >= 1)
     {
         stop = true;
         cam.Position = cam.Position + V1;
         j++;
     }
     if (j == cicliPos)
     {
         stop = true;
         j = -1;
         i = -1;
         k = -1;
         l = 0;
     }
     if (oldTimeSpeed != 0)
     {
         if (l == 0)
         {
             stop = true;
             I1 = oldTimeSpeed / 20;
             l++;
         }
         if (l >= 1)
         {
             stop = true;
             timeSpeed = timeSpeed + I1;
             l++;
         }
         if (l == 20)
         {
             timeSpeed = oldTimeSpeed;
             stop = false;
             k = -1;
             i = -1;
             j = -1;
             l = -1;
         }
     }
     else
     {
         if (l == 0)
         {
             stop = false;
             timeSpeed = 0;
             k = -1;
             i = -1;
             j = -1;
             l = -1;
         }
     }
 }
        /// <summary>
        /// Inizializza la generazione (tramite rendering to target) della CubeMap. (Va utilizzato nel GameLoop prima dell'inizio del frame [specificato da LogiX_Technologies.LogiX_Engine.StartRender()] o dopo la fine del frame [specificata da LogiX_Technologies.LogiX_Engine.EndRender()])
        /// </summary>
        /// <param name="function"></param>
        /// <param name="CenterOfCube"></param>
        /// <returns></returns>
        public bool RenderToCube(RenderFunction function, VertexData CenterOfCube)
        {
            try
            {
                renderToEnvy.BeginCube(cube);
                backViewPort = LogiX_Engine.Device.Viewport;
                LogiX_Engine.Device.Viewport = viewport;
                Vector3 v = new Vector3();
                Vector3 upV = new Vector3();
                for (int i = 0; i < 6; i++)
                {
                    switch (i)
                    {
                        case (int)CubeMapFace.PositiveX:
                            cam.Position = CenterOfCube;
                            cam.Look = new VertexData(1, 0, 0) + CenterOfCube;
                            cam.UpVector = new VertexData(0, 1, 0);
                            break;
                        case (int)CubeMapFace.NegativeX:
                            cam.Position = CenterOfCube;
                            cam.Look = new VertexData(-1, 0, 0) + CenterOfCube;
                            cam.UpVector = new VertexData(0, 1, 0);
                            break;
                        case (int)CubeMapFace.PositiveY:
                            cam.Position = CenterOfCube;
                            cam.Look = new VertexData(0, 1, 0) + CenterOfCube;
                            cam.UpVector = new VertexData(0, 0, -1);
                            break;
                        case (int)CubeMapFace.NegativeY:
                            cam.Position = CenterOfCube;
                            cam.Look = new VertexData(0, -1, 0) + CenterOfCube;
                            cam.UpVector = new VertexData(0, 0, 1);
                            break;
                        case (int)CubeMapFace.PositiveZ:
                            cam.Position = CenterOfCube;
                            cam.Look = new VertexData(0, 0, 1) + CenterOfCube;
                            cam.UpVector = new VertexData(0, 1, 0);
                            break;
                        case (int)CubeMapFace.NegativeZ:
                            cam.Position = CenterOfCube;
                            cam.Look = new VertexData(0, 0, -1) + CenterOfCube;
                            cam.UpVector = new VertexData(0, 1, 0);
                            break;
                    }
                    cam.Capture();
                    SetFace((CubeMapFace)i);
                    function.Invoke();
                }
                renderToEnvy.End(1);
                LogiX_Engine.Device.Viewport = backViewPort;

                return true;
            }
            catch
            {
                Error("OnRenderToCube");
                return false;
            }
        }
 /// <summary>
 /// Inizializza un oggetto Luce Direzionale
 /// </summary>
 /// <param name="Direction"></param>
 /// <param name="Ambient"></param>
 /// <param name="Diffuse"></param>
 /// <param name="Specular"></param>
 public DirectionalLight(VertexData Direction, Color Ambient, Color Diffuse, Color Specular)
 {
     try
     {
         ambient = Ambient;
         diffuse = Diffuse;
         direction = Direction;
         specular = Specular;
         LightCount++;
         Count = LightCount;
         correct = true;
     }
     catch
     {
         Error("OnCreateObject");
     }
 }
 /// <summary>
 /// Inizializza automaticamente una camera
 /// </summary>
 /// <param name="Position"></param>
 /// <param name="TargetPoint"></param>
 public Camera(VertexData Position, VertexData TargetPoint)
 {
     try
     {
         my_position = Position;
         my_look = TargetPoint;
         correct = true;
     }
     catch
     {
         Error("OnCreateObject");
     }
 }
 /// <summary>
 /// Attiva l'effetto avanzato Water
 /// </summary>
 /// <param name="cam"></param>
 /// <param name="LightPosition"></param>
 /// <param name="vAlpha"></param>
 /// <param name="WaveHeight"></param>
 /// <param name="WaveSpeed"></param>
 /// <param name="WaveLenght"></param>
 /// <param name="TexturesDimension"></param>
 /// <returns></returns>
 public bool BeginWaterEffect(Camera cam, VertexData LightPosition, float vAlpha, float WaveHeight, float WaveSpeed, float WaveLenght, float TexturesDimension)
 {
     try
     {
         Effect.Begin(FX.None);
         matrix = LogiX_Engine.Device.Transform.View * LogiX_Engine.Device.Transform.Projection * LogiX_Engine.Device.Transform.World;
         Matrix.TransposeMatrix(matrix);
         Effect.SetValue(EffectHandles[0], matrix);
         Effect.SetValue(EffectHandles[1], new float[3] { LightPosition.X, LightPosition.Y, LightPosition.Z });
         Effect.SetValue(EffectHandles[2], new float[4] { cam.Position.X, cam.Position.Y, cam.Position.Z, 0 });
         Effect.SetValue(EffectHandles[3], (float)Environment.TickCount / 1000);
         Effect.SetValue(EffectHandles[4], vAlpha);
         Effect.SetValue(EffectHandles[5], WaveHeight);
         Effect.SetValue(EffectHandles[6], WaveSpeed);
         Effect.SetValue(EffectHandles[7], WaveLenght);
         Effect.SetValue(EffectHandles[8], TexturesDimension);
         Effect.SetValue(EffectHandles[9], BaseTextures[0]);
         Effect.SetValue(EffectHandles[10], BaseTextures[1]);
         Effect.SetValue(EffectHandles[11], BaseTextures[2]);
         Effect.SetValue(EffectHandles[12], BaseTextures[3]);
         Effect.SetValue(EffectHandles[13], BaseTextures[4]);
         Effect.SetValue(EffectHandles[14], BaseTextures[5]);
         Effect.SetValue(EffectHandles[15], BaseTextures[6]);
         Effect.CommitChanges();
         Effect.BeginPass(0);
         return true;
     }
     catch
     {
         if (AmICorrect == true)
             Error("OnBeginEffect");
         return false;
     }
 }
 /// <summary>
 /// Ritorna la distanza tra due punti le cui posizioni cartesiane sono definite da rispettivi VertexData
 /// </summary>
 /// <param name="V1"></param>
 /// <param name="V2"></param>
 /// <returns></returns>
 public static float Distance(VertexData V1, VertexData V2)
 {
     float f;
     f = (float)Math.Sqrt((Math.Pow((V1.X - V2.X), 2) + Math.Pow((V1.Y - V2.Y), 2) + Math.Pow((V1.Z - V2.Z), 2)));
     return f;
 }
Example #8
0
 public Satellite(Pianeta Pianeta, float DistanzaDalPianetaInMigliaiaKm, float RaggioInKm, float InclinazioneAsse, float PeriodoDiRotazioneInGiorni, float PeriodoDiRivoluzioneInGiorni, XTexture Texture, string NomeDelSatellite)
 {
     pianeta = Pianeta;
     nomeSatellite = NomeDelSatellite;
     model = new Model("MEDIA//satellite.x", 0);
     model1 = new Model("MEDIA//sfera4.x", 0);
     distanzaDalPianeta = DistanzaDalPianetaInMigliaiaKm;
     periodoRotazione = PeriodoDiRotazioneInGiorni;
     periodoRivoluzione = PeriodoDiRivoluzioneInGiorni;
     inclinazioneAsse = InclinazioneAsse;
     raggio = RaggioInKm;
     texture = Texture;
     isdefault = true;
     position = VertexData.Empty;
 }
 /// <summary>
 /// Inizializza un Triangolo con un materiale applicato
 /// </summary>
 /// <param name="Vertex1"></param>
 /// <param name="Vertex2"></param>
 /// <param name="Vertex3"></param>
 /// <param name="Material"></param>
 public Triangle(VertexData Vertex1, VertexData Vertex2, VertexData Vertex3, XMaterial Material)
 {
     try
     {
         mat = Material;
         my_vertex_buffer = new VertexBuffer(typeof(CustomVertex.PositionNormalColored), 3, device, 0, CustomVertex.PositionNormalColored.Format, Pool.Default);
         CustomVertex.PositionNormalColored[] verts = (CustomVertex.PositionNormalColored[])my_vertex_buffer.Lock(0, 0);
         verts[0].X = Vertex1.X; verts[0].Y = Vertex1.Y; verts[0].Z = Vertex1.Z; verts[0].Color = Material.Ambient.ToArgb();
         verts[1].X = Vertex2.X; verts[1].Y = Vertex2.Y; verts[1].Z = Vertex2.Z; verts[1].Color = Material.Ambient.ToArgb(); ;
         verts[2].X = Vertex3.X; verts[2].Y = Vertex3.Y; verts[2].Z = Vertex3.Z; verts[2].Color = Material.Ambient.ToArgb();
         my_vertex_buffer.Unlock();
         correct = true;
         textured = false;
     }
     catch
     {
         Error("OnCreateObject");
     }
 }
Example #10
0
 /// <summary>
 /// Inizializza un Triangolo da texturizzare
 /// </summary>
 /// <param name="Vertex1"></param>
 /// <param name="Vertex2"></param>
 /// <param name="Vertex3"></param>
 /// <param name="TexturePath"></param>
 /// <param name="QualityValue"></param>
 public Triangle(VertexData Vertex1, VertexData Vertex2, VertexData Vertex3, string TexturePath, int QualityValue)
 {
     try
     {
         //da modificare i valori Tu Tv
         my_texture = TextureLoader.FromFile(device, TexturePath, 0, 0, 0, Usage.None, Format.Unknown, Pool.Default, Filter.Linear, Filter.Linear, 0);
         //my_texture = TextureLoader.FromFile(device, TexturePath);
         my_vertex_buffer = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), 3, device, 0, CustomVertex.PositionNormalTextured.Format, Pool.Default);
         CustomVertex.PositionNormalTextured[] verts = (CustomVertex.PositionNormalTextured[])my_vertex_buffer.Lock(0, 0);
         verts[0].X = Vertex1.X; verts[0].Y = Vertex1.Y; verts[0].Z = Vertex1.Z;
         verts[0].Tu = 0.5f;
         verts[0].Tv = 0.5f;
         verts[1].X = Vertex2.X; verts[1].Y = Vertex2.Y; verts[1].Z = Vertex2.Z;
         verts[1].Tu = 1.0f;
         verts[1].Tv = 1.0f;
         verts[2].X = Vertex3.X; verts[2].Y = Vertex3.Y; verts[2].Z = Vertex3.Z;
         verts[2].Tu = 0.0f;
         verts[2].Tv = 1.0f;
         my_vertex_buffer.Unlock();
         quality = QualityValue;
         correct = true;
         textured = true;
     }
     catch
     {
         Error("OnCreateObject");
     }
 }
Example #11
0
 /// <summary>
 /// Inizializza un oggetto Riflettore
 /// </summary>
 /// <param name="Position"></param>
 /// <param name="Direction"></param>
 /// <param name="Ambient"></param>
 /// <param name="Diffuse"></param>
 /// <param name="Specular"></param>
 /// <param name="InnerConeAngle"></param>
 /// <param name="OuterConeAngle"></param>
 /// <param name="Falloff"></param>
 /// <param name="Range"></param>
 public SpotLight(VertexData Position, VertexData Direction, Color Ambient, Color Diffuse, Color Specular, float InnerConeAngle, float OuterConeAngle, float Falloff, float Range)
 {
     try
     {
         ambient = Ambient;
         diffuse = Diffuse;
         position = Position;
         direction = Direction;
         specular = Specular;
         range = Range;
         falloff = Falloff;
         innerconeangle = InnerConeAngle;
         outerconeangle = OuterConeAngle;
         LightCount++;
         Count = LightCount;
         correct = true;
     }
     catch
     {
         Error("OnCreateObject");
     }
 }
Example #12
0
 /// <summary>
 /// Inizializza un oggetto Luce Puntiorme
 /// </summary>
 /// <param name="Position"></param>
 /// <param name="Ambient"></param>
 /// <param name="Diffuse"></param>
 /// <param name="Specular"></param>
 /// <param name="Range"></param>
 public PointLight(VertexData Position, Color Ambient, Color Diffuse, Color Specular, float Range)
 {
     try
     {
         my_ambient = Ambient;
         my_diffuse = Diffuse;
         my_position = Position;
         my_specular = Specular;
         my_range = Range;
         LightCount++;
         Count = LightCount;
         correct = true;
     }
     catch
     {
         Error("OnCreateObject");
     }
 }
Example #13
0
        /// <summary>
        /// Controlla l'oggetto Camera (specificato da LogiX_Technologies.Camera) ruotando il suo punto di posizione nello spazio (specificato da LogiX_Technologies.Camera.Position) attorno al suo punto di osservazione (specificato da LogiX_Technologies.Camera.Look) con il Mouse. 
        /// </summary>
        /// <param name="Camera"></param>
        /// <param name="Look"></param>
        /// <param name="Speed"></param>
        /// <returns></returns>
        public bool CameraTrackBall(Camera Camera, VertexData Look, float Speed, float SpeedScaling, float Sensibility)
        {
            try
            {
                cam = Camera;
                speedScaling = SpeedScaling;
                angleX = angleX + 0.005f * CurrentX * Sensibility;
                angleY = angleY + 0.005f * CurrentY * Sensibility;
                angleZ = angleZ + 0.005f * CurrentZ * Speed;
                Camera.Look = Look;
                if (angleY > 0)
                {
                    if (angleZ < 0)
                    {
                        if (angleY < (float)Math.PI)
                        {
                            Camera.Position.Y = Look.Y + 1000 * ((float)Math.Pow(angleZ, 5) / SpeedScaling) * (float)Math.Cos(angleY);
                            Camera.Position.X = Look.X + 1000 * ((float)Math.Pow(angleZ, 5) / SpeedScaling) * (float)Math.Cos(angleX) * (float)Math.Sin(angleY);
                            Camera.Position.Z = Look.Z + 1000 * ((float)Math.Pow(angleZ, 5) / SpeedScaling) * (float)Math.Sin(angleX) * (float)Math.Sin(angleY);
                        }
                        else
                        {
                            angleY = (float)Math.PI - 0.001f;
                            Camera.Position.Y = Look.Y + 1000 * ((float)Math.Pow(angleZ, 5) / SpeedScaling) * (float)Math.Cos(angleY);
                            Camera.Position.X = Look.X + 1000 * ((float)Math.Pow(angleZ, 5) / SpeedScaling) * (float)Math.Cos(angleX) * (float)Math.Sin(angleY);
                            Camera.Position.Z = Look.Z + 1000 * ((float)Math.Pow(angleZ, 5) / SpeedScaling) * (float)Math.Sin(angleX) * (float)Math.Sin(angleY);
                        }
                    }
                    else
                    {
                        angleZ = -0.00001f;
                    }
                }
                if (angleY <= 0)
                {
                    angleY = 0.01f;
                    Camera.Position.Y = Look.Y + 1000 * ((float)Math.Pow(angleZ, 5) / SpeedScaling) * (float)Math.Cos(angleY);
                    Camera.Position.X = Look.X + 1000 * ((float)Math.Pow(angleZ, 5) / SpeedScaling) * (float)Math.Cos(angleX) * (float)Math.Sin(angleY);
                    Camera.Position.Z = Look.Z + 1000 * ((float)Math.Pow(angleZ, 5) / SpeedScaling) * (float)Math.Sin(angleX) * (float)Math.Sin(angleY);
                }

                correct = true;
                return true;
            }
            catch
            {
                correct = false;
                return false;
            }
        }
Example #14
0
 void GuardaPunto(VertexData look)
 {
     mouse.CameraTrackBall(cam, look, 0.1f, 1000000f / 1f, cam.FieldOfView);
 }
Example #15
0
 /// <summary>
 /// Normalizza un VertexData.
 /// </summary>
 /// <param name="V"></param>
 /// <returns></returns>
 public static VertexData Normalize(VertexData V)
 {
     VertexData n;
     float f;
     f = 1 / ((float)Math.Sqrt((Math.Pow(V.X, 2) + Math.Pow(V.Y, 2) + Math.Pow(V.Z, 2))));
     n = V * f;
     return n;
 }
Example #16
0
 public Pianeta(float DistanzaDalSoleInMilioniKm, float RaggioInKm, float InclinazioneAsse, float PeriodoDiRotazioneInGiorni, float PeriodoDiRivoluzioneInGiorni, XTexture Texture, string NomeDelPianeta)
 {
     nomePianeta = NomeDelPianeta;
     model = new Model("MEDIA//satellite.x",0);
     model1 = new Model("MEDIA//sfera4.x", 0);
     distanzaDalSole = DistanzaDalSoleInMilioniKm;
     periodoRotazione = PeriodoDiRotazioneInGiorni;
     periodoRivoluzione = PeriodoDiRivoluzioneInGiorni;
     inclinazioneAsse = InclinazioneAsse;
     raggio = RaggioInKm;
     texture = Texture;
     position = VertexData.Empty;
 }
Example #17
0
 /// <summary>
 /// Attiva l'effetto base PerPixelDirectionalLight
 /// </summary>
 /// <param name="cam"></param>
 /// <param name="LightDirection"></param>
 /// <param name="mat"></param>
 /// <returns></returns>
 public bool BeginPerPixelDirectionalLightEffect(Camera cam, VertexData LightDirection, XMaterial mat)
 {
     try
     {
         Effect.Begin(FX.None);
         matrix = LogiX_Engine.Device.Transform.View * LogiX_Engine.Device.Transform.Projection;
         Matrix.TransposeMatrix(matrix);
         Effect.SetValue(EffectHandles[0], matrix);
         matrix = LogiX_Engine.Device.Transform.World;
         Matrix.TransposeMatrix(matrix);
         Effect.SetValue(EffectHandles[1], matrix);
         Effect.SetValue(EffectHandles[2], new float[3] { -LightDirection.X, -LightDirection.Y, -LightDirection.Z });
         Effect.SetValue(EffectHandles[3], new float[3] { cam.Position.X, cam.Position.Y, cam.Position.Z });
         Effect.SetValue(EffectHandles[4], BaseTextures[0]);
         Effect.SetValue(EffectHandles[5], new float[4] { mat.Specular.R / 255, mat.Specular.G / 255, mat.Specular.B / 255, mat.Specular.A / 255 });
         Effect.SetValue(EffectHandles[6], new float[4] { mat.Diffuse.R / 255, mat.Diffuse.G / 255, mat.Diffuse.B / 255, mat.Diffuse.A / 255 });
         Effect.SetValue(EffectHandles[7], mat.SpecularSharpness);
         Effect.CommitChanges();
         Effect.BeginPass(0);
         return true;
     }
     catch
     {
         if (AmICorrect == true)
             Error("OnBeginEffect");
         return false;
     }
 }
Example #18
0
 public Satellite(Pianeta Pianeta, float DistanzaDalPianetaInMigliaiaKm, float RaggioInKm, float InclinazioneAsse, float PeriodoDiRotazioneInGiorni, float PeriodoDiRivoluzioneInGiorni, XTexture Texture, string NomeDelSatellite, Model Model)
 {
     pianeta = Pianeta;
     nomeSatellite = NomeDelSatellite;
     model = Model;
     distanzaDalPianeta = DistanzaDalPianetaInMigliaiaKm;
     periodoRotazione = PeriodoDiRotazioneInGiorni;
     periodoRivoluzione = PeriodoDiRivoluzioneInGiorni;
     inclinazioneAsse = InclinazioneAsse;
     raggio = RaggioInKm;
     texture = Texture;
     isdefault = false;
     position = VertexData.Empty;
 }
Example #19
0
 /// <summary>
 /// Inizializza manualmente una camera
 /// </summary>
 /// <param name="Position"></param>
 /// <param name="TargetPoint"></param>
 /// <param name="UpVector"></param>
 /// <param name="FieldOfView"></param>
 /// <param name="NearPlane"></param>
 /// <param name="FarPlane"></param>
 /// <param name="AspectRatio"></param>
 public Camera(VertexData Position, VertexData TargetPoint, VertexData UpVector, float FieldOfView, float NearPlane, float FarPlane, float AspectRatio)
 {
     try
     {
         fieldView = FieldOfView;
         near = NearPlane;
         far = FarPlane;
         aspectratio = AspectRatio;
         my_position = Position;
         my_look = TargetPoint;
         my_up = UpVector;
         correct = true;
     }
     catch
     {
         Error("OnCreateObject");
     }
 }