MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / getPos

Method getPos

Source/Input/TouchDispather.cpp:184–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

182}
183
184Vec2 NodeTouchHandler::getPos(const Vec3& winPos) {
185 Vec3 pos = winPos;
186 Size viewSize = SharedView.getSize();
187
188 Matrix invMVP;
189 {
190 Matrix MVP;
191 Matrix::mulMtx(MVP, SharedDirector.getViewProjection(), _target->getWorld());
192 bx::mtxInverse(invMVP.m, MVP.m);
193 }
194 bx::Plane plane(bx::InitNone);
195 bx::calcPlane(plane, bx::Vec3{0, 0, 0}, bx::Vec3{1, 0, 0}, bx::Vec3{0, 1, 0});
196
197 Vec3 posTarget{pos.x, pos.y, 1.0f};
198 float viewPort[4]{0, 0, viewSize.width, viewSize.height};
199
200 Vec3 origin, target;
201 unProject(pos.x, pos.y, pos.z, invMVP, viewPort, origin);
202 unProject(posTarget.x, posTarget.y, posTarget.z, invMVP, viewPort, target);
203
204 bx::Vec3 dir = bx::sub(target, origin);
205 bx::Vec3 dirNorm = bx::normalize(dir);
206 float denom = bx::dot(dirNorm, plane.normal);
207 if (std::abs(denom) >= FLT_EPSILON) {
208 float nom = bx::dot(origin, plane.normal) + plane.dist;
209 float t = -(nom / denom);
210 if (t >= 0) {
211 bx::Vec3 offset = bx::mul(dirNorm, t);
212 bx::Vec3 result = bx::add(origin, offset);
213 return Vec2{result.x, result.y};
214 }
215 }
216 return Vec2{-1.0f, -1.0f};
217}
218
219Vec2 NodeTouchHandler::getPos(const SDL_Event& event) {
220 Vec3 pos{-1.0f, -1.0f, 0.0f};

Callers

nothing calls this directly

Calls 12

mtxInverseFunction · 0.85
calcPlaneFunction · 0.85
unProjectFunction · 0.85
getWorldMethod · 0.80
getWinSizeMethod · 0.80
subClass · 0.50
normalizeFunction · 0.50
dotClass · 0.50
absFunction · 0.50
mulClass · 0.50
addFunction · 0.50
getSizeMethod · 0.45

Tested by

no test coverage detected