Comments (3)
You can use XMVector3Project: https://learn.microsoft.com/en-us/windows/win32/api/directxmath/nf-directxmath-xmvector3project
from wickedengine.
Can you offset your (0,0,0) farther from camera, like at (0,0,1) for example? Because might be that camera near clip plane in projection matrix is causing the unexpected values, because your point is outside the near plane.
Btw this XMVector3Project function is just a helper over multiplying your world space point with the camera's viewProjection matrix. So you can also try this:
XMVECTOR worldpos = XMVectorSet(0,0,1);
XMVECTOR screenpos = XMVector3TransformCoord(worldpos, camera.GetViewProjection()); // to normalized device coordinates in [-1,1] range
screenpos = screenpos * XMVectorSet(0.5f, -0.5f, 1, 1) + XMVectorSet(0.5f, 0.5f, 0, 0); // [-1,1] -> [0,1] range and flip on Y
screenpos = screenpos * XMVectorSet(3840, 2160, 1, 1); // [0,1] range to pixel coordinates
from wickedengine.
Thank you, it's probably my bad knowledge or I'm not configuring it correctly in the viewport, I don't know if it's the aspect ratio or the dpi but the result on the y axis is not correct I think, I'll show you the code and the result obtained and desired.
// Resolution -> width= 3840 --- height=2160 ---- dpi=144
Result obtained with input 3d pos (0,0,0) -> x=1920 | y=1454.122925 | z=0.009980
Result desired x=1920 | y=1080
Code used:
`
Viewport v;
v.width = GetInternalResolution().x;
v.height = GetInternalResolution().y;
v.min_depth = 0.0f;
v.max_depth = 1.0f;
v.top_left_x = 0.0f;
v.top_left_y = 0.0f;
EditorScene& e = GetCurrentEditorScene();
XMFLOAT3 in_v3 = XMFLOAT3(0.0f, 0.0f, 0.0f);
//XMVECTOR r_v = XMVector3Project(XMLoadFloat3(&in_v3), v.top_left_x, v.top_left_y, v.width, v.height, v.min_depth, v.max_depth, e.scene.camera.GetProjection(), e.scene.camera.GetView(), XMLoadFloat4x4(&e.camera_transform.world)));
XMVECTOR r_v = XMVector3Project(XMLoadFloat3(&in_v3), v.top_left_x, v.top_left_y, v.width, v.height, v.min_depth, v.max_depth, e.scene.camera.GetProjection(), e.scene.camera.GetView(), XMMatrixIdentity());
XMFLOAT3 r_pos;
XMStoreFloat3(&r_pos, r_v);`
I'm probably missing some dpi or aspect ratio calculation over z value, I've tried with several cameras and instead of using an identity matrix with the camera transformation world and I always get the same result.
from wickedengine.
Related Issues (20)
- [feature] SDL2 visual studio project for Windows OS with DX12 & Vulkan
- Incorrect assertion in video parser HOT 1
- Does the `config.ini` have some font-size setting? HOT 2
- scale and rotation drifting HOT 1
- [feature] USD importer HOT 4
- Issues using WickedEngine as submodule HOT 5
- Linux: segfault on window-close / quit HOT 1
- Crash with: DXGI_ERROR_INVALID_CALL
- FSR 2.2 HOT 1
- Vulkan Synchronization Error HOT 3
- Minor typo in ssaoCS.hlsl HOT 2
- Editor keeps freezing HOT 2
- Bug in CloudShadowFilter? HOT 1
- Incomprehensible work of wi::jobsystem. HOT 5
- UI/UX improvments HOT 5
- Double-clicking an object in Entities menu moves the to it HOT 2
- Terrain uv mapping performs correct? HOT 8
- Engine crashes after trying to upload a video HOT 1
- Export video HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wickedengine.