Beispiel #1
0
 public Viewport(Vec3f cameraOrigin, Vec3f screenOrigin, int screenHeight, int screenWidth)
 {
     CameraOrigin = cameraOrigin;
     ScreenOrigin = screenOrigin;
     ScreenHeight = screenHeight;
     ScreenWidth = screenWidth;
 }
Beispiel #2
0
 public static int Encode(Vec3f v)
 {
     //return (_zOrderLookup[ClampFloat(v.Z)] | _zOrderLookup[ClampFloat(v.Y)] << 1 | _zOrderLookup[ClampFloat(v.X)] << 2);
     if (v.X >= _zOrderLookup.Length || v.Y >= _zOrderLookup.Length || v.Z >= _zOrderLookup.Length)
     {
         return 0;
     }
     return (_zOrderLookup[(int)v.Z] | _zOrderLookup[(int)v.Y] << 1 | _zOrderLookup[(int)v.X] << 2);
 }
Beispiel #3
0
 public Camera(Vec3f origin, Vec3f direction, int screenWidth, int screenHeight, float fieldOfView)
 {
     throw new System.NotImplementedException();
 }
Beispiel #4
0
 //public int Render()
 //{
 //    //Vector3f d = ScreenOrigin - CameraOrigin;
 //    //Vector3 o = ScreenOrigin.Clamp();
 //    //Ray r = new Ray(CameraOrigin, d.Normalize());
 //    //int test = r.Stab();
 //    //Vector3f upperRight = new Vector3f(ScreenOrigin.X + ScreenWidth, ScreenOrigin.Y, ScreenOrigin.Z);
 //    //Vector3f lowerLeft = new Vector3f(ScreenOrigin.X, ScreenOrigin.Y + ScreenHeight, ScreenOrigin.Z);
 //    Ray r = null;
 //    Vector3f dir = null;
 //    Vector3f target = ScreenOrigin;
 //    for (int y = 0; y < ScreenHeight; y++)
 //    {
 //        for (int x = 0; x < ScreenWidth; x++)
 //        {
 //            target.X = ScreenOrigin.X + x;
 //            target.Y = ScreenOrigin.Y + y;
 //            dir = target - CameraOrigin;
 //            r = new Ray(CameraOrigin, dir.Normalize());
 //            int test = r.Stab();
 //            _rayList.Add(r);
 //        }
 //    }
 //    return 0;
 //}
 public Ray GetRay(int x, int y)
 {
     Vec3f dir = new Vec3f(ScreenOrigin.X, ScreenOrigin.Y, ScreenOrigin.Z);
     dir.X += x;
     dir.Y += y;
     dir -= CameraOrigin;
     return new Ray(CameraOrigin, dir.Normalize());
 }
Beispiel #5
0
        public Vec3f Normalize()
        {
            float magnitude = GetMagnitude();

            Vec3f v3f = new Vec3f(X, Y, Z);

            v3f.X = v3f.X / magnitude;
            v3f.Y = v3f.Y / magnitude;
            v3f.Z = v3f.Z / magnitude;

            return v3f;
        }
Beispiel #6
0
 public static void Vector3fMult(ref Vec3f v1, ref Vec3f v2, ref Vec3f v3)
 {
     v3.X = v1.X * v2.X;
     v3.Y = v1.Y * v2.Y;
     v3.Z = v1.Z * v2.Z;
 }
Beispiel #7
0
 public static void Vector3fMult(ref Vec3f v1, float s1, ref Vec3f v2)
 {
     v2.X = v1.X * s1;
     v2.Y = v1.Y * s1;
     v2.Z = v1.Z * s1;
 }
Beispiel #8
0
 public static void Vector3fAdd(ref Vec3f v1, ref Vec3f v2, ref Vec3f v3)
 {
     v3.X = v1.X + v2.X;
     v3.Y = v1.Y + v2.Y;
     v3.Z = v1.Z + v2.Z;
 }
Beispiel #9
0
 //public static void Lerp(Ray r, float delta, ref Vector3f coords)
 //{
 //    //coords = r.Direction * delta + r.Origin;
 //    Vector3fMult(r.Direction, delta, ref coords);
 //}
 public static void Lerp(Vec3f origin, Vec3f direction, float delta, ref Vec3f coords)
 {
     //coords = direction * delta + origin;
     Vector3fMult(ref direction, delta, ref coords);
     Vector3fAdd(ref coords, ref origin, ref coords);
 }