Untitled
unknown
c_cpp
a year ago
934 B
9
Indexable
bool world_to_screen(vec3_t world_location, vec2_t& out, vec3_t camera_pos, int screen_width, int screen_height, vec2_t fov, vec3_t matricies[3]) {
auto local = world_location - camera_pos;
auto trans = vec3_t{
local.dot(matricies[1]),
local.dot(matricies[2]),
local.dot(matricies[0])
};
if (trans.z < 0.01f) {
return false;
}
out.x = ((float)screen_width / 2.0) * (1.0 - (trans.x / fov.x / trans.z));
out.y = ((float)screen_height / 2.0) * (1.0 - (trans.y / fov.y / trans.z));
if (out.x < 1 || out.y < 1 || (out.x > sdk::ref_def.width) || (out.y > sdk::ref_def.height)) {
return false;
}
return true;
}
bool w2s(vec3_t world_position, vec2_t& screen_position) {
return world_to_screen(world_position, screen_position, get_camera_position(), ref_def.width, ref_def.height, ref_def.view.tan_half_fov, ref_def.view.axis);
}Editor is loading...
Leave a Comment