차이
문서의 선택한 두 판 사이의 차이를 보여줍니다.
tech:picking [2011/07/13 19:50] – 새로 만듦 vaslor | tech:picking [2016/07/12 09:26] (현재) – 바깥 편집 127.0.0.1 | ||
---|---|---|---|
줄 1: | 줄 1: | ||
+ | {{tag> | ||
+ | ======Mouse Picking====== | ||
+ | |||
+ | 그냥 [[xna]] 예제를 보고 따라면 된다. 그리고 Ray의 시작점에서 거리 만큼 가면 만나는 지점임...이 것을 계산하면 된다. | ||
+ | |||
+ | <code csharp> | ||
+ | private void ProcessMouse(GameTime gameTime) | ||
+ | { | ||
+ | MouseState ms = Mouse.GetState(); | ||
+ | |||
+ | curMousePos.X = ms.X; | ||
+ | curMousePos.Y = ms.Y; | ||
+ | |||
+ | Vector3 nearsource = new Vector3((float)curMousePos.X, | ||
+ | Vector3 farsource = new Vector3((float)curMousePos.X, | ||
+ | |||
+ | Matrix world = Matrix.CreateTranslation(0, | ||
+ | |||
+ | Vector3 nearPoint = GraphicsDevice.Viewport.Unproject(nearsource, | ||
+ | projectionMatrix, | ||
+ | |||
+ | Vector3 farPoint = GraphicsDevice.Viewport.Unproject(farsource, | ||
+ | projectionMatrix, | ||
+ | |||
+ | Vector3 direction = farPoint - nearPoint; | ||
+ | direction.Normalize(); | ||
+ | Ray pickRay = new Ray(nearPoint, | ||
+ | |||
+ | Nullable< | ||
+ | |||
+ | if (dis != null) cursorPos = pickRay.Direction * (float)dis + pickRay.Position; | ||
+ | // Ray의 시작점에서 거리 만큼 가면 만나는 지점임...이 것을 계산.. | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | * 출처: [[|]] | ||
+ | |||
+ | ^ 누구나 수정하실 수 있습니다. | ||
+ | |||
+ | |||