// private DrawBuffer dummy_draw_buffer_; void Start() { TaskManager.Instance.init(); Sight.Instance.init(null /* material */); LockTarget.createPool(); list_ = new List<TestTask>(); GameObject prefab = null; for (var i = 0; i < MAX; ++i) { GameObject go; if (prefab == null) { prefab = GameObject.Find("Cube"); go = prefab; } else { float range = 8; go = Instantiate(prefab, new Vector3(Random.Range(-range, range), Random.Range(-range, range), Random.Range(-range, range)), Quaternion.identity) as GameObject; } var task = new TestTask(); var pos = go.transform.position; var rot = go.transform.rotation; task.init(ref pos, ref rot); var lock_target = LockTarget.create(task, ref CV.Vector3Zero); task.lock_target_ = lock_target; task.owner_ = go; list_.Add(task); } camera_ = Camera.main; my_camera_ = MyCamera.create(); // dummy_draw_buffer_ = new DrawBuffer(); }
public MainMenu(MyCamera parent, SFManager sfmgr, SFMovieCreationParams cp) : base(sfmgr, cp) { this.parent = parent; SFMgr = sfmgr; this.SetFocus(true); }
void Awake() { string targetname = gameObject.transform.root.name; identifier = int.Parse(targetname.Substring(3)); targetname = "Camera" + targetname.Substring(3); targetcamera = GameObject.Find (targetname).GetComponent<MyCamera>(); initialize (); }
public override void renderUpdate(int front, MyCamera camera, ref DrawBuffer draw_buffer) { const float LENGTH = 2.5f; var tail = rigidbody_.transform_.position_ - rigidbody_.velocity_.normalized * LENGTH; Beam.Instance.renderUpdate(front, beam_id_, ref rigidbody_.transform_.position_, ref tail); }
// Use this for initialization new void Start() { base.Start(); theCamera = FindObjectOfType<MyCamera> (); thePlayer = GameObject.FindGameObjectWithTag("Player"); theCharacterMotor = GetComponent<CharacterMotor> (); theCharacterShoot = GetComponent<CharacterShoot> (); enemyShotStartPos = transform.FindChild ("ShotStartPos").gameObject.GetComponent<Transform> (); }
void Awake() { string targetname = gameObject.transform.root.name; identifier = int.Parse(targetname.Substring(3)); string carobjectname = "/" + targetname + "/Car" ; carobject = GameObject.Find (carobjectname).gameObject; targetcameraname = "/" + targetname + "/Camera" ; targetcamera = GameObject.Find (targetcameraname).GetComponent<MyCamera>(); targetsubcameraname = "/" + targetname + "/SubCamera"; targetsubcamera = GameObject.Find (targetsubcameraname).GetComponent<MySubCamera>(); initialize(); }
public abstract void renderUpdate(int front, MyCamera camera, ref DrawBuffer draw_buffer);
public override void LoadData() { MainCamera = new MyCamera(MySandboxGame.Config.FieldOfView, MySandboxGame.ScreenViewport); MainCamera.FarPlaneDistance = MySession.Static.Settings.ViewDistance; MyEntities.LoadData(); }
public void InitCamera(string ID) { int numberID = -1; int nRet = MyCamera.MV_OK; MyCamera.MV_CC_DEVICE_INFO device; try { nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref m_pDeviceList); for (int i = 0; i < m_pDeviceList.nDeviceNum; i++) { device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(m_pDeviceList.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO)); if (device.nTLayerType == MyCamera.MV_GIGE_DEVICE) { IntPtr buffer = Marshal.UnsafeAddrOfPinnedArrayElement(device.SpecialInfo.stGigEInfo, 0); MyCamera.MV_GIGE_DEVICE_INFO gigeInfo = (MyCamera.MV_GIGE_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MyCamera.MV_GIGE_DEVICE_INFO)); if (gigeInfo.chUserDefinedName == ID) { Mac = gigeInfo.chSerialNumber; numberID = i; break; } } else if (device.nTLayerType == MyCamera.MV_USB_DEVICE) { IntPtr buffer = Marshal.UnsafeAddrOfPinnedArrayElement(device.SpecialInfo.stUsb3VInfo, 0); MyCamera.MV_USB3_DEVICE_INFO usbInfo = (MyCamera.MV_USB3_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MyCamera.MV_USB3_DEVICE_INFO)); if (usbInfo.chUserDefinedName == ID) { Mac = usbInfo.chSerialNumber; numberID = i; break; } } } device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(m_pDeviceList.pDeviceInfo[numberID], typeof(MyCamera.MV_CC_DEVICE_INFO)); //打开设备 if (null == m_pMyCamera) { m_pMyCamera = new MyCamera(); if (null == m_pMyCamera) { return; } } nRet = m_pMyCamera.MV_CC_CreateDevice_NET(ref device); if (MyCamera.MV_OK != nRet) { throw new Exception($"failed to create camera {m_Cameraname}"); } nRet = m_pMyCamera.MV_CC_OpenDevice_NET(); if (MyCamera.MV_OK != nRet) { m_pMyCamera.MV_CC_DestroyDevice_NET(); throw new Exception($"failed to open camera {m_Cameraname}"); } // ch:探测网络最佳包大小(只对GigE相机有效) | en:Detection network optimal package size(It only works for the GigE camera) if (device.nTLayerType == MyCamera.MV_GIGE_DEVICE) { int nPacketSize = m_pMyCamera.MV_CC_GetOptimalPacketSize_NET(); if (nPacketSize > 0) { nRet = m_pMyCamera.MV_CC_SetIntValue_NET("GevSCPSPacketSize", (uint)nPacketSize); if (nRet != MyCamera.MV_OK) { throw new Exception("Warning: Set Packet Size failed"); } } else { throw new Exception("Warning: Get Packet Size failed"); } } // ch:设置采集连续模式 | en:Set Continues Aquisition Mode m_pMyCamera.MV_CC_SetEnumValue_NET("AcquisitionMode", 2); // ch:工作在连续模式 | en:Acquisition On Continuous Mode m_pMyCamera.MV_CC_SetEnumValue_NET("TriggerMode", 0); // ch:连续模式 | en:Continuous m_pMyCamera.MV_CC_SetEnumValue_NET("TriggerSource", 7); //ch:触发源设为软触发 | en:Set trigger source as Software //ImageCallback = new MyCamera.cbOutputExdelegate(ImageOut); //nRet = m_pMyCamera.MV_CC_RegisterImageCallBackEx_NET(ImageCallback, IntPtr.Zero); //if (MyCamera.MV_OK != nRet) //{ // throw new Exception("Register image callback failed!"); //} //ExceptionCallback = new MyCamera.cbExceptiondelegate(Exception); //nRet = m_pMyCamera.MV_CC_RegisterImageCallBackEx_NET(ImageCallback, IntPtr.Zero); //if (MyCamera.MV_OK != nRet) //{ // throw new Exception("Register image exception callback failed!"); //} //开启抓图 nRet = m_pMyCamera.MV_CC_StartGrabbing_NET(); if (MyCamera.MV_OK != nRet) { throw new Exception("Start grabbing failed"); } } catch (Exception ex) { throw new Exception(ID + "初始化失败:" + ex.Message); } }
/// <summary> /// 海康相机 /// </summary> /// <returns></returns> public static List <string> GetHikCameraListInfo() { List <string> cameralist = new List <string>(); try { MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST(); int nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE, ref stDevList); if (MyCamera.MV_OK != nRet) { return(cameralist); } ///设备信息 MyCamera.MV_CC_DEVICE_INFO stDevInfo; for (int i = 0; i < stDevList.nDeviceNum; i++) { stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO)); if (MyCamera.MV_GIGE_DEVICE == stDevInfo.nTLayerType) { MyCamera.MV_GIGE_DEVICE_INFO stGigEDeviceInfo = (MyCamera.MV_GIGE_DEVICE_INFO)MyCamera.ByteToStruct(stDevInfo.SpecialInfo.stGigEInfo, typeof(MyCamera.MV_GIGE_DEVICE_INFO)); if (!string.IsNullOrEmpty(stGigEDeviceInfo.chUserDefinedName)) { cameralist.Add(stGigEDeviceInfo.chUserDefinedName); } } else if (MyCamera.MV_USB_DEVICE == stDevInfo.nTLayerType) { MyCamera.MV_USB3_DEVICE_INFO stUsb3DeviceInfo = (MyCamera.MV_USB3_DEVICE_INFO)MyCamera.ByteToStruct(stDevInfo.SpecialInfo.stUsb3VInfo, typeof(MyCamera.MV_USB3_DEVICE_INFO)); if (!string.IsNullOrEmpty(stUsb3DeviceInfo.chUserDefinedName)) { cameralist.Add(stUsb3DeviceInfo.chUserDefinedName); } } } } catch (Exception e) { LogFileManager.Error("Camera", e.ToString()); } return(cameralist); }
public bool Update() { if (!Enabled) { return(AutoDelete); //efect is not enabled at all and must be deleted } System.Diagnostics.Debug.Assert(WorldMatrix != MyUtils.ZeroMatrix, "Effect world matrix was not set!"); if (!m_isPreloading && !m_wasPreloaded && m_preload > 0) { m_isPreloading = true; // TODO: Optimize (preload causes lags, depending on preload size, it's from 0 ms to 85 ms) //while (m_elapsedTime < m_preload) //{ // Update(); //} m_isPreloading = false; m_wasPreloaded = true; } MyRender.GetRenderProfiler().StartProfilingBlock("ParticleEffect-Update"); if (!m_isPreloading && IsInFrustum) { MyPerformanceCounter.PerCameraDraw.ParticleEffectsDrawn++; } MyRender.GetRenderProfiler().EndProfilingBlock(); MyRender.GetRenderProfiler().StartProfilingBlock("ParticleEffect-UpdateGen"); m_elapsedTime += MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS; m_distance = MyCamera.GetDistanceWithFOV(WorldMatrix.Translation) / (UserScale * 1000.0f); m_particlesCount = 0; m_birthRate = 0; m_AABB = m_AABB.CreateInvalid(); if (CalculateDeltaMatrix) { DeltaMatrix = Matrix.Invert(m_lastWorldMatrix) * m_worldMatrix; } if (RenderCounter == 0 || ((MyRender.RenderCounter - RenderCounter) < FRAMES_TO_SKIP)) //more than FRAMES_TO_SKIP frames consider effect as invisible { foreach (MyParticleGeneration generation in m_generations) { generation.EffectMatrix = WorldMatrix; generation.Update(); m_particlesCount += generation.GetParticlesCount(); m_birthRate += generation.GetBirthRate(); BoundingBox bbox = generation.GetAABB(); m_AABB = m_AABB.Include(ref bbox); } m_lastWorldMatrix = m_worldMatrix; if (m_particlesCount > 0) { m_hasShownSomething = true; } IsInFrustum = MyCamera.IsInFrustum(ref m_AABB); } MyRender.GetRenderProfiler().EndProfilingBlock(); if (((m_particlesCount == 0 && HasShownSomething()) || (m_particlesCount == 0 && m_birthRate == 0.0f)) && AutoDelete && !m_isPreloading) { //Effect was played and has to be deleted return(true); } if (!m_isPreloading && OnUpdate != null) { OnUpdate(this, null); } return(false); }
public void ReceiveImageWorkThread(object obj) { int nRet = MyCamera.MV_OK; MyCamera device = obj as MyCamera; MyCamera.MV_FRAME_OUT_INFO_EX pFrameInfo = new MyCamera.MV_FRAME_OUT_INFO_EX(); IntPtr pData = Marshal.AllocHGlobal((int)g_nPayloadSize * 3); if (pData == IntPtr.Zero) { return; } IntPtr pImageBuffer = Marshal.AllocHGlobal((int)g_nPayloadSize * 3); if (pImageBuffer == IntPtr.Zero) { return; } uint nDataSize = g_nPayloadSize * 3; HObject Hobj = new HObject(); IntPtr RedPtr = IntPtr.Zero; IntPtr GreenPtr = IntPtr.Zero; IntPtr BluePtr = IntPtr.Zero; IntPtr pTemp = IntPtr.Zero; while (m_bGrabbing) { nRet = device.MV_CC_GetOneFrameTimeout_NET(pData, nDataSize, ref pFrameInfo, 1000); if (MyCamera.MV_OK == nRet) { if (IsColorPixelFormat(pFrameInfo.enPixelType)) { if (pFrameInfo.enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed) { pTemp = pData; } else { nRet = ConvertToRGB(obj, pData, pFrameInfo.nHeight, pFrameInfo.nWidth, pFrameInfo.enPixelType, pImageBuffer); if (MyCamera.MV_OK != nRet) { return; } pTemp = pImageBuffer; } unsafe { byte *pBufForSaveImage = (byte *)pTemp; UInt32 nSupWidth = (pFrameInfo.nWidth + (UInt32)3) & 0xfffffffc; for (int nRow = 0; nRow < pFrameInfo.nHeight; nRow++) { for (int col = 0; col < pFrameInfo.nWidth; col++) { m_pDataForRed[nRow * nSupWidth + col] = pBufForSaveImage[nRow * pFrameInfo.nWidth * 3 + (3 * col)]; m_pDataForGreen[nRow * nSupWidth + col] = pBufForSaveImage[nRow * pFrameInfo.nWidth * 3 + (3 * col + 1)]; m_pDataForBlue[nRow * nSupWidth + col] = pBufForSaveImage[nRow * pFrameInfo.nWidth * 3 + (3 * col + 2)]; } } } RedPtr = Marshal.UnsafeAddrOfPinnedArrayElement(m_pDataForRed, 0); GreenPtr = Marshal.UnsafeAddrOfPinnedArrayElement(m_pDataForGreen, 0); BluePtr = Marshal.UnsafeAddrOfPinnedArrayElement(m_pDataForBlue, 0); try { HOperatorSet.GenImage3Extern(out Hobj, (HTuple)"byte", pFrameInfo.nWidth, pFrameInfo.nHeight, (new HTuple(RedPtr)), (new HTuple(GreenPtr)), (new HTuple(BluePtr)), IntPtr.Zero); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } } else if (IsMonoPixelFormat(pFrameInfo.enPixelType)) { if (pFrameInfo.enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8) { pTemp = pData; } else { nRet = ConvertToMono8(device, pData, pImageBuffer, pFrameInfo.nHeight, pFrameInfo.nWidth, pFrameInfo.enPixelType); if (MyCamera.MV_OK != nRet) { return; } pTemp = pImageBuffer; } try { HOperatorSet.GenImage1Extern(out Hobj, "byte", pFrameInfo.nWidth, pFrameInfo.nHeight, pTemp, IntPtr.Zero); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return; } } else { continue; } HalconDisplay(m_Window, Hobj, pFrameInfo.nHeight, pFrameInfo.nWidth); } else { continue; } } if (pData != IntPtr.Zero) { Marshal.FreeHGlobal(pData); } if (pImageBuffer != IntPtr.Zero) { Marshal.FreeHGlobal(pImageBuffer); } return; }
public void Draw(SpriteBatch spriteBatch, GraphicsDevice graphicsDevice) { graphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, MyCamera.GameWorldTransform()); foreach (IScenery scenery in Scenery) { scenery.Draw(spriteBatch); } foreach (Flagpole flagpole in Flagpoles) { flagpole.Draw(spriteBatch); } foreach (Castle castle in Castles) { castle.Draw(spriteBatch); } foreach (IItem item in Items) { item.Draw(spriteBatch); } for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { IBlock block = Blocks[i].OneBlockLevel[j]; if (block != null) { block.Draw(spriteBatch); } } } foreach (EnemySpawner enemySpawner in EnemySpawners) { enemySpawner.Draw(spriteBatch); } foreach (IEnemy enemy in Enemies) { enemy.Draw(spriteBatch); } foreach (Fireball fireball in Fireballs) { fireball.Draw(spriteBatch); } foreach (ScoreObject score in Scores) { score.Draw(spriteBatch); } spriteBatch.End(); }
static void Main(string[] args) { int nRet = MyCamera.MV_OK; MyCamera device = new MyCamera(); do { // ch:枚举设备 | en:Enum device MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST(); nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE, ref stDevList); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Enum device failed:{0:x8}", nRet); break; } Console.WriteLine("Enum device count : " + Convert.ToString(stDevList.nDeviceNum)); if (0 == stDevList.nDeviceNum) { break; } MyCamera.MV_CC_DEVICE_INFO stDevInfo; // 通用设备信息 // ch:打印设备信息 en:Print device info for (Int32 i = 0; i < stDevList.nDeviceNum; i++) { stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO)); if (MyCamera.MV_GIGE_DEVICE == stDevInfo.nTLayerType) { MyCamera.MV_GIGE_DEVICE_INFO stGigEDeviceInfo = (MyCamera.MV_GIGE_DEVICE_INFO)MyCamera.ByteToStruct(stDevInfo.SpecialInfo.stGigEInfo, typeof(MyCamera.MV_GIGE_DEVICE_INFO)); uint nIp1 = ((stGigEDeviceInfo.nCurrentIp & 0xff000000) >> 24); uint nIp2 = ((stGigEDeviceInfo.nCurrentIp & 0x00ff0000) >> 16); uint nIp3 = ((stGigEDeviceInfo.nCurrentIp & 0x0000ff00) >> 8); uint nIp4 = (stGigEDeviceInfo.nCurrentIp & 0x000000ff); Console.WriteLine("\n" + i.ToString() + ": [GigE] User Define Name : " + stGigEDeviceInfo.chUserDefinedName); Console.WriteLine("device IP :" + nIp1 + "." + nIp2 + "." + nIp3 + "." + nIp4); } else { Console.Write("Not Support!\n"); break; } } Int32 nDevIndex = 0; Console.Write("\nPlease input index (0 -- {0:d}) : ", stDevList.nDeviceNum - 1); try { nDevIndex = Convert.ToInt32(Console.ReadLine()); } catch { Console.Write("Invalid Input!\n"); break; } if (nDevIndex > stDevList.nDeviceNum - 1 || nDevIndex < 0) { Console.Write("Input Error!\n"); break; } stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[nDevIndex], typeof(MyCamera.MV_CC_DEVICE_INFO)); // ch:创建设备 | en:Create device nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Create device failed:{0:x8}", nRet); break; } // ch:打开设备 | en:Open device nRet = device.MV_CC_OpenDevice_NET(); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Open device failed:{0:x8}", nRet); break; } // ch:探测网络最佳包大小(只对GigE相机有效) | en:Detection network optimal package size(It only works for the GigE camera) if (stDevInfo.nTLayerType == MyCamera.MV_GIGE_DEVICE) { int nPacketSize = device.MV_CC_GetOptimalPacketSize_NET(); if (nPacketSize > 0) { nRet = device.MV_CC_SetIntValue_NET("GevSCPSPacketSize", (uint)nPacketSize); if (nRet != MyCamera.MV_OK) { Console.WriteLine("Warning: Set Packet Size failed {0:x8}", nRet); } } else { Console.WriteLine("Warning: Get Packet Size failed {0:x8}", nPacketSize); } } // ch:设置触发模式为on | en:Set trigger mode as on nRet = device.MV_CC_SetEnumValue_NET("TriggerMode", 1); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Set Trigger Mode failed! {0:x8}", nRet); break; } // ch:设置触发源为Action1 | en:Set trigger source as Action1 nRet = device.MV_CC_SetEnumValue_NET("TriggerSource", 9); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Set Trigger Source failed! {0:x8}", nRet); break; } // ch:设置Action Device Key | en:Set Action Device Key nRet = device.MV_CC_SetIntValue_NET("ActionDeviceKey", g_DeviceKey); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Set Action Device Key failed! {0:x8}", nRet); break; } // ch:设置Action Group Key | en:Set Action Group Key nRet = device.MV_CC_SetIntValue_NET("ActionGroupKey", g_GroupKey); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Set Action Group Key failed! {0:x8}", nRet); break; } // ch:设置Action Group Mask | en:Set Action Group Mask nRet = device.MV_CC_SetIntValue_NET("ActionGroupMask", g_GroupMask); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Set Action Group Mask fail! {0:x8}", nRet); break; } // ch:获取包大小 || en: Get Payload Size MyCamera.MVCC_INTVALUE stParam = new MyCamera.MVCC_INTVALUE(); nRet = device.MV_CC_GetIntValue_NET("PayloadSize", ref stParam); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Get PayloadSize failed:{0:x8}", nRet); break; } g_nPayloadSize = stParam.nCurValue; // ch:开启抓图 | en:start grab nRet = device.MV_CC_StartGrabbing_NET(); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Start grabbing failed:{0:x8}", nRet); break; } Thread hActionCommandThreadHandle = new Thread(ActionCommandWorkThread); hActionCommandThreadHandle.Start(device); Thread hReceiveImageThreadHandle = new Thread(ReceiveImageWorkThread); hReceiveImageThreadHandle.Start(device); Console.WriteLine("Press enter to exit"); Console.ReadKey(); g_bExit = true; Thread.Sleep(1000); // ch:停止抓图 | en:Stop grab image nRet = device.MV_CC_StopGrabbing_NET(); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Stop grabbing failed{0:x8}", nRet); break; } // ch:关闭设备 | en:Close device nRet = device.MV_CC_CloseDevice_NET(); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Close device failed{0:x8}", nRet); break; } // ch:销毁设备 | en:Destroy device nRet = device.MV_CC_DestroyDevice_NET(); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Destroy device failed:{0:x8}", nRet); break; } } while (false); if (MyCamera.MV_OK != nRet) { // ch:销毁设备 | en:Destroy device nRet = device.MV_CC_DestroyDevice_NET(); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Destroy device failed:{0:x8}", nRet); } } Console.WriteLine("Press enter to exit"); Console.ReadKey(); }
private void button3_Click(object sender, EventArgs e) { // ch:IP转换 | en:IP conversion IPAddress clsIpAddr; if (false == IPAddress.TryParse(textBox1.Text, out clsIpAddr)) { MessageBox.Show("IP地址格式不合法"); return; } long nIp = IPAddress.NetworkToHostOrder(clsIpAddr.Address); // ch:掩码转换 | en:Mask conversion IPAddress clsSubMask; if (false == IPAddress.TryParse(textBox2.Text, out clsSubMask)) { MessageBox.Show("子网掩码格式不合法"); return; } long nSubMask = IPAddress.NetworkToHostOrder(clsSubMask.Address); // ch:网关转换 | en:Gateway conversion IPAddress clsDefaultWay; if (false == IPAddress.TryParse(textBox3.Text, out clsDefaultWay)) { MessageBox.Show("网关格式不合法"); return; } long nDefaultWay = IPAddress.NetworkToHostOrder(clsDefaultWay.Address); IntPtr ptr = CameraDevice.GetIntPtrForSerialNumber(((CameraInfo)comboBox1.SelectedItem).SeriaNumber); if (ptr == IntPtr.Zero) { return; } MyCamera.MV_CC_DEVICE_INFO device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(ptr, typeof(MyCamera.MV_CC_DEVICE_INFO)); // ch:打开设备 | en:Open device if (null == m_pMyCamera) { m_pMyCamera = new MyCamera(); if (null == m_pMyCamera) { return; } } int nRet = m_pMyCamera.MV_CC_CreateDevice_NET(ref device); if (MyCamera.MV_OK != nRet) { return; } nRet = m_pMyCamera.MV_GIGE_ForceIpEx_NET((uint)(nIp >> 32), (uint)(nSubMask >> 32), (uint)(nDefaultWay >> 32)); if (MyCamera.MV_OK != nRet) { return; } m_pMyCamera = null; lc = CameraDevice.DeviceListAcq(); int index = comboBox1.SelectedIndex; comboBox1.DataSource = lc; comboBox1.SelectedIndex = index; comboBox1_SelectedIndexChanged(null, null); GC.Collect(); }
void IMyCameraController.ControlCamera(MyCamera currentCamera) { if (!m_enableFirstPerson) { IsInFirstPersonView = false; } // in case that the cockpit was destroyed but still is for some reason camera controller // (e.g. user was looking through camera block but both camera block and this cockpit were destroyed) if (Closed && MySession.Static.LocalCharacter != null) { MySession.Static.SetCameraController(MyCameraControllerEnum.Entity, MySession.Static.LocalCharacter); } currentCamera.SetViewMatrix(GetViewMatrix()); currentCamera.CameraSpring.Enabled = true; currentCamera.CameraSpring.SetCurrentCameraControllerVelocity(Physics != null ? Physics.LinearVelocity : Vector3.Zero); if (m_currentCameraShakePower > 0) { currentCamera.CameraShake.AddShake(m_currentCameraShakePower); m_currentCameraShakePower = 0; } if (Pilot != null && Pilot.InScene && ControllerInfo.IsLocallyControlled()) Pilot.EnableHead(!IsInFirstPersonView && !ForceFirstPersonCamera); }
public override void renderUpdate(int front, MyCamera camera, ref DrawBuffer draw_buffer) { // lock_target_.renderUpdate(front, camera); }
void Awake() { instance = this; hits = new HashSet<Renderer>(); }
public void ControlCamera(MyCamera currentCamera) { currentCamera.FieldOfViewDegrees = FOV; currentCamera.SetViewMatrix(MatrixD.Invert(WorldMatrix)); }
void Awake() { Camera = UnityEngine.Camera.main.gameObject.GetComponent <MyCamera>(); Camera.SetCharacter(this.transform); }
public override void renderUpdate(int front, MyCamera camera, ref DrawBuffer draw_buffer) { var v = camera.getScreenPoint(ref target_cursor_.transform_.position_); if (v.z > 0) { var rect = new Rect(v.x, v.y, 96f, 96f); MySprite.Instance.put(front, ref rect, MySprite.Kind.Cursor, MySprite.Type.Full); } // trail if (l_trail_ >= 0) { Trail.Instance.renderUpdate(front, l_trail_); } if (r_trail_ >= 0) { Trail.Instance.renderUpdate(front, r_trail_); } draw_buffer.registPlayer(ref rigidbody_.transform_); }
private void bnOpen_Click(object sender, EventArgs e) { if (m_pDeviceList.nDeviceNum == 0 || cbDeviceList.SelectedIndex == -1) { MessageBox.Show("No device,please select"); return; } int nRet = -1; //ch:获取选择的设备信息 | en:Get selected device information MyCamera.MV_CC_DEVICE_INFO device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(m_pDeviceList.pDeviceInfo[cbDeviceList.SelectedIndex], typeof(MyCamera.MV_CC_DEVICE_INFO)); m_pMyCamera = new MyCamera(); nRet = m_pMyCamera.MV_CC_CreateDevice_NET(ref device); if (MyCamera.MV_OK != nRet) { return; } // ch:打开设备 | en:Open device nRet = m_pMyCamera.MV_CC_OpenDevice_NET(); if (MyCamera.MV_OK != nRet) { MessageBox.Show("Open Device Fail"); return; } // ch:获取包大小 || en: Get Payload Size MyCamera.MVCC_INTVALUE stParam = new MyCamera.MVCC_INTVALUE(); nRet = m_pMyCamera.MV_CC_GetIntValue_NET("PayloadSize", ref stParam); if (MyCamera.MV_OK != nRet) { MessageBox.Show("Get PayloadSize Fail"); return; } g_nPayloadSize = stParam.nCurValue; // ch:获取高 || en: Get Height nRet = m_pMyCamera.MV_CC_GetIntValue_NET("Height", ref stParam); if (MyCamera.MV_OK != nRet) { MessageBox.Show("Get Height Fail"); return; } uint nHeight = stParam.nCurValue; // ch:获取宽 || en: Get Width nRet = m_pMyCamera.MV_CC_GetIntValue_NET("Width", ref stParam); if (MyCamera.MV_OK != nRet) { MessageBox.Show("Get Width Fail"); return; } uint nWidth = stParam.nCurValue; // ch:获取步长 || en: Get nRowStep m_nRowStep = nWidth * nHeight; // ch:设置触发模式为off || en:set trigger mode as off m_pMyCamera.MV_CC_SetEnumValue_NET("AcquisitionMode", 2); m_pMyCamera.MV_CC_SetEnumValue_NET("TriggerMode", 0); SetCtrlWhenOpen(); }
void IMyCameraController.ControlCamera(MyCamera currentCamera) { MatrixD viewMatrix = GetViewMatrix(); currentCamera.SetViewMatrix(viewMatrix); currentCamera.CameraSpring.Enabled = !(IsInFirstPersonView || ForceFirstPersonCamera); currentCamera.CameraSpring.SetCurrentCameraControllerVelocity(Physics != null ? Physics.LinearVelocity : Vector3.Zero); currentCamera.CameraShake.AddShake(m_currentCameraShakePower); m_currentCameraShakePower = 0; EnableHead(!ControllerInfo.IsLocallyControlled() || (!IsInFirstPersonView && !ForceFirstPersonCamera)); }
/// <summary> /// 接收图片线程函数 /// </summary> /// <param name="obj"></param> public void ReceiveImageWorkThread(object obj) { int nRet = MyCamera.MV_OK; MyCamera device = obj as MyCamera; MyCamera.MV_FRAME_OUT_INFO_EX pFrameInfo = new MyCamera.MV_FRAME_OUT_INFO_EX(); IntPtr pData = Marshal.AllocHGlobal((int)g_nPayloadSize); if (pData == IntPtr.Zero) { return; } IntPtr pImageBuffer = Marshal.AllocHGlobal((int)m_nRowStep * 3); if (pImageBuffer == IntPtr.Zero) { return; } IntPtr pTemp = IntPtr.Zero; Byte[] byteArrImageData = new Byte[m_nRowStep * 3]; while (m_bGrabbing) { nRet = device.MV_CC_GetOneFrameTimeout_NET(pData, g_nPayloadSize, ref pFrameInfo, 1000); if (MyCamera.MV_OK == nRet) { MyCamera.MvGvspPixelType pixelType = MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed; if (IsColorPixelFormat(pFrameInfo.enPixelType)) // 彩色图像处理 { if (pFrameInfo.enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed) { pTemp = pData; } else { // 其他格式彩色图像转为RGB nRet = ConvertToRGB(obj, pData, pFrameInfo.nHeight, pFrameInfo.nWidth, pFrameInfo.enPixelType, pImageBuffer); if (MyCamera.MV_OK != nRet) { return; } pTemp = pImageBuffer; } // Packed转Plane unsafe { byte *pBufForSaveImage = (byte *)pTemp; UInt32 nSupWidth = (pFrameInfo.nWidth + (UInt32)3) & 0xfffffffc; for (int nRow = 0; nRow < pFrameInfo.nHeight; nRow++) { for (int col = 0; col < pFrameInfo.nWidth; col++) { byteArrImageData[nRow * nSupWidth + col] = pBufForSaveImage[nRow * pFrameInfo.nWidth * 3 + (3 * col)]; byteArrImageData[pFrameInfo.nWidth * pFrameInfo.nHeight + nRow * nSupWidth + col] = pBufForSaveImage[nRow * pFrameInfo.nWidth * 3 + (3 * col + 1)]; byteArrImageData[pFrameInfo.nWidth * pFrameInfo.nHeight * 2 + nRow * nSupWidth + col] = pBufForSaveImage[nRow * pFrameInfo.nWidth * 3 + (3 * col + 2)]; } } pTemp = Marshal.UnsafeAddrOfPinnedArrayElement(byteArrImageData, 0); } } else if (IsMonoPixelFormat(pFrameInfo.enPixelType)) // Mono图像处理 { if (pFrameInfo.enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8) { pTemp = pData; } else { // 其他格式Mono转为Mono8 nRet = ConvertToMono8(device, pData, pImageBuffer, pFrameInfo.nHeight, pFrameInfo.nWidth, pFrameInfo.enPixelType); if (MyCamera.MV_OK != nRet) { return; } pTemp = pImageBuffer; } pixelType = MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8; } else { continue; } VisionProDisplay(pFrameInfo.nHeight, pFrameInfo.nWidth, pTemp, pixelType); } else { continue; } } if (pData != IntPtr.Zero) { Marshal.FreeHGlobal(pData); } if (pImageBuffer != IntPtr.Zero) { Marshal.FreeHGlobal(pImageBuffer); } return; }
void IMyCameraController.ControlCamera(MyCamera currentCamera) { if (!m_enableFirstPerson) { IsInFirstPersonView = false; } currentCamera.SetViewMatrix(GetViewMatrix()); currentCamera.CameraSpring.Enabled = true; currentCamera.CameraSpring.SetCurrentCameraControllerVelocity(Physics != null ? Physics.LinearVelocity : Vector3.Zero); if (m_currentCameraShakePower > 0) { currentCamera.CameraShake.AddShake(m_currentCameraShakePower); m_currentCameraShakePower = 0; } if (Pilot != null && Pilot.InScene && ControllerInfo.IsLocallyControlled()) Pilot.EnableHead(!IsInFirstPersonView && !ForceFirstPersonCamera); }
static void Main(string[] args) { MyCamera device = new MyCamera(); int nRet = MyCamera.MV_OK; do { // ch:枚举设备 | en:Enum deivce MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST(); nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref stDevList); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Enum device failed:{0:x8}", nRet); break; } Console.WriteLine("Enum device count : " + Convert.ToString(stDevList.nDeviceNum)); if (0 == stDevList.nDeviceNum) { break; } MyCamera.MV_CC_DEVICE_INFO stDevInfo; // 通用设备信息 // ch:打印设备信息 en:Print device info for (Int32 i = 0; i < stDevList.nDeviceNum; i++) { stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO)); if (MyCamera.MV_GIGE_DEVICE == stDevInfo.nTLayerType) { MyCamera.MV_GIGE_DEVICE_INFO stGigEDeviceInfo = (MyCamera.MV_GIGE_DEVICE_INFO)MyCamera.ByteToStruct(stDevInfo.SpecialInfo.stGigEInfo, typeof(MyCamera.MV_GIGE_DEVICE_INFO)); uint nIp1 = ((stGigEDeviceInfo.nCurrentIp & 0xff000000) >> 24); uint nIp2 = ((stGigEDeviceInfo.nCurrentIp & 0x00ff0000) >> 16); uint nIp3 = ((stGigEDeviceInfo.nCurrentIp & 0x0000ff00) >> 8); uint nIp4 = (stGigEDeviceInfo.nCurrentIp & 0x000000ff); Console.WriteLine("\n" + i.ToString() + ": [GigE] User Define Name : " + stGigEDeviceInfo.chUserDefinedName); Console.WriteLine("device IP :" + nIp1 + "." + nIp2 + "." + nIp3 + "." + nIp4); } else if (MyCamera.MV_USB_DEVICE == stDevInfo.nTLayerType) { MyCamera.MV_USB3_DEVICE_INFO stUsb3DeviceInfo = (MyCamera.MV_USB3_DEVICE_INFO)MyCamera.ByteToStruct(stDevInfo.SpecialInfo.stUsb3VInfo, typeof(MyCamera.MV_USB3_DEVICE_INFO)); Console.WriteLine("\n" + i.ToString() + ": [U3V] User Define Name : " + stUsb3DeviceInfo.chUserDefinedName); Console.WriteLine("\n Serial Number : " + stUsb3DeviceInfo.chSerialNumber); Console.WriteLine("\n Device Number : " + stUsb3DeviceInfo.nDeviceNumber); } } Int32 nDevIndex = 0; Console.Write("\nPlease input index (0 -- {0:d}) : ", stDevList.nDeviceNum - 1); try { nDevIndex = Convert.ToInt32(Console.ReadLine()); } catch { Console.Write("Invalid Input!\n"); break; } if (nDevIndex > stDevList.nDeviceNum - 1 || nDevIndex < 0) { Console.Write("Input Error!\n"); break; } stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[nDevIndex], typeof(MyCamera.MV_CC_DEVICE_INFO)); // ch:创建设备 | en: Create device nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Create device failed:{0:x8}", nRet); break; } // ch:打开设备 | en:Open device nRet = device.MV_CC_OpenDevice_NET(); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Open device failed:{0:x8}", nRet); break; } Console.WriteLine("Start export the camera properties to the file"); Console.WriteLine("Wait......"); // ch:将相机属性导出到文件中 // en:Export the camera properties to the file nRet = device.MV_CC_FeatureSave_NET("CameraFile"); if (MyCamera.MV_OK != nRet) { Console.WriteLine("FeatureSave failed!"); break; } Console.WriteLine("Finish export the camera properties to the file\n"); Console.WriteLine("Start import the camera properties from the file"); Console.WriteLine("Wait......"); // ch:从文件中导入相机属性 // en:Import the camera properties from the file nRet = device.MV_CC_FeatureLoad_NET("CameraFile"); if (MyCamera.MV_OK != nRet) { Console.WriteLine("FeatureLoad failed!"); break; } Console.WriteLine("Finish import the camera properties from the file"); // ch:关闭设备 | en:Close device nRet = device.MV_CC_CloseDevice_NET(); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Close device failed{0:x8}", nRet); break; } // ch:销毁设备 | en:Destroy device nRet = device.MV_CC_DestroyDevice_NET(); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Destroy device failed:{0:x8}", nRet); break; } } while (false); if (MyCamera.MV_OK != nRet) { // ch:销毁设备 | en:Destroy device nRet = device.MV_CC_DestroyDevice_NET(); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Destroy device failed:{0:x8}", nRet); } } Console.WriteLine("Press enter to exit"); Console.ReadKey(); }
void VRage.Game.ModAPI.Interfaces.IMyCameraController.ControlCamera(MyCamera currentCamera) { currentCamera.SetViewMatrix(GetViewMatrix()); }
public void DebugDraw() { return; MyStateObjects.WireframeRasterizerState.Apply(); for (int i = 0; i < NumSplits; i++) { cameraFrustum.Matrix = m_lightCameras[i].CameraSubfrustum; cameraFrustum.GetCorners(frustum); var tmp = frustum[3]; frustum[3] = frustum[2]; frustum[2] = tmp; //MyDebugDraw.DrawBoundingFrustum(cameraFrustum, frustumColors[i]); MySimpleObjectDraw.OcclusionPlaneDraw(frustum); //MyDebugDraw.DrawTriangle(frustum[0], frustum[1], frustum[2], frustumColors[i], frustumColors[i], frustumColors[i]); //MyDebugDraw.DrawTriangle(frustum[1], frustum[2], frustum[3], frustumColors[i], frustumColors[i], frustumColors[i]); } return; bool update = false; if (MyRender.CurrentRenderSetup.CallerID.Value == MyRenderCallerEnum.Main) { if (update) { mainCamera = MyCamera.GetBoundingFrustum().Matrix; } for (int i = 0; i < NumSplits; i++) { if (update) { Vector4 c = frustumColors[i].ToVector4(); //MyDebugDraw.DrawAABBLowRes(ref box, ref c, 1); //BoundingFrustum bf = new BoundingFrustum(); //frustumMatrices[i] = m_lightCameras[i].CameraSubfrustum; frustumMatrices[i] = m_lightCameras[i].BoundingFrustum.Matrix; } DebugDrawFrustum(frustumMatrices[i], frustumColors[i]); Vector4 cc = frustumColors[i].ToVector4(); BoundingFrustum frma = new BoundingFrustum(frustumMatrices[i]); MyRender.PrepareEntitiesForDraw(ref frma, Vector3.Zero, 0, (MyOcclusionQueryID)(i + 1), m_castingRenderObjects, m_castingCullObjects, m_occlusionQueriesLists[i], ref MyPerformanceCounter.PerCameraDraw.ShadowEntitiesOccluded[i]); BoundingBox aabbFr = new BoundingBox(); aabbFr = aabbFr.CreateInvalid(); foreach (MyRenderObject ro in m_castingRenderObjects) { BoundingBox vv = ro.GetWorldSpaceAABB(); //MyDebugDraw.DrawAABBLowRes(ref vv, ref cc, 1); aabbFr = aabbFr.Include(ref vv); } //MyDebugDraw.DrawAABBLowRes(ref aabbFr, ref cc, 1); } // DebugDrawFrustum(mainCamera, new Color(1.0f, 1.0f, 1.0f)); } }
/// <summary> /// /// </summary> /// <param name="dataPtr">指向图像数据</param> /// <param name="frameInfo"></param> internal JFImage_Hik(byte[] dataBytes, MyCamera.MV_FRAME_OUT_INFO_EX frameInfo, MyCamera cmr) { _dataBytes = dataBytes; _frameInfo = frameInfo; _cmr = cmr; }
private void Awake() { Instance = this; m_IsUpdatingPosition = false; }
void IMyCameraController.ControlCamera(MyCamera currentCamera) { currentCamera.SetViewMatrix(GetViewMatrix()); }
protected virtual void SetupViewport() { GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); if (!Observer.Active) { GL.Ortho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); } else { double windowRatio = (double)glControl.Width / glControl.Height; double texRatio = (double)Observer.TextureWidth / Observer.TextureHeight; switch (Observer.ViewMode) { case MyAbstractObserver.ViewMethod.Fit_2D: { double halfWidth = Observer.TextureWidth * MyDefaultShape.SCALE * 0.5; double halfHeight = Observer.TextureHeight * MyDefaultShape.SCALE * 0.5; if (Observer.KeepRatio) { if (windowRatio > texRatio) { halfWidth = halfHeight * windowRatio; } else { halfHeight = halfWidth / windowRatio; } } GL.Ortho(-halfWidth, halfWidth, -halfHeight, halfHeight, -1.0, 1.0); m_camera = null; } break; case MyAbstractObserver.ViewMethod.Free_2D: { Matrix4 m_prespective = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI * 0.25f, (float)windowRatio, 0.1f, 400.0f); GL.LoadMatrix(ref m_prespective); if (!(m_camera is MyZoomAndPanCamera)) { m_camera = new MyZoomAndPanCamera(glControl); } } break; case MyAbstractObserver.ViewMethod.Orbit_3D: { Matrix4 m_prespective = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI * 0.25f, (float)windowRatio, 0.1f, 400.0f); GL.LoadMatrix(ref m_prespective); if (!(m_camera is MyOrbitCamera)) { m_camera = new MyOrbitCamera(glControl); } } break; } if (m_camera != null && Observer.CameraData != null && Observer.CameraData.CameraType == Observer.ViewMode) { m_camera.CameraSetup = Observer.CameraData; Observer.CameraData = null; } } GL.Viewport(0, 0, glControl.Width, glControl.Height); }
public bool IsPointLightInFrustum() { return(MyCamera.IsInFrustum(ref m_pointBoundingSphere)); }
public int Capture(out HObject Himage) { HOperatorSet.GenEmptyObj(out Himage); Himage.Dispose(); int nRet = MyCamera.MV_OK; MyCamera device = m_pMyCamera as MyCamera; MyCamera.MV_FRAME_OUT_INFO_EX pFrameInfo = new MyCamera.MV_FRAME_OUT_INFO_EX(); IntPtr pData = Marshal.AllocHGlobal((int)g_nPayloadSize * 3); if (pData == IntPtr.Zero) { return(1); } IntPtr pImageBuffer = Marshal.AllocHGlobal((int)g_nPayloadSize * 3); if (pImageBuffer == IntPtr.Zero) { return(2); } uint nDataSize = g_nPayloadSize * 3; HObject Hobj = new HObject(); IntPtr RedPtr = IntPtr.Zero; IntPtr GreenPtr = IntPtr.Zero; IntPtr BluePtr = IntPtr.Zero; IntPtr pTemp = IntPtr.Zero; nRet = device.MV_CC_GetOneFrameTimeout_NET(pData, nDataSize, ref pFrameInfo, 1000); if (MyCamera.MV_OK == nRet) { if (IsColorPixelFormat(pFrameInfo.enPixelType)) { if (pFrameInfo.enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed) { pTemp = pData; } else { nRet = ConvertToRGB(m_pMyCamera, pData, pFrameInfo.nHeight, pFrameInfo.nWidth, pFrameInfo.enPixelType, pImageBuffer); if (MyCamera.MV_OK != nRet) { Marshal.FreeHGlobal(pImageBuffer); Marshal.FreeHGlobal(pData); return(3); } pTemp = pImageBuffer; } unsafe { byte *pBufForSaveImage = (byte *)pTemp; UInt32 nSupWidth = (pFrameInfo.nWidth + (UInt32)3) & 0xfffffffc; for (int nRow = 0; nRow < pFrameInfo.nHeight; nRow++) { for (int col = 0; col < pFrameInfo.nWidth; col++) { m_pDataForRed[nRow * nSupWidth + col] = pBufForSaveImage[nRow * pFrameInfo.nWidth * 3 + (3 * col)]; m_pDataForGreen[nRow * nSupWidth + col] = pBufForSaveImage[nRow * pFrameInfo.nWidth * 3 + (3 * col + 1)]; m_pDataForBlue[nRow * nSupWidth + col] = pBufForSaveImage[nRow * pFrameInfo.nWidth * 3 + (3 * col + 2)]; } } } RedPtr = Marshal.UnsafeAddrOfPinnedArrayElement(m_pDataForRed, 0); GreenPtr = Marshal.UnsafeAddrOfPinnedArrayElement(m_pDataForGreen, 0); BluePtr = Marshal.UnsafeAddrOfPinnedArrayElement(m_pDataForBlue, 0); try { HOperatorSet.GenImage3Extern(out Hobj, (HTuple)"byte", pFrameInfo.nWidth, pFrameInfo.nHeight, (new HTuple(RedPtr)), (new HTuple(GreenPtr)), (new HTuple(BluePtr)), IntPtr.Zero); } catch (HalconException ex) { Marshal.FreeHGlobal(pImageBuffer); Marshal.FreeHGlobal(pData); return(4); } } else if (IsMonoPixelFormat(pFrameInfo.enPixelType)) { if (pFrameInfo.enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8) { pTemp = pData; } else { nRet = ConvertToMono8(device, pData, pImageBuffer, pFrameInfo.nHeight, pFrameInfo.nWidth, pFrameInfo.enPixelType); if (MyCamera.MV_OK != nRet) { Marshal.FreeHGlobal(pImageBuffer); Marshal.FreeHGlobal(pData); return(5); } pTemp = pImageBuffer; } try { HOperatorSet.GenImage1Extern(out Hobj, "byte", pFrameInfo.nWidth, pFrameInfo.nHeight, pTemp, IntPtr.Zero); } catch (HalconException ex) { Marshal.FreeHGlobal(pImageBuffer); Marshal.FreeHGlobal(pData); return(6); } } Himage = Hobj.Clone(); Hobj.Dispose(); } Marshal.FreeHGlobal(pImageBuffer); Marshal.FreeHGlobal(pData); return(0); }
public override void UpdateAfterSimulation() { base.UpdateAfterSimulation(); // Cannon is rotating while shoting. After that, it will slow-down. float normalizedRotationSpeed = 1.0f - MathHelper.Clamp((float)(MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) / m_rotationTimeout, 0, 1); normalizedRotationSpeed = MathHelper.SmoothStep(0, 1, normalizedRotationSpeed); m_rotationAngle -= normalizedRotationSpeed * MyAutocanonConstants.ROTATION_SPEED_PER_SECOND * MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS; Matrix worldMatrix = this.WorldMatrix; m_positionMuzzleInWorldSpace = GetMuzzlePosition(m_barrel.GetMuzzlePosition()); m_barrel.SetData(ref m_worldMatrixForRenderingFromCockpitView, m_rotationAngle); // Handle 'motor loop and motor end' cues if ((m_cannonMotorEndPlayed == false) && ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) > MyAutocanonConstants.SHOT_INTERVAL_IN_MILISECONDS)) { // Stop 'shooting loop' cue if (MyMinerGame.TotalGamePlayTimeInMilliseconds > m_lastTimeShoot + MyAutocanonConstants.MIN_TIME_RELEASE_INTERVAL_IN_MILISECONDS) { MySoundCue?autocanonAttackLoopCue = GetParentMinerShip().UnifiedWeaponCueGet(AUTOCANON_ATTACK_LOOP); if ((autocanonAttackLoopCue != null) && (autocanonAttackLoopCue.Value.IsPlaying == true)) { autocanonAttackLoopCue.Value.Stop(SharpDX.XACT3.StopFlags.Immediate); } autocanonAttackLoopCue = GetParentMinerShip().UnifiedWeaponCueGet(AUTOCANON_ATTACK); if ((autocanonAttackLoopCue != null) && (autocanonAttackLoopCue.Value.IsPlaying == true)) { autocanonAttackLoopCue.Value.Stop(SharpDX.XACT3.StopFlags.Immediate); } // Start 'release' cue MySoundCue?autocanonReleaseCue = GetParentMinerShip().UnifiedWeaponCueGet(AUTOCANON_RELEASE); if ((autocanonReleaseCue == null) || (autocanonReleaseCue.Value.IsPlaying == false)) { GetParentMinerShip().UnifiedWeaponCueSet( AUTOCANON_RELEASE, MyAudio.AddCue2dOr3d(GetParentMinerShip(), AUTOCANON_RELEASE, Parent.GetPosition(), Parent.WorldMatrix.Forward, Parent.WorldMatrix.Up, Parent.Physics.LinearVelocity)); } m_cannonMotorEndPlayed = true; } } // Update sound position MySoundCue?updateAutocanonAttackLoopCue = GetParentMinerShip().UnifiedWeaponCueGet(AUTOCANON_ATTACK_LOOP); if ((updateAutocanonAttackLoopCue != null) && (updateAutocanonAttackLoopCue.Value.IsPlaying == true)) { MyAudio.UpdateCuePosition(updateAutocanonAttackLoopCue, m_positionMuzzleInWorldSpace, WorldMatrix.Forward, WorldMatrix.Up, Parent.Physics.LinearVelocity); } updateAutocanonAttackLoopCue = GetParentMinerShip().UnifiedWeaponCueGet(AUTOCANON_ATTACK); if ((updateAutocanonAttackLoopCue != null) && (updateAutocanonAttackLoopCue.Value.IsPlaying == true)) { MyAudio.UpdateCuePosition(updateAutocanonAttackLoopCue, m_positionMuzzleInWorldSpace, WorldMatrix.Forward, WorldMatrix.Up, Parent.Physics.LinearVelocity); } // Update sound position MySoundCue?updateAutocanonReleaseCue = GetParentMinerShip().UnifiedWeaponCueGet(AUTOCANON_RELEASE); if ((updateAutocanonReleaseCue != null) && (updateAutocanonReleaseCue.Value.IsPlaying == true)) { MyAudio.UpdateCuePosition(updateAutocanonReleaseCue, m_positionMuzzleInWorldSpace, WorldMatrix.Forward, WorldMatrix.Up, Parent.Physics.LinearVelocity); } // If gun fires too much, we start generating smokes at the muzzle if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_smokeLastTime) >= (MyAutocanonConstants.SMOKES_INTERVAL_IN_MILISECONDS)) { m_smokeLastTime = MyMinerGame.TotalGamePlayTimeInMilliseconds; SmokesToGenerateDecrease(); if (m_smokesToGenerate > 0 && m_smokeEffect == null) { if (MyCamera.GetDistanceWithFOV(GetPosition()) < 150) { m_smokeEffect = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_Autocannon); m_smokeEffect.WorldMatrix = WorldMatrix; m_smokeEffect.OnDelete += new EventHandler(m_smokeEffect_OnDelete); } } } if (m_smokeEffect != null) { float smokeOffset = 0.2f; if ((MinerWars.AppCode.Game.GUI.MyGuiScreenGamePlay.Static.CameraAttachedTo == MinerWars.AppCode.Game.GUI.MyCameraAttachedToEnum.PlayerMinerShip) && (Parent == MySession.PlayerShip)) { smokeOffset = 0.0f; } m_smokeEffect.WorldMatrix = Matrix.CreateTranslation(m_positionMuzzleInWorldSpace + worldMatrix.Forward * smokeOffset); m_smokeEffect.UserBirthMultiplier = m_smokesToGenerate; } }
public int OpenDevices(string CamName) { if (IsOpen == true) { return(0); } foreach (var temp in CameraInfo) { IntPtr buffer = Marshal.UnsafeAddrOfPinnedArrayElement(temp.SpecialInfo.stGigEInfo, 0); MyCamera.MV_GIGE_DEVICE_INFO gigeInfo1 = (MyCamera.MV_GIGE_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MyCamera.MV_GIGE_DEVICE_INFO)); if (gigeInfo1.chUserDefinedName == CamName || gigeInfo1.chSerialNumber == CamName) { int nRet = -1; MyCamera.MV_CC_DEVICE_INFO device = temp; bool bRes = MyCamera.MV_CC_IsDeviceAccessible_NET(ref device, 1); if (bRes == false) { return(1); } nRet = m_pMyCamera.MV_CC_CreateDevice_NET(ref device); if (MyCamera.MV_OK != nRet) { return(2); } nRet = m_pMyCamera.MV_CC_OpenDevice_NET(); if (MyCamera.MV_OK != nRet) { //MessageBox.Show("Open Device Fail"); return(3); } MyCamera.MVCC_INTVALUE stParam = new MyCamera.MVCC_INTVALUE(); // ch:获取包大小 || en: Get Payload Size nRet = m_pMyCamera.MV_CC_GetIntValue_NET("PayloadSize", ref stParam); if (MyCamera.MV_OK != nRet) { MessageBox.Show("Get PayloadSize Fail"); return(4); } g_nPayloadSize = stParam.nCurValue; // ch:获取高 || en: Get Height nRet = m_pMyCamera.MV_CC_GetIntValue_NET("Height", ref stParam); if (MyCamera.MV_OK != nRet) { return(5); } uint nHeight = stParam.nCurValue; // ch:获取宽 || en: Get Width nRet = m_pMyCamera.MV_CC_GetIntValue_NET("Width", ref stParam); if (MyCamera.MV_OK != nRet) { return(6); } uint nWidth = stParam.nCurValue; m_pDataForRed = new byte[nWidth * nHeight]; m_pDataForGreen = new byte[nWidth * nHeight]; m_pDataForBlue = new byte[nWidth * nHeight]; nRet = m_pMyCamera.MV_CC_StartGrabbing_NET(); if (MyCamera.MV_OK != nRet) { return(7); } IsOpen = true; return(0); } } return(-1); }
private void DeviceListAcq() { // ch:创建设备列表 | en:Create Device List System.GC.Collect(); cbDeviceList.Items.Clear(); m_stDeviceList.nDeviceNum = 0; int nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref m_stDeviceList); if (0 != nRet) { ShowErrorMsg("Enumerate devices fail!", 0); return; } // ch:在窗体列表中显示设备名 | en:Display device name in the form list for (int i = 0; i < m_stDeviceList.nDeviceNum; i++) { MyCamera.MV_CC_DEVICE_INFO device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(m_stDeviceList.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO)); if (device.nTLayerType == MyCamera.MV_GIGE_DEVICE) { MyCamera.MV_GIGE_DEVICE_INFO gigeInfo = (MyCamera.MV_GIGE_DEVICE_INFO)MyCamera.ByteToStruct(device.SpecialInfo.stGigEInfo, typeof(MyCamera.MV_GIGE_DEVICE_INFO)); if (gigeInfo.chUserDefinedName != "") { cbDeviceList.Items.Add("GEV: " + gigeInfo.chUserDefinedName + " (" + gigeInfo.chSerialNumber + ")"); } else { cbDeviceList.Items.Add("GEV: " + gigeInfo.chManufacturerName + " " + gigeInfo.chModelName + " (" + gigeInfo.chSerialNumber + ")"); } } else if (device.nTLayerType == MyCamera.MV_USB_DEVICE) { MyCamera.MV_USB3_DEVICE_INFO usbInfo = (MyCamera.MV_USB3_DEVICE_INFO)MyCamera.ByteToStruct(device.SpecialInfo.stUsb3VInfo, typeof(MyCamera.MV_USB3_DEVICE_INFO)); if (usbInfo.chUserDefinedName != "") { cbDeviceList.Items.Add("U3V: " + usbInfo.chUserDefinedName + " (" + usbInfo.chSerialNumber + ")"); } else { cbDeviceList.Items.Add("U3V: " + usbInfo.chManufacturerName + " " + usbInfo.chModelName + " (" + usbInfo.chSerialNumber + ")"); } } } // ch:选择第一项 | en:Select the first item if (m_stDeviceList.nDeviceNum != 0) { cbDeviceList.SelectedIndex = 0; } }
public bool Init() { cameras.Clear(); int nRet = MyCamera.MV_OK; MyCamera device = new MyCamera(); MyCamera.MV_CC_DEVICE_INFO_LIST stDevList = new MyCamera.MV_CC_DEVICE_INFO_LIST(); nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE, ref stDevList); if (MyCamera.MV_OK != nRet) { Console.WriteLine("Can not find device", nRet); return(false); } Console.WriteLine("Enum device count : " + Convert.ToString(stDevList.nDeviceNum)); if (0 == stDevList.nDeviceNum) { return(false); } MyCamera.MV_CC_DEVICE_INFO stDevInfo; // 通用设备信息 // ch:打印设备信息 en:Print device info for (Int32 i = 0; i < stDevList.nDeviceNum; i++) { AqHikVisionCamera camera = new AqHikVisionCamera(); stDevInfo = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO)); if (MyCamera.MV_GIGE_DEVICE == stDevInfo.nTLayerType) { MyCamera.MV_GIGE_DEVICE_INFO stGigEDeviceInfo = (MyCamera.MV_GIGE_DEVICE_INFO)MyCamera.ByteToStruct(stDevInfo.SpecialInfo.stGigEInfo, typeof(MyCamera.MV_GIGE_DEVICE_INFO)); uint nIp1 = ((stGigEDeviceInfo.nCurrentIp & 0xff000000) >> 24); uint nIp2 = ((stGigEDeviceInfo.nCurrentIp & 0x00ff0000) >> 16); uint nIp3 = ((stGigEDeviceInfo.nCurrentIp & 0x0000ff00) >> 8); uint nIp4 = (stGigEDeviceInfo.nCurrentIp & 0x000000ff); string ip = nIp1 + "." + nIp2 + "." + nIp3 + "." + nIp4; camera.Name = stGigEDeviceInfo.chUserDefinedName; camera.Ip = ip; camera.Id = stGigEDeviceInfo.chSerialNumber; cameras.Add(camera); } } if (cameras.Count == 0) { return(false); } return(true); } //end function
// ------------------------------------------------------------------------------------------------ void IMyCameraController.ControlCamera(MyCamera currentCamera) { currentCamera.SetViewMatrix(GetViewMatrix()); }
private static GrabInfo ConvertImage(MyCamera.MV_FRAME_OUT_INFO_EX frameInfo, IntPtr pData, MyCamera device) { uint channel = frameInfo.nFrameLen / frameInfo.nWidth / frameInfo.nHeight; if (channel == 1) { var data = new byte[frameInfo.nFrameLen]; Marshal.Copy(pData, data, 0, (int)frameInfo.nFrameLen); return(new GrabInfo(EGrabResult.Success, frameInfo.nWidth, frameInfo.nHeight, 1, data)); } else { var data = new byte[frameInfo.nWidth * frameInfo.nHeight * 3]; var handle = GCHandle.Alloc(data, GCHandleType.Pinned); var stConverPixelParam = new MyCamera.MV_PIXEL_CONVERT_PARAM(); stConverPixelParam.nWidth = frameInfo.nWidth; stConverPixelParam.nHeight = frameInfo.nHeight; stConverPixelParam.pSrcData = pData; stConverPixelParam.nSrcDataLen = frameInfo.nFrameLen; stConverPixelParam.enSrcPixelType = frameInfo.enPixelType; stConverPixelParam.enDstPixelType = MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed; stConverPixelParam.pDstBuffer = handle.AddrOfPinnedObject(); stConverPixelParam.nDstBufferSize = (uint)(frameInfo.nWidth * frameInfo.nHeight * 3); if (MyCamera.MV_OK != device.MV_CC_ConvertPixelType_NET(ref stConverPixelParam)) { handle.Free(); return(new GrabInfo(EGrabResult.Error)); } handle.Free(); return(new GrabInfo(EGrabResult.Success, frameInfo.nWidth, frameInfo.nHeight, 3, data)); } }
public override void LoadData() { MainCamera = new MyCamera(); MainCamera.FarPlaneDistance = MySession.Static.Settings.ViewDistance; MyEntities.LoadData(); }
protected override void UnloadData() { MyEntities.UnloadData(); MainCamera = null; base.UnloadData(); }
public RotateToPersonState(Transform camera, Vector3 target) : base(camera, target) { MyCamera = camera.GetComponent <MyCamera>(); StartPos = MyCamera.StartPos; }
public void setCamera(MyCamera camera) { camera_ = camera; }
private bool DeviceListAcq() { System.GC.Collect(); m_stDeviceList.nDeviceNum = 0; int nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE, ref m_stDeviceList); if (0 != nRet) { StrErrorMsg = "枚举设备失败!"; return(false); } for (int i = 0; i < m_stDeviceList.nDeviceNum; i++) { MyCamera.MV_CC_DEVICE_INFO device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(m_stDeviceList.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO)); if (device.nTLayerType == MyCamera.MV_GIGE_DEVICE) { MyCamera.MV_GIGE_DEVICE_INFO gigeInfo = (MyCamera.MV_GIGE_DEVICE_INFO)MyCamera.ByteToStruct(device.SpecialInfo.stGigEInfo, typeof(MyCamera.MV_GIGE_DEVICE_INFO)); if (gigeInfo.chUserDefinedName != "") { m_listUserDefinedName.Add(i, gigeInfo.chUserDefinedName); } else { StrErrorMsg = "没有给相机命名!" + "GigE: " + gigeInfo.chManufacturerName + " " + gigeInfo.chModelName + " (" + gigeInfo.chSerialNumber + ")"; return(false); } } } return(true); }
private bool DeviceOpenAll() { if (m_stDeviceList.nDeviceNum == 0) { StrErrorMsg = "无相机设备"; return(false); } cbImage = new MyCamera.cbOutputExdelegate(ImageCallBack); int nIndex; string UserDefinedName; foreach (var item in m_listUserDefinedName) { nIndex = item.Key; UserDefinedName = item.Value; //获取选择的设备信息 MyCamera.MV_CC_DEVICE_INFO device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(m_stDeviceList.pDeviceInfo[nIndex], typeof(MyCamera.MV_CC_DEVICE_INFO)); m_dicMyCamera[nIndex] = new MyCamera(); if (m_dicMyCamera[nIndex] == null) { StrErrorMsg = "相机" + UserDefinedName + "对象创建失败"; m_dicMyCamera.Remove(nIndex); return(false); } int nRet = m_dicMyCamera[nIndex].MV_CC_CreateDevice_NET(ref device); if (MyCamera.MV_OK != nRet) { StrErrorMsg = "相机" + UserDefinedName + "创建设备失败"; m_dicMyCamera.Remove(nIndex); return(false); } for (int i = 0; i < 2; i++) { nRet = m_dicMyCamera[nIndex].MV_CC_OpenDevice_NET(); if (MyCamera.MV_OK != nRet) { StrErrorMsg = "相机" + UserDefinedName + "打开设备失败,正在尝试重连"; Thread.Sleep(1000); } else { break; } } if (MyCamera.MV_OK != nRet) { StrErrorMsg = "相机" + UserDefinedName + "打开设备失败(" + nRet.ToString("X") + ")"; m_dicMyCamera.Remove(nIndex); return(false); } else { m_pDeviceInfo[nIndex] = device; //探测网络最佳包大小 int nPacketSize = m_dicMyCamera[nIndex].MV_CC_GetOptimalPacketSize_NET(); if (nPacketSize > 0) { nRet = m_dicMyCamera[nIndex].MV_CC_SetIntValue_NET("GevSCPSPacketSize", (uint)nPacketSize); if (nRet != MyCamera.MV_OK) { StrErrorMsg = "相机" + UserDefinedName + "设置数据包大小失败(" + nRet.ToString("X") + ")"; } } else { StrErrorMsg = "相机" + UserDefinedName + "设置数据包大小失败(" + nRet.ToString("X") + ")"; } //打开软触发模式 m_dicMyCamera[nIndex].MV_CC_SetEnumValue_NET("TriggerMode", (uint)MyCamera.MV_CAM_TRIGGER_MODE.MV_TRIGGER_MODE_ON); m_dicMyCamera[nIndex].MV_CC_SetEnumValue_NET("TriggerSource", (uint)MyCamera.MV_CAM_TRIGGER_SOURCE.MV_TRIGGER_SOURCE_SOFTWARE); ////打开实时模式 //m_dicMyCamera[nIndex].MV_CC_SetEnumValue_NET("TriggerMode", (uint)MyCamera.MV_CAM_TRIGGER_MODE.MV_TRIGGER_MODE_OFF); m_stFrameInfo[nIndex] = new MyCamera.MV_FRAME_OUT_INFO_EX(); m_dicSaveImge[nIndex] = new SaveImage(); m_dicImageCallBackSignal[nIndex] = new EventWaitHandle(false, EventResetMode.AutoReset); m_dicMyCamera[nIndex].MV_CC_RegisterImageCallBackEx_NET(cbImage, (IntPtr)nIndex); } } return(true); }
public override void renderUpdate(int front, MyCamera camera, ref DrawBuffer draw_buffer) { lock_target_.renderUpdate(front, camera); draw_buffer.regist(ref rigidbody_.transform_, DrawBuffer.Type.Zako); }
public override void renderUpdate(int front, MyCamera camera, ref DrawBuffer draw_buffer) { if (trail_id_ >= 0) { Trail.Instance.renderUpdate(front, trail_id_); } }