예제 #1
0
        public void attachTo(Attachment thisatch, Attachment thatatch, Object3D targetObj)
        {
            for (int i = 0; i < atch_info.Count; i++)
            {
                if (atch_info[i].thisAtch == thatatch)
                {
                    atch_info.RemoveAt(i);
                    break;
                }
            }
            attachmentInfo new_atif = new attachmentInfo();

            new_atif.thisAtch   = thisatch;
            new_atif.thatAtch   = thatatch;
            new_atif.thisObject = this;
            new_atif.AttachedTo = targetObj;
            new_atif.Attach();
            atch_info.Add(new_atif);
        }
예제 #2
0
        public static bool inSight(Object3D obj, Camera cam)
        {
            Matrix4 mtx  = obj.transform;
            Vector3 pos1 = ToScreen(Vector3.TransformPosition(obj.model.size.nXnYnZ, mtx), cam);
            Vector3 pos2 = ToScreen(Vector3.TransformPosition(obj.model.size.pXnYnZ, mtx), cam);
            Vector3 pos3 = ToScreen(Vector3.TransformPosition(obj.model.size.nXpYnZ, mtx), cam);
            Vector3 pos4 = ToScreen(Vector3.TransformPosition(obj.model.size.nXnYpZ, mtx), cam);
            Vector3 pos5 = ToScreen(Vector3.TransformPosition(obj.model.size.pXpYnZ, mtx), cam);
            Vector3 pos6 = ToScreen(Vector3.TransformPosition(obj.model.size.pXnYpZ, mtx), cam);
            Vector3 pos7 = ToScreen(Vector3.TransformPosition(obj.model.size.nXpYpZ, mtx), cam);
            Vector3 pos8 = ToScreen(Vector3.TransformPosition(obj.model.size.pXpYpZ, mtx), cam);
            float   Left =
                Math.Min(pos1.X,
                         Math.Min(pos2.X,
                                  Math.Min(pos3.X,
                                           Math.Min(pos4.X,
                                                    Math.Min(pos5.X,
                                                             Math.Min(pos6.X,
                                                                      Math.Min(pos7.X, pos8.X)))))));
            float Right =
                Math.Max(pos1.X,
                         Math.Max(pos2.X,
                                  Math.Max(pos3.X,
                                           Math.Max(pos4.X,
                                                    Math.Max(pos5.X,
                                                             Math.Max(pos6.X,
                                                                      Math.Max(pos7.X, pos8.X)))))));
            float Bottom =
                Math.Min(pos1.Y,
                         Math.Min(pos2.Y,
                                  Math.Min(pos3.Y,
                                           Math.Min(pos4.Y,
                                                    Math.Min(pos5.Y,
                                                             Math.Min(pos6.Y,
                                                                      Math.Min(pos7.Y, pos8.Y)))))));
            float Top =
                Math.Max(pos1.Y,
                         Math.Max(pos2.Y,
                                  Math.Max(pos3.Y,
                                           Math.Max(pos4.Y,
                                                    Math.Max(pos5.Y,
                                                             Math.Max(pos6.Y,
                                                                      Math.Max(pos7.Y, pos8.Y)))))));
            float Depth =
                Math.Max(pos1.Z,
                         Math.Max(pos2.Z,
                                  Math.Max(pos3.Z,
                                           Math.Max(pos4.Z,
                                                    Math.Max(pos5.Z,
                                                             Math.Max(pos6.Z,
                                                                      Math.Max(pos7.Z, pos8.Z)))))));

            if (Left > 1)
            {
                return(false);
            }
            if (Right < -1)
            {
                return(false);
            }
            if (Bottom > 1)
            {
                return(false);
            }
            if (Top < -1)
            {
                return(false);
            }
            if (Depth < 0)
            {
                return(false);
            }
            return(true);
        }
예제 #3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            DateTime t = DateTime.Now.AddSeconds(1 / 60.0);

            if (_targetObj != null)
            {
                if (_transtime < 0)
                {
                    _transtime = 0;
                    cam.pivot  = _targetObj.position;
                    if (_panzoom)
                    {
                        cam.position = _fromcampos - _frompos + _targetObj.position;
                    }
                    cam.zoom   = _targetObj.model.size.maxS * 4F;
                    _targetObj = null;
                }
                else
                {
                    cam.pivot = Vector3.Lerp(_targetObj.position, _frompos, _smoothtranstime);
                    if (_panzoom)
                    {
                        cam.position = Vector3.Lerp(_fromcampos - _frompos + _targetObj.position, _fromcampos, _smoothtranstime);
                    }
                    cam.zoom = lerp(_targetObj.model.size.maxS * 4F, _fromzoom, _smoothtranstime);
                }
            }
            if (Forward)
            {
                Vector3 vel    = new Vector3(0, 0, -cam.zoom / 40F);
                Matrix4 rotmtx = cam.look_at_mtx.ClearTranslation();
                cam.pivot    += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation();
                cam.position += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation();
            }
            if (Backward)
            {
                Vector3 vel    = new Vector3(0, 0, cam.zoom / 40F);
                Matrix4 rotmtx = cam.look_at_mtx.ClearTranslation();
                cam.pivot    += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation();
                cam.position += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation();
            }
            if (SideLeft)
            {
                Vector3 vel    = new Vector3(-cam.zoom / 40F, 0, 0);
                Matrix4 rotmtx = cam.look_at_mtx.ClearTranslation();
                cam.pivot    += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation();
                cam.position += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation();
            }
            if (SideRight)
            {
                Vector3 vel    = new Vector3(cam.zoom / 40F, 0, 0);
                Matrix4 rotmtx = cam.look_at_mtx.ClearTranslation();
                cam.pivot    += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation();
                cam.position += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation();
            }
            if (SideUp)
            {
                Vector3 vel    = new Vector3(0, cam.zoom / 40F, 0);
                Matrix4 rotmtx = cam.look_at_mtx.ClearTranslation();
                cam.pivot    += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation();
                cam.position += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation();
            }
            if (SideDown)
            {
                Vector3 vel    = new Vector3(0, -cam.zoom / 40F, 0);
                Matrix4 rotmtx = cam.look_at_mtx.ClearTranslation();
                cam.pivot    += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation();
                cam.position += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation();
            }
            if (!DesignMode)
            {
                GL.MatrixMode(MatrixMode.Modelview);
                //Import Objects if necessary
                if (_ObjectsToLoad.Count > 0)
                {
                    foreach (string objectpath in _ObjectsToLoad)
                    {
                        Object3D obj = new Object3D(objectpath);
                        if (_AttachmentToAttachTo == null)
                        {
                            goto no;
                        }
                        if (!obj.attachTo(_AttachmentToAttachTo, Object3D.Active_Object))
                        {
                            goto no;
                        }
                        goto yes;
                        no :;
                        obj.position = cam.pivot;
                        yes :;
                        GoToObject(obj, true);
                        Object3D.database.Add(obj);
                        Object3D.Active_Object = obj;
                    }
                    _ObjectsToLoad = new List <string>();
                }
                //End of Import
                Matrix4 mtx = cam.matrix;
                GL.LoadMatrix(ref mtx);
                GL.Clear(ClearBufferMask.ColorBufferBit);
                GL.Clear(ClearBufferMask.DepthBufferBit);
                for (float i = -100; i <= 100; i += 10)
                {
                    GL.Color3(Color.Green);
                    GL.LineWidth(0.5F);
                    GL.Begin(PrimitiveType.Lines);
                    GL.Vertex3(i, 100, 0);
                    GL.Vertex3(i, -100, 0);
                    GL.End();
                    GL.Begin(PrimitiveType.Lines);
                    GL.Vertex3(100, i, 0);
                    GL.Vertex3(-100, i, 0);
                    GL.End();
                }
                GL.LineWidth(1F);

                /*GL.Begin(PrimitiveType.Polygon);
                 * GL.Color3(Color.Red);
                 * for (int i = 0; i < 360; i += 60)
                 * {
                 *  GL.Vertex3(Math.Sin(i * Math.PI / 180) * 30 + mx - Width / 2, Math.Cos(i * Math.PI / 180) * 30 - my + Height / 2, -8);
                 * }
                 * GL.End();
                 * GL.Begin(PrimitiveType.Polygon);
                 * GL.Color3(Color.White);
                 * for (int i = 0; i < 360; i += 60)
                 * {
                 *  GL.Vertex3(Math.Sin(i * Math.PI / 180) * 20 + mx - Width / 2, Math.Cos(i * Math.PI / 180) * 20 - my + Height / 2, -5);
                 * }
                 * GL.End();*/
                foreach (Object3D obj in Object3D.database)
                {
                    obj.DrawObject(_pgm, _coll, _wf, inSight(obj, cam));
                }
                switch (Form1.current_tool)
                {
                case Tools.Select:
                    if (tr.Hit)
                    {
                        GL.Color3(0.8F, 0.8F, 0.8F);
                        ToolModels.DrawBall(tr.HitPos, cam.zoom / 120F, 16);
                    }
                    break;

                case Tools.Decorate:
                    if (tr.Hit)
                    {
                        GL.Color3(1F, 0, 0);
                        ToolModels.DrawBall(tr.HitPos, cam.zoom / 50F, 16);
                        GL.Color3(1F, 1F, 0);
                        GL.LineWidth(2F);
                        GL.Begin(PrimitiveType.Lines);
                        GL.Vertex3(tr.HitPos);
                        GL.Vertex3(tr.HitPos + tr.HitNormal * cam.zoom / 15F);
                        GL.End();
                    }
                    break;
                }
                GL.Clear(ClearBufferMask.DepthBufferBit);
                if (Object3D.Active_Object != null)
                {
                    Object3D.Active_Object.DrawTool();
                }
                SwapBuffers();
            }
            if (Forward || Backward || SideLeft || SideRight || SideUp || SideDown || (_targetObj != null))
            {
                while (DateTime.Now < t)
                {
                }
                _transtime -= 1 / 30F;
                Invalidate();
            }
        }