示例#1
0
        public void GetBasis(out Vec3f pos, out Vec3f fwd, out Vec3f right, out Vec3f up)
        {
            IntPtr p = CustomMarshal.Alloc(typeof(FloatVector));
            IntPtr f = CustomMarshal.Alloc(typeof(FloatVector));
            IntPtr r = CustomMarshal.Alloc(typeof(FloatVector));
            IntPtr u = CustomMarshal.Alloc(typeof(FloatVector));

            Camera_GetBasis(m_Real, p, f, r, u);

            pos = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(p, typeof(FloatVector), false));
            fwd = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(f, typeof(FloatVector), false));
            right = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(r, typeof(FloatVector), false));
            up = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(u, typeof(FloatVector), false));

            CustomMarshal.Free(p);
            CustomMarshal.Free(f);
            CustomMarshal.Free(r);
            CustomMarshal.Free(u);
        }
示例#2
0
        public void GetBasis(out Vec3f pos, out Vec3f fwd, out Vec3f right, out Vec3f up)
        {
            IntPtr p = CustomMarshal.Alloc(typeof(FloatVector));
            IntPtr f = CustomMarshal.Alloc(typeof(FloatVector));
            IntPtr r = CustomMarshal.Alloc(typeof(FloatVector));
            IntPtr u = CustomMarshal.Alloc(typeof(FloatVector));

            Camera_GetBasis(m_Real, p, f, r, u);

            pos   = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(p, typeof(FloatVector), false));
            fwd   = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(f, typeof(FloatVector), false));
            right = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(r, typeof(FloatVector), false));
            up    = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(u, typeof(FloatVector), false));

            CustomMarshal.Free(p);
            CustomMarshal.Free(f);
            CustomMarshal.Free(r);
            CustomMarshal.Free(u);
        }
示例#3
0
        public void fpsLook(Vec3f pos, Vec3f rot)
        {
            IntPtr p = CustomMarshal.Alloc(typeof(FloatVector));
            IntPtr f = CustomMarshal.Alloc(typeof(FloatVector));
            IntPtr r = CustomMarshal.Alloc(typeof(FloatVector));

            isarc = false;
            parampos = new Vec3f(pos);
            paramrot = new Vec3f(rot);

            var ps = new FloatVector(pos);
            var rt = new FloatVector(rot);

            Maths_CameraFPSLook(ref ps, ref rt, p, f, r);

            pos = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(p, typeof(FloatVector), false));
            fwd = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(f, typeof(FloatVector), false));
            right = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(r, typeof(FloatVector), false));

            CustomMarshal.Free(p);
            CustomMarshal.Free(f);
            CustomMarshal.Free(r);
        }
示例#4
0
        public void fpsLook(Vec3f lookpos, Vec3f lookrot)
        {
            IntPtr p = CustomMarshal.Alloc(typeof(FloatVector));
            IntPtr f = CustomMarshal.Alloc(typeof(FloatVector));
            IntPtr r = CustomMarshal.Alloc(typeof(FloatVector));

            isarc    = false;
            parampos = new Vec3f(lookpos);
            paramrot = new Vec3f(lookrot);

            var ps = new FloatVector(lookpos);
            var rt = new FloatVector(lookrot);

            Maths_CameraFPSLook(ref ps, ref rt, p, f, r);

            pos   = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(p, typeof(FloatVector), false));
            fwd   = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(f, typeof(FloatVector), false));
            right = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(r, typeof(FloatVector), false));

            CustomMarshal.Free(p);
            CustomMarshal.Free(f);
            CustomMarshal.Free(r);
        }
示例#5
0
        public void Arcball(float dist, Vec3f rot)
        {
            IntPtr p = CustomMarshal.Alloc(typeof(FloatVector));
            IntPtr f = CustomMarshal.Alloc(typeof(FloatVector));
            IntPtr r = CustomMarshal.Alloc(typeof(FloatVector));

            isarc = true;
            parampos.x = dist;
            parampos.y = 0.0f;
            parampos.z = 0.0f;
            paramrot = new Vec3f(rot);

            var rt = new FloatVector(rot);

            Maths_CameraArcball(dist, ref rt, p, f, r);

            pos = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(p, typeof(FloatVector), false));
            fwd = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(f, typeof(FloatVector), false));
            right = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(r, typeof(FloatVector), false));

            CustomMarshal.Free(p);
            CustomMarshal.Free(f);
            CustomMarshal.Free(r);
        }
示例#6
0
        public void Arcball(float dist, Vec3f rot)
        {
            IntPtr p = CustomMarshal.Alloc(typeof(FloatVector));
            IntPtr f = CustomMarshal.Alloc(typeof(FloatVector));
            IntPtr r = CustomMarshal.Alloc(typeof(FloatVector));

            isarc      = true;
            parampos.x = dist;
            parampos.y = 0.0f;
            parampos.z = 0.0f;
            paramrot   = new Vec3f(rot);

            var rt = new FloatVector(rot);

            Maths_CameraArcball(dist, ref rt, p, f, r);

            pos   = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(p, typeof(FloatVector), false));
            fwd   = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(f, typeof(FloatVector), false));
            right = new Vec3f((FloatVector)CustomMarshal.PtrToStructure(r, typeof(FloatVector), false));

            CustomMarshal.Free(p);
            CustomMarshal.Free(f);
            CustomMarshal.Free(r);
        }
示例#7
0
 public Vec3f(Vec3f v) { x = v.x; y = v.y; z = v.z; }
示例#8
0
 public FloatVector(Vec3f v, float W)
 {
     x = v.x; y = v.y; z = v.z; w = W;
 }
示例#9
0
        public override bool Update()
        {
            Vec3f pos, fwd, right, up;
            m_Camera.GetBasis(out pos, out fwd, out right, out up);

            if (CurrentMove[0] != 0)
            {
                Vec3f dir = right;
                dir.Mul((float)CurrentMove[0]);

                m_Position.x += dir.x * CurrentSpeed;
                m_Position.y += dir.y * CurrentSpeed;
                m_Position.z += dir.z * CurrentSpeed;
            }
            if (CurrentMove[1] != 0)
            {
                Vec3f dir = new Vec3f(0.0f, 1.0f, 0.0f);
                //dir = up;
                dir.Mul((float)CurrentMove[1]);

                m_Position.x += dir.x * CurrentSpeed;
                m_Position.y += dir.y * CurrentSpeed;
                m_Position.z += dir.z * CurrentSpeed;
            }
            if (CurrentMove[2] != 0)
            {
                Vec3f dir = fwd;
                dir.Mul((float)CurrentMove[2]);

                m_Position.x += dir.x * CurrentSpeed;
                m_Position.y += dir.y * CurrentSpeed;
                m_Position.z += dir.z * CurrentSpeed;
            }

            if (CurrentMove[0] != 0 || CurrentMove[1] != 0 || CurrentMove[2] != 0)
            {
                Camera.SetPosition(m_Position);
                return true;
            }

            return false;
        }
示例#10
0
        public void Reset(Vec3f pos, float dist)
        {
            m_LookAt = pos;
            m_Distance = Math.Abs(dist);

            m_Camera.ResetArcball();
            m_Camera.SetPosition(m_LookAt);
            m_Camera.SetArcballDistance(m_Distance);
        }
示例#11
0
 public FloatVector(Vec3f v)
 {
     x = v.x; y = v.y; z = v.z; w = 1;
 }
示例#12
0
 public Vec3f(Vec3f v)
 {
     x = v.x; y = v.y; z = v.z;
 }
示例#13
0
        public override void Update()
        {
            if (CurrentMove[0] != 0)
            {
                Vec3f dir = m_Camera.Right;
                dir.Mul((float)CurrentMove[0]);

                m_Position.x += dir.x * CurrentSpeed;
                m_Position.y += dir.y * CurrentSpeed;
                m_Position.z += dir.z * CurrentSpeed;

                m_Dirty = true;
            }
            if (CurrentMove[1] != 0)
            {
                Vec3f dir = new Vec3f(0.0f, 1.0f, 0.0f);
                //dir = m_Camera.GetUp();
                dir.Mul((float)CurrentMove[1]);

                m_Position.x += dir.x * CurrentSpeed;
                m_Position.y += dir.y * CurrentSpeed;
                m_Position.z += dir.z * CurrentSpeed;

                m_Dirty = true;
            }
            if (CurrentMove[2] != 0)
            {
                Vec3f dir = m_Camera.Forward;
                dir.Mul((float)CurrentMove[2]);

                m_Position.x += dir.x * CurrentSpeed;
                m_Position.y += dir.y * CurrentSpeed;
                m_Position.z += dir.z * CurrentSpeed;

                m_Dirty = true;
            }
        }
示例#14
0
 public override void Reset(Vec3f pos)
 {
     m_Position = pos;
     m_Rotation = new Vec3f();
 }
示例#15
0
 public override void Reset(Vec3f dist)
 {
     m_Distance = Math.Abs(dist.z);
     m_Rotation = new Vec3f();
 }
示例#16
0
 public abstract void Reset(Vec3f pos);
示例#17
0
 public Vec3f Sub(Vec3f o)
 {
     return new Vec3f(x - o.x,
                         y - o.y,
                         z - o.z);
 }
示例#18
0
 abstract public void Reset(Vec3f pos);
示例#19
0
 public FloatVector(Vec3f v) { x = v.x; y = v.y; z = v.z; w = 1; }
示例#20
0
        private void fitScreen_Click(object sender, EventArgs e)
        {
            if(m_MeshDisplay.type != MeshDataStage.VSIn)
                return;

            controlType.SelectedIndex = 1;

            var state = GetUIState(m_MeshDisplay.type);

            Vec3f diag = state.m_MaxBounds.Sub(state.m_MinBounds);

            if(diag.x < 0.0f || diag.y < 0.0f || diag.z < 0.0f || diag.Length() <= 0.00001f)
                return;

            Vec3f middle = new Vec3f(state.m_MinBounds.x + diag.x / 2.0f,
                                     state.m_MinBounds.y + diag.y / 2.0f,
                                     state.m_MinBounds.z + diag.z / 2.0f);

            Vec3f pos = new Vec3f(middle);

            pos.z -= diag.Length();

            m_Flycam.Reset(pos);

            camSpeed.Value = Helpers.Clamp((decimal)(diag.Length() / 200.0f), camSpeed.Minimum, camSpeed.Maximum);

            m_CurrentCamera.Apply();
            m_Core.Renderer.BeginInvoke(RT_UpdateRenderOutput);
            render.Invalidate();
        }
示例#21
0
 public Vec3f Sub(Vec3f o)
 {
     return(new Vec3f(x - o.x,
                      y - o.y,
                      z - o.z));
 }
示例#22
0
        private void UI_FillRawData(UIState state)
        {
            var data = state.m_Data;

            Input input = state.m_Input;
            uint instance = m_CurInst;

            Thread th = new Thread(new ThreadStart(() =>
            {
                byte[][] d = data.Buffers;

                Stream rawStream = new MemoryStream(state.m_RawData);
                BinaryWriter rawWriter = new BinaryWriter(rawStream);

                uint rownum = 0;
                bool finished = false;

                var bufferFormats = input.BufferFormats;

                Vec3f minBounds = new Vec3f(float.MaxValue, float.MaxValue, float.MaxValue);
                Vec3f maxBounds = new Vec3f(-float.MaxValue, -float.MaxValue, -float.MaxValue);

                while (!finished)
                {
                    if (rownum >= data.IndexCount)
                    {
                        finished = true;
                        break;
                    }

                    uint index = rownum;

                    if (data.Indices != null)
                    {
                        if (rownum >= data.Indices.Length)
                        {
                            index = 0;
                        }
                        else
                        {
                            index = data.Indices[rownum];
                        }
                    }
                    else if ((input.Drawcall.flags & DrawcallFlags.UseIBuffer) != 0 && state == m_VSIn)
                    {
                        // no index buffer, but indexed drawcall
                        index = 0;
                    }

                    try
                    {
                        for (int el = 0; el < bufferFormats.Length; el++)
                        {
                            byte[] bytedata = d[bufferFormats[el].buffer];
                            Stream strm = state.m_Stream[bufferFormats[el].buffer];
                            BinaryReader read = state.m_Reader[bufferFormats[el].buffer];

                            uint offs = input.Strides[bufferFormats[el].buffer] * (bufferFormats[el].perinstance ? instance : index) +
                                                bufferFormats[el].offset;

                            if (!MeshView)
                                offs += ByteOffset;

                            bool outofBounds = false;

                            if (bytedata == null)
                            {
                                strm.Seek(0, SeekOrigin.Begin);
                            }
                            else if (offs >= bytedata.Length)
                            {
                                outofBounds = true;
                                strm = null;
                                read = new BinaryReader(new MemoryStream(m_Zeroes));
                            }
                            else
                            {
                                strm.Seek(offs, SeekOrigin.Begin);
                            }

                            string elname = bufferFormats[el].name.ToLowerInvariant();
                            var fmt = bufferFormats[el].format;
                            int byteWidth = (int)fmt.compByteWidth;

                            int bytesToRead = (int)(fmt.compByteWidth * fmt.compCount);

                            byte[] bytes = read.ReadBytes(bytesToRead);
                            rawWriter.Write(bytes);

                            if (bytes.Length != bytesToRead)
                                throw new System.IO.EndOfStreamException();

                            if (elname == "position" || elname == "sv_position")
                            {
                                for (int i = 0; i < fmt.compCount; i++)
                                {
                                    float val = 0;

                                    if (fmt.compType == FormatComponentType.Float)
                                    {
                                        if (byteWidth == 4)
                                            val = BitConverter.ToSingle(bytes, i * byteWidth);
                                        else if (byteWidth == 2)
                                            val = fmt.ConvertFromHalf(BitConverter.ToUInt16(bytes, i * byteWidth));
                                    }
                                    else
                                    {
                                        if (byteWidth == 4)
                                            val = (float)BitConverter.ToUInt32(bytes, i * byteWidth);
                                        else if (byteWidth == 2)
                                            val = (float)BitConverter.ToUInt16(bytes, i * byteWidth);
                                        else if (byteWidth == 1)
                                            val = (float)bytes[i * byteWidth];
                                    }

                                    if (outofBounds) continue;

                                    if (i == 0)
                                    {
                                        minBounds.x = Math.Min(minBounds.x, val);
                                        maxBounds.x = Math.Max(maxBounds.x, val);
                                    }
                                    else if (i == 1)
                                    {
                                        minBounds.y = Math.Min(minBounds.y, val);
                                        maxBounds.y = Math.Max(maxBounds.y, val);
                                    }
                                    else if (i == 2)
                                    {
                                        minBounds.z = Math.Min(minBounds.z, val);
                                        maxBounds.z = Math.Max(maxBounds.z, val);
                                    }
                                }
                            }
                        }
                    }
                    catch (System.IO.EndOfStreamException)
                    {
                        finished = true;
                    }

                    rownum++;
                }

                this.BeginInvoke(new Action(() =>
                {
                    state.m_MinBounds = minBounds;
                    state.m_MaxBounds = maxBounds;

                    UI_ShowRows(state);
                }));
            }));

            th.Start();

            state.m_DataParseThread = th;
        }
示例#23
0
 public FloatVector(Vec3f v, float W)
 {
     x = v.x; y = v.y; z = v.z; w = W;
 }
示例#24
0
 public void SetPosition(Vec3f p)
 {
     Camera_SetPosition(m_Real, p.x, p.y, p.z);
 }
示例#25
0
        public void Reset(Vec3f position)
        {
            m_Position = position;
            m_Rotation = new Vec3f();

            Camera.SetPosition(m_Position);
            Camera.SetFPSRotation(m_Rotation);
        }
示例#26
0
 public void SetFPSRotation(Vec3f r)
 {
     Camera_SetFPSRotation(m_Real, r.x, r.y, r.z);
 }
示例#27
0
        private void fitScreen_Click(object sender, EventArgs e)
        {
            if(m_MeshDisplay.type != MeshDataStage.VSIn)
                return;

            controlType.SelectedIndex = 1;

            var state = GetUIState(m_MeshDisplay.type);

            if (state.m_MinBounds == null || state.m_MaxBounds == null)
                return;

            if (CurPosElement < 0 || CurPosElement >= state.m_MinBounds.Length || CurPosElement >= state.m_MaxBounds.Length)
                return;

            Vec3f diag = state.m_MaxBounds[CurPosElement].Sub(state.m_MinBounds[CurPosElement]);

            if (diag.x < 0.0f || diag.y < 0.0f || diag.z < 0.0f || diag.Length() <= 1e-6f)
                return;

            Vec3f middle = new Vec3f(state.m_MinBounds[CurPosElement].x + diag.x / 2.0f,
                                     state.m_MinBounds[CurPosElement].y + diag.y / 2.0f,
                                     state.m_MinBounds[CurPosElement].z + diag.z / 2.0f);

            Vec3f pos = new Vec3f(middle);

            pos.z -= diag.Length();

            m_Flycam.Reset(pos);

            UI_UpdateBoundingBox();

            render.Invalidate();
        }
示例#28
0
 public void SetPosition(Vec3f p)
 {
     Camera_SetPosition(m_Real, p.x, p.y, p.z);
 }
示例#29
0
 public void SetFPSRotation(Vec3f r)
 {
     Camera_SetFPSRotation(m_Real, r.x, r.y, r.z);
 }
示例#30
0
        private void UI_FillRawData(UIState state, int horizScroll)
        {
            var data = state.m_Data;

            Input input = state.m_Input;
            uint instance = m_MeshDisplay.curInstance;

            Thread th = Helpers.NewThread(new ThreadStart(() =>
            {
                byte[][] d = data.Buffers;

                Stream rawStream = new MemoryStream(state.m_RawData);
                BinaryWriter rawWriter = new BinaryWriter(rawStream);

                uint rownum = 0;
                bool finished = false;

                var bufferFormats = input.BufferFormats;
                var generics = input.GenericValues;

                Vec3f[] minBounds = new Vec3f[bufferFormats.Length];
                Vec3f[] maxBounds = new Vec3f[bufferFormats.Length];

                for (int el = 0; el < bufferFormats.Length; el++)
                {
                    minBounds[el] = new Vec3f(float.MaxValue, float.MaxValue, float.MaxValue);
                    maxBounds[el] = new Vec3f(-float.MaxValue, -float.MaxValue, -float.MaxValue);

                    if (bufferFormats[el].format.compCount == 1)
                        minBounds[el].y = maxBounds[el].y = minBounds[el].z = maxBounds[el].z = 0.0f;
                    if (bufferFormats[el].format.compCount == 2)
                        minBounds[el].z = maxBounds[el].z = 0.0f;
                }

                while (!finished)
                {
                    if (rownum >= data.IndexCount)
                    {
                        finished = true;
                        break;
                    }

                    uint index = rownum;

                    if (data.Indices != null)
                    {
                        if (rownum >= data.Indices.Length)
                        {
                            index = 0;
                        }
                        else
                        {
                            index = data.Indices[rownum];
                        }
                    }
                    else if ((input.Drawcall.flags & DrawcallFlags.UseIBuffer) != 0 && state == m_VSIn)
                    {
                        // no index buffer, but indexed drawcall
                        index = 0;
                    }

                    int elemsWithData = 0;

                    for (int el = 0; el < bufferFormats.Length; el++)
                    {
                        if (generics != null && generics[el] != null)
                        {
                            for(int g=0; g < generics[el].Length; g++)
                            {
                                if (generics[el][g] is uint)
                                    rawWriter.Write((uint)generics[el][g]);
                                else if (generics[el][g] is int)
                                    rawWriter.Write((int)generics[el][g]);
                                else if (generics[el][g] is float)
                                    rawWriter.Write((float)generics[el][g]);
                            }

                            continue;
                        }

                        try
                        {
                            byte[] bytedata = d[bufferFormats[el].buffer];
                            Stream strm = state.m_Stream[bufferFormats[el].buffer];
                            BinaryReader read = state.m_Reader[bufferFormats[el].buffer];

                            uint instIdx = 0;
                            // for instancing, need to handle instance rate being 0 (every instance takes index 0 in that case)
                            if (bufferFormats[el].perinstance)
                                instIdx = bufferFormats[el].instancerate > 0 ? (instance / (uint)bufferFormats[el].instancerate) : 0;
                            else
                                instIdx = index;

                            uint stride = input.Strides[bufferFormats[el].buffer];
                            if (data.PostVS.stride != 0)
                                stride = data.PostVS.stride;

                            uint offs = stride * instIdx + bufferFormats[el].offset;

                            bool outofBounds = false;

                            if (bytedata == null)
                            {
                                strm.Seek(0, SeekOrigin.Begin);
                            }
                            else if (offs >= bytedata.Length)
                            {
                                outofBounds = true;
                                strm = null;
                                read = new BinaryReader(new MemoryStream(m_Zeroes));
                            }
                            else
                            {
                                strm.Seek(offs, SeekOrigin.Begin);
                            }

                            string elname = bufferFormats[el].name.ToUpperInvariant();
                            var fmt = bufferFormats[el].format;
                            int byteWidth = (int)fmt.compByteWidth;

                            int bytesToRead = (int)(fmt.compByteWidth * fmt.compCount);

                            byte[] bytes = read.ReadBytes(bytesToRead);
                            rawWriter.Write(bytes);

                            if (bytes.Length != bytesToRead)
                                continue;

                            // update min/max for this element
                            {
                                for (int i = 0; i < fmt.compCount; i++)
                                {
                                    float val = 0;

                                    if (fmt.compType == FormatComponentType.Float)
                                    {
                                        if (byteWidth == 4)
                                            val = BitConverter.ToSingle(bytes, i * byteWidth);
                                        else if (byteWidth == 2)
                                            val = fmt.ConvertFromHalf(BitConverter.ToUInt16(bytes, i * byteWidth));
                                    }
                                    else
                                    {
                                        if (byteWidth == 4)
                                            val = (float)BitConverter.ToUInt32(bytes, i * byteWidth);
                                        else if (byteWidth == 2)
                                            val = (float)BitConverter.ToUInt16(bytes, i * byteWidth);
                                        else if (byteWidth == 1)
                                            val = (float)bytes[i * byteWidth];
                                    }

                                    if (outofBounds) continue;

                                    if (i == 0)
                                    {
                                        minBounds[el].x = Math.Min(minBounds[el].x, val);
                                        maxBounds[el].x = Math.Max(maxBounds[el].x, val);
                                    }
                                    else if (i == 1)
                                    {
                                        minBounds[el].y = Math.Min(minBounds[el].y, val);
                                        maxBounds[el].y = Math.Max(maxBounds[el].y, val);
                                    }
                                    else if (i == 2)
                                    {
                                        minBounds[el].z = Math.Min(minBounds[el].z, val);
                                        maxBounds[el].z = Math.Max(maxBounds[el].z, val);
                                    }
                                }
                            }

                            elemsWithData++;
                        }
                        catch (System.IO.EndOfStreamException)
                        {
                            // don't increment elemsWithData
                        }
                    }

                    finished = (elemsWithData == 0);

                    rownum++;
                }

                this.BeginInvoke(new Action(() =>
                {
                    state.m_MinBounds = minBounds;
                    state.m_MaxBounds = maxBounds;

                    UI_UpdateBoundingBox();

                    UI_ShowRows(state, horizScroll);
                }));
            }));

            th.Start();

            state.m_DataParseThread = th;
        }