`world to screen` C++ Examples
12 C++ code examples are found related to "world to screen".
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: DrawingUtils.cpp From Rust-Cheat with Apache License 2.0 | 7 votes |
bool WorldToScreen(D3DXVECTOR3 origin, D3DXVECTOR2 * out) { D3DXMATRIX temp; D3DXMatrixTranspose(&temp, &viewMatrix); D3DXVECTOR3 translationVector = D3DXVECTOR3(temp._41, temp._42, temp._43); D3DXVECTOR3 up = D3DXVECTOR3(temp._21, temp._22, temp._23); D3DXVECTOR3 right = D3DXVECTOR3(temp._11, temp._12, temp._13); float w = D3DXVec3Dot(&translationVector, &origin) + temp._44; if (w < 0.098f) return false; float y = D3DXVec3Dot(&up, &origin) + temp._24; float x = D3DXVec3Dot(&right, &origin) + temp._14; out->x = (int)(Width / 2) * (1.f + x / w); out->y = (int)(Height / 2) * (1.f - y / w); return true; }
Example 2
Source File: Camera.cpp From r6s-internal with MIT License | 6 votes |
Vector3 Camera::WorldToScreen(Vector3 position) { if (!Memory::IsValidPtr<Camera>(this)) return *(new Vector3()); Vector3 temp = position - GetViewTranslation(); float x = temp.Dot(GetViewRight()); float y = temp.Dot(GetViewUp()); float z = temp.Dot(GetViewForward() * -1); ImGuiIO& io = ImGui::GetIO(); return *(new Vector3( (io.DisplaySize.x / 2) * (1 + x / GetViewFovX() / z), (io.DisplaySize.y / 2) * (1 - y / GetViewFovY() / z), z)); }
Example 3
Source File: camera.cpp From octoon with MIT License | 6 votes |
math::float3 Camera::screenToWorld(const math::float3& pos) const noexcept { math::float4 viewport = this->getPixelViewport(); math::float4 v(pos, 1.0); v.y = viewport.w - v.y; // opengl v.x = ((v.x - viewport.x) / viewport.z) * 2.0f - 1.0f; v.y = ((v.y - viewport.y) / viewport.w) * 2.0f - 1.0f; v = this->getViewProjectionInverse() * v; if (v.w != 0) v /= v.w; return math::float3(v.x, v.y, v.z); }
Example 4
Source File: camera.cpp From octoon with MIT License | 6 votes |
math::float3 Camera::worldToScreen(const math::float3& pos) const noexcept { math::float4 viewport = this->getPixelViewport(); float w = viewport.z * 0.5f; float h = viewport.w * 0.5f; math::float4 v = this->getViewProjection() * math::float4(pos, 1.0); if (v.w != 0) v /= v.w; v.x = v.x * w + w + viewport.x; v.y = v.y * h + h + viewport.y; return math::float3(v.x, v.y, v.z); }
Example 5
Source File: DebugDraw.cpp From SimpleRenderEngineProject with MIT License | 6 votes |
b2Vec2 Camera::ConvertScreenToWorld(const b2Vec2& ps) { float32 w = float32(m_width); float32 h = float32(m_height); float32 u = ps.x / w; float32 v = (h - ps.y) / h; float32 ratio = w / h; b2Vec2 extents(ratio * 25.0f, 25.0f); extents *= m_zoom; b2Vec2 lower = m_center - extents; b2Vec2 upper = m_center + extents; b2Vec2 pw; pw.x = (1.0f - u) * lower.x + u * upper.x; pw.y = (1.0f - v) * lower.y + v * upper.y; return pw; }
Example 6
Source File: DebugDraw.cpp From SimpleRenderEngineProject with MIT License | 6 votes |
b2Vec2 Camera::ConvertWorldToScreen(const b2Vec2& pw) { float32 w = float32(m_width); float32 h = float32(m_height); float32 ratio = w / h; b2Vec2 extents(ratio * 25.0f, 25.0f); extents *= m_zoom; b2Vec2 lower = m_center - extents; b2Vec2 upper = m_center + extents; float32 u = (pw.x - lower.x) / (upper.x - lower.x); float32 v = (pw.y - lower.y) / (upper.y - lower.y); b2Vec2 ps; ps.x = u * w; ps.y = (1.0f - v) * h; return ps; }
Example 7
Source File: CODMath.cpp From Call-of-Duty-Black-Ops-III-Cheat with MIT License | 6 votes |
bool CODMath::WorldToScreen(vec3 world, float *x, float *y) { refdef_t* refdef = BO3Engine::getInstance()->GetRefDef(); vec3 Position = world.VectorSubtract(refdef->vecOrigin); vec3 Transform = vec3( Position.DotProduct(refdef->vecAxisY), Position.DotProduct(refdef->vecAxisZ), Position.DotProduct(refdef->vecAxisX)); if (Transform.z < 0.1f) return false; vec2 Center = vec2((float)(refdef->iWidth * 0.5f), (float)(refdef->iHeight * 0.5f)); *x = Center.x * (1 - (Transform.x / refdef->fFovX / Transform.z)); *y = Center.y * (1 - (Transform.y / refdef->fFovY / Transform.z)); return true; }
Example 8
Source File: Esp.cpp From Call-of-Duty-Black-Ops-III-Cheat with MIT License | 6 votes |
bool Esp:: WorldToScreen(vec3_t world, float *x, float *y) { refdef_t* refdef = CODEngine::GetRefDef(); vec3_t Position = world.VectorSubtract(refdef->vecOrigin); vec3_t Transform; // get our dot products from viewAxis Transform.x = Position.DotProduct(refdef->vecAxisY); Transform.y = Position.DotProduct(refdef->vecAxisZ); Transform.z = Position.DotProduct(refdef->vecAxisX); // make sure it is in front of us if (Transform.z < 0.1f) return false; // get the center of the screen vec2_t Center; Center.x = (float)(refdef->iWidth * 0.5f); Center.y = (float)(refdef->iHeight * 0.5f); *x = Center.x * (1 - (Transform.x / refdef->fFovX / Transform.z)); *y = Center.y * (1 - (Transform.y / refdef->fFovY / Transform.z)); return true; }
Example 9
Source File: UEPyController.cpp From UnrealEnginePython with MIT License | 5 votes |
PyObject *py_ue_controller_project_world_location_to_screen(ue_PyUObject * self, PyObject * args) { ue_py_check(self); PyObject *py_obj_point; PyObject *py_relative = nullptr; if (!PyArg_ParseTuple(args, "O|O:project_world_location_to_screen", &py_obj_point, &py_relative)) return nullptr; APlayerController *controller = ue_py_check_type<APlayerController>(self); if (!controller) return PyErr_Format(PyExc_Exception, "uobject is not an AController"); ue_PyFVector *point = py_ue_is_fvector(py_obj_point); if (!point) return PyErr_Format(PyExc_Exception, "argument is not a FVector"); // TODO: Check return value: FVector2D screenLocation; if (!controller->ProjectWorldLocationToScreen(point->vec, screenLocation, (py_relative && PyObject_IsTrue(py_relative)))) { return PyErr_Format(PyExc_Exception, "unable to project coordinates"); } return Py_BuildValue("(ff)", screenLocation.X, screenLocation.Y); }
Example 10
Source File: Camera2D.cpp From Mastering-Cpp-Game-Development with MIT License | 5 votes |
glm::vec2 Camera2D::ConvertScreenToWorld(glm::vec2 screenCoords) { // Invert Y direction screenCoords.y = m_screenHeight - screenCoords.y; // Make it so that 0 is the center screenCoords -= glm::vec2(m_screenWidth / 2, m_screenHeight / 2); // Scale the coordinates screenCoords /= m_scale; // Translate with the camera position screenCoords += m_position; return screenCoords; }
Example 11
Source File: ESP.cpp From GOESP with MIT License | 5 votes |
static bool worldToScreen(const Vector& in, ImVec2& out) noexcept { const auto& matrix = GameData::toScreenMatrix(); const auto w = matrix._41 * in.x + matrix._42 * in.y + matrix._43 * in.z + matrix._44; if (w < 0.001f) return false; out = ImGui::GetIO().DisplaySize / 2.0f; out.x *= 1.0f + (matrix._11 * in.x + matrix._12 * in.y + matrix._13 * in.z + matrix._14) / w; out.y *= 1.0f - (matrix._21 * in.x + matrix._22 * in.y + matrix._23 * in.z + matrix._24) / w; return true; }
Example 12
Source File: Esp.cpp From Osiris with MIT License | 5 votes |
static constexpr bool worldToScreen(const Vector& in, Vector& out) noexcept { const auto& matrix = interfaces->engine->worldToScreenMatrix(); float w = matrix._41 * in.x + matrix._42 * in.y + matrix._43 * in.z + matrix._44; if (w > 0.001f) { const auto [width, height] = interfaces->surface->getScreenSize(); out.x = width / 2 * (1 + (matrix._11 * in.x + matrix._12 * in.y + matrix._13 * in.z + matrix._14) / w); out.y = height / 2 * (1 - (matrix._21 * in.x + matrix._22 * in.y + matrix._23 * in.z + matrix._24) / w); out.z = 0.0f; return true; } return false; }