Exemplo n.º 1
0
    public RayTracingEngine(int quality, int width, int height)
    {
        maxSampleNum_ = quality;
        width_        = width;
        height_       = height;
        CameraParam cameraParam = new CameraParam();

        cameraParam.lookFrom.Set(13.0f, 2.0f, 3.0f);
        cameraParam.lookAt.Set(0.0f, 0.0f, 0.0f);
        cameraParam.aspect        = (float)width_ / (float)height_;
        cameraParam.fstop         = 4.0f;
        cameraParam.focusDistance = 10.0f;
        cameraParam.fov           = 20.0f;
        cameraParam.t1            = 1.0f;
        cameraRay_ = new CameraRay(cameraParam);
        pixel_     = new Color[width_, height_];
        for (int y = height_ - 1; y >= 0; --y)
        {
            for (int x = 0; x < width_; ++x)
            {
                pixel_[x, y] = Color.black;
            }
        }
        y_ = 0;
    }
Exemplo n.º 2
0
        private void buttonReadParam_Click(object sender, EventArgs e)
        {
            if (_isParamChanged)
            {
                if (MessageBox.Show("参数未保存,确定替换?", "提示信息", MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
            }

            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Multiselect = false;
            dialog.Title       = "请选择输入文件";
            dialog.Filter      = "相机配置文件(*.dat)|*.dat";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string transit = CameraParam.CameraParamPath;
                CameraParam.CameraParamPath = dialog.FileName;
                CameraParam = CameraParam.DeSerializeAndRead();
                CameraParam.CameraParamPath = transit;

                DisplayParam(CameraParam, 0);
            }
            RearrangeCameraName();
        }
Exemplo n.º 3
0
    private void SwitchCamMode(CameraMode mode, CameraContext context = null)
    {
        if (cameraControlModeParam == null || curCameraModeParam == null)
        {
            return;
        }
        CameraMode oldMode = cameraMode;

        cameraMode = mode;  //保证外部拿到的cameraMode是当前的?

        if (camCtrl != null)
        {
            if (camCtrl.GetCameraMode() == mode)    //同一个状态不能重复进入
            {
                return;
            }
            curCameraModeParam.FOV               = m_userDesireFov;
            curCameraModeParam.curPitchAngle     = m_userDesireAngle.x;
            curCameraModeParam.curDistance       = m_userDesireDistance;
            cameraControlModeParam[(int)oldMode] = curCameraModeParam;
            camCtrl.Leave();
        }
        camCtrl = CameraUtil.GetCamCtrl(mode);
        camCtrl.curCameraMode = mode;
        curCameraModeParam    = cameraControlModeParam[(int)mode];
        camCtrl.Enter(context);
    }
Exemplo n.º 4
0
 public void SaveParams()
 {
     m_SavedParams = new CameraParam();
     if (TargetCameraEnable)
     {
         m_SavedParams.cullingMask = m_TargetCam.cullingMask;
         m_SavedParams.fov         = m_TargetCam.fieldOfView;
         m_SavedParams.farClip     = m_TargetCam.farClipPlane;
         m_SavedParams.nearClip    = m_TargetCam.nearClipPlane;
     }
 }
Exemplo n.º 5
0
        private void PlateReceived(object sender, PlateEventArgs e)
        {
            IdentificationInfo info        = new IdentificationInfo(e.LicensePlateNumber, e.LicensePlateType, e.LicensePlateColor, e.PanoramaImage, e.VehicleImage, e.IdentificationTime);
            CameraParam        cameraParam = m_CameraParams.Where(w => w.Ip == e.IP).FirstOrDefault();

            if (cameraParam != null)
            {
                IDoor door = cameraParam.Direction == Directions.Enter ? EnterDoor : ExitDoor;
                door.Execute(info);
            }
        }
Exemplo n.º 6
0
        public CameraParam GetCopy()
        {
            CameraParam param = new CameraParam();

            param.curDistance     = this.curDistance;
            param.distanceRange   = this.distanceRange;
            param.curPitchAngle   = this.curPitchAngle;
            param.pitchAngleRange = this.pitchAngleRange;
            param.targetOffset    = this.targetOffset;
            param.FOV             = this.FOV;
            param.modeID          = this.modeID;

            return(param);
        }
Exemplo n.º 7
0
    public void updateCameraParam(int sceneType, int heroType)
    {
        if (sceneType >= 0)
        {
            currentSceneType = sceneType;
        }
        if (heroType >= 0)
        {
            currentHeroType = heroType;
        }
        CameraParam[] cameraInfo = ASpeedGame.Data.CameraConfig.CameraConfig.Instance.GetCameraConfigInfo(sceneType, heroType);
        if (cameraInfo != null)
        {
            if (cameraControlModeParam == null)
            {
                cameraControlModeParam = new CameraParam[(int)CameraMode.MaxCount];

                for (int i = 0; i < (int)CameraMode.MaxCount; i++)
                {
                    cameraControlModeParam[i]        = cameraInfo[0].GetCopy();
                    cameraControlModeParam[i].modeID = i;
                }
            }
            cameraControlModeParam[(int)CameraMode.UserControl]        = cameraInfo[0].GetCopy();
            cameraControlModeParam[(int)CameraMode.FloatingControl]    = cameraInfo[1].GetCopy();
            cameraControlModeParam[(int)CameraMode.FPSMode]            = cameraInfo[2].GetCopy();
            cameraControlModeParam[(int)CameraMode.SniperscopeControl] = cameraInfo[3].GetCopy();
        }

        if (cameraMode < CameraMode.MaxCount)
        {
            curCameraModeParam = cameraControlModeParam[(int)cameraMode];
            m_userDesireFov    = curCameraModeParam.FOV;
            SetUserDesireAngleX(curCameraModeParam.curPitchAngle);
            m_userDesireDistance = curCameraModeParam.curDistance;

            if (CurCameraProperty != null)
            {
                CurCameraProperty.NormalFOV          = (int)curCameraModeParam.FOV;
                CurCameraProperty.NormalDistance     = curCameraModeParam.curDistance;
                CurCameraProperty.NormalHeight       = curCameraModeParam.targetOffset;
                CurCameraProperty.InitedEulerAngle.x = curCameraModeParam.curPitchAngle;
            }
        }
        else
        {
            SwitchCamModeDefault();
        }
    }
Exemplo n.º 8
0
    public CameraRay(CameraParam param)
    {
        lensRadius_ = 0.5f / param.fstop;
        var theta      = param.fov * Mathf.PI / 180.0f;
        var halfHeight = Mathf.Tan(theta / 2.0f);
        var halfWidth  = param.aspect * halfHeight;

        origin_          = param.lookFrom;
        w_               = (param.lookFrom - param.lookAt).normalized;
        u_               = Vector3.Cross(param.vup, w_).normalized;
        v_               = Vector3.Cross(w_, u_);
        lowerLeftCorner_ = origin_ - param.focusDistance * (halfWidth * u_ + halfHeight * v_ + w_);
        horizontal_      = 2.0f * halfWidth * u_ * param.focusDistance;
        vertical_        = 2.0f * halfHeight * v_ * param.focusDistance;
        time0_           = param.t0;
        time1_           = param.t1;
    }
Exemplo n.º 9
0
        public PTZ ScreenLocationToAngleLocation(Point location, CameraParam cameraParam)
        {
            double radianCameraPan  = cameraParam.Pan.ToRadian();
            double radianCameraTilt = cameraParam.Tilt.ToRadian();

            double radianHorizontalFieldOfView = cameraParam.HorizontalFieldOfView.ToRadian();
            double radianVerticalFieldOfView   = cameraParam.VerticalFieldOfView.ToRadian();

            double horizontalNormalizedDisplacement = location.X / _width;
            double verticalNormalizedDisplacement   = location.Y / _height;

            double panAngleToCamera  = NormalizedDisplacementToAngle(radianHorizontalFieldOfView, horizontalNormalizedDisplacement);
            double tiltAngleToCamera = NormalizedDisplacementToAngle(radianVerticalFieldOfView, verticalNormalizedDisplacement);

            double absolutePanAngle  = CameraAngleToAbsoluteAngle(panAngleToCamera, radianCameraPan);
            double absoluteTiltAngle = CameraAngleToAbsoluteAngle(tiltAngleToCamera, radianCameraTilt);

            return(new PTZ(absolutePanAngle.ToDegree(), absoluteTiltAngle.ToDegree(), 1));
        }
Exemplo n.º 10
0
    void SaveScreenShot()
    {
        CameraParamList list = new CameraParamList();

        for (int i = 0; i < cameras.Length; ++i)
        {
            CameraParam cam = new CameraParam();
            cam.mat = cameras[i].projectionMatrix * cameras[i].worldToCameraMatrix;
            cam.id  = i;

            cam.img = "/" + i.ToString() + ".png";
            string imgPath = SaveRenderTextureToFile(cameras[i].targetTexture, cam.img);

            list.arr.Add(cam);
        }

        string camInfo = JsonUtility.ToJson(list);

        System.IO.File.WriteAllText(Application.streamingAssetsPath + "/camera.json", camInfo);
    }
Exemplo n.º 11
0
        private void buttonSaveParam_Click(object sender, EventArgs e)
        {
            if (false == UpdateAllData(CurrentCameraIndex, CurrentCameraName))
            {
                return;
            }

            if (!checkBoxConstPath.Checked)
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter = "相机配置文件(*.dat)|*.dat";
                //设置默认文件类型显示顺序
                sfd.FilterIndex = 1;
                //保存对话框是否记忆上次打开的目录
                sfd.RestoreDirectory = true;

                string localFilePath = "";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    localFilePath = sfd.FileName.ToString();
                }
                else
                {
                    MessageBox.Show("保存失败");
                    return;
                }

                //暂存固定路径于中转站,使用后恢复路径
                string transit = CameraParam.CameraParamPath;
                CameraParam.CameraParamPath = localFilePath;
                CameraParam.SerializeAndSave();
                CameraParam.CameraParamPath = transit;
            }
            else
            {
                CameraParam.SerializeAndSave();
            }

            _isParamChanged = false;
            RearrangeCameraName();
        }
Exemplo n.º 12
0
 public Point AngleLocationToScreenLocation(double panAngle, double tiltAngle, CameraParam cameraParam)
 {
     return(AngleLocationToScreenLocation(panAngle, tiltAngle, cameraParam.Pan, cameraParam.Tilt, cameraParam.HorizontalFieldOfView, cameraParam.VerticalFieldOfView));
 }
Exemplo n.º 13
0
        private void FindCamera(object sender, CameraEventArgs e)
        {
            CameraParam cameraParam = new CameraParam(e.IpAddress, e.Port, e.Brand);

            m_CameraParams.Add(cameraParam);
        }
Exemplo n.º 14
0
    public void Load()
    {
        TextAsset txt = (TextAsset)ResManager.singleton.LoadAsset(CAMERA_CONFIG, typeof(TextAsset));

        cfg = JsonMapper.ToObject <CameraParam>(txt.text);
    }