123 unsigned int pixelsX = mRenderSize / 2;
124 unsigned int pixelsY = mRenderSize / 2;
130 Ogre::SubEntity* subEntity = 0;
131 Ogre::Vector3 pos(0.0f, 0.0f, 0.0f);
132 float rayLenght = 0.0f;
143 Ogre::Real nx = (2.0f * xR) - 1.0f;
144 Ogre::Real ny = 1.0f - (2.0f * yR);
145 Ogre::Vector3 nearPoint(nx, ny, -1.0f);
146 Ogre::Vector3 midPoint(nx, ny, 0.0f);
149 Ogre::Matrix4 invViewMat = (mRayCam->getProjectionMatrix() * mRayCam->getViewMatrix(
true)).inverse();
150 Ogre::Vector3 rayOrigin = invViewMat * nearPoint;
151 Ogre::Vector3 rayDest = invViewMat * midPoint;
152 Ogre::Vector3 rayDirection = rayDest - rayOrigin;
153 rayDirection.normalise();
155 float farclip = mRayCam->getFarClipDistance();
156 float nearclip = mRayCam->getNearClipDistance();
159 if (mRayCam->getProjectionType() == Ogre::PT_PERSPECTIVE)
162 Ogre::Vector4 viewpos = mRayCam->getProjectionMatrixWithRSDepth().inverse() * Ogre::Vector4(nx, ny, zdepth, 1.0f);
163 zdepth = viewpos.z / viewpos.w;
178 double ylenght = Ogre::Math::Tan(mRayCam->getFOVy().valueRadians() * 0.5f);
179 double xlenght = ylenght * mRayCam->getAspectRatio();
180 double opx = zdepth * abs(xlenght * nx);
181 double opy = zdepth * abs(ylenght * ny);
182 rayLenght = Ogre::Math::Sqrt((zdepth * zdepth) + (opx * opx) + (opy * opy));
186 zdepth *= (farclip - nearclip);
197 pos = rayOrigin + (rayDirection * rayLenght);
207 for (
unsigned int i = 0; i < subEntity->getParent()->getNumSubEntities() && (subid == -1); i++)
209 if (subEntity->getParent()->getSubEntity(i) == subEntity)
214 if (mCameraSelector != 0)
218 Ogre::Any bindedCustomEntity = subEntity->getUserObjectBindings().getUserAny(
"SEntity");
219 SEntity* entity = Ogre::any_cast<SEntity*> (bindedCustomEntity);
223 nRaycastValue.
entity = entity;
233 nRaycastValue.
point = pos;
238 Ogre::Any bindedCustomEntity = subEntity->getUserObjectBindings().getUserAny(
"SEntity");
239 SEntity* entity = Ogre::any_cast<SEntity*> (bindedCustomEntity);
246 nRaycastValue.
entity = entity;
257 Ogre::Ray ray = mRayCam->getCameraToViewportRay(fabs(xR), fabs(yR));
279 Ogre::Ray ray = mRayCam->getCameraToViewportRay(fabs(xR), fabs(yR));
286 mRaycastValue = nRaycastValue;