Refactor: replace 'isect_ray_plane_v3' with 'isect_ray_plane_v3_factor'

By using `isect_ray_plane_v3_factor` we avoid calculating the v4 plane.
This commit is contained in:
Germano Cavalcante
2024-02-13 21:06:03 -03:00
parent c9bd326255
commit 1a74b80d42
6 changed files with 19 additions and 26 deletions

View File

@@ -5672,17 +5672,17 @@ static int add_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
ED_view3d_global_to_vector(vc.rv3d, location, view_dir);
/* get the plane */
float plane[4];
const float *plane_co = vc.obedit->object_to_world[3];
float plane_no[3];
/* only normalize to avoid precision errors */
normalize_v3_v3(plane, vc.obedit->object_to_world[2]);
plane[3] = -dot_v3v3(plane, vc.obedit->object_to_world[3]);
normalize_v3_v3(plane_no, vc.obedit->object_to_world[2]);
if (fabsf(dot_v3v3(view_dir, plane)) < eps) {
if (fabsf(dot_v3v3(view_dir, plane_no)) < eps) {
/* can't project on an aligned plane. */
}
else {
float lambda;
if (isect_ray_plane_v3(location, view_dir, plane, &lambda, false)) {
if (isect_ray_plane_v3_factor(location, view_dir, plane_co, plane_no, &lambda)) {
/* check if we're behind the viewport */
float location_test[3];
madd_v3_v3v3fl(location_test, location, view_dir, lambda);

View File

@@ -151,17 +151,17 @@ static void update_location_for_2d_curve(const ViewContext *vc, float location[3
ED_view3d_global_to_vector(vc->rv3d, location, view_dir);
/* Get the plane. */
float plane[4];
const float *plane_co = vc->obedit->object_to_world[3];
float plane_no[3];
/* Only normalize to avoid precision errors. */
normalize_v3_v3(plane, vc->obedit->object_to_world[2]);
plane[3] = -dot_v3v3(plane, vc->obedit->object_to_world[3]);
normalize_v3_v3(plane_no, vc->obedit->object_to_world[2]);
if (fabsf(dot_v3v3(view_dir, plane)) < eps) {
if (fabsf(dot_v3v3(view_dir, plane_no)) < eps) {
/* Can't project on an aligned plane. */
}
else {
float lambda;
if (isect_ray_plane_v3(location, view_dir, plane, &lambda, false)) {
if (isect_ray_plane_v3_factor(location, view_dir, plane_co, plane_no, &lambda)) {
/* Check if we're behind the viewport */
float location_test[3];
madd_v3_v3v3fl(location_test, location, view_dir, lambda);

View File

@@ -363,14 +363,11 @@ static int gizmo_arrow_modal(bContext *C,
float arrow_no_proj[3];
project_plane_v3_v3v3(arrow_no_proj, arrow_no, proj[j].ray_direction);
normalize_v3(arrow_no_proj);
float plane[4];
plane_from_point_normal_v3(plane, proj[j].ray_origin, arrow_no_proj);
float lambda;
if (isect_ray_plane_v3(arrow_co, arrow_no, plane, &lambda, false)) {
if (isect_ray_plane_v3_factor(arrow_co, arrow_no, proj[j].ray_origin, arrow_no_proj, &lambda))
{
madd_v3_v3v3fl(proj[j].location, arrow_co, arrow_no, lambda);
ok++;
}

View File

@@ -3687,9 +3687,8 @@ static bool knife_snap_angle_relative(KnifeTool_OpData *kcd)
mul_transposed_mat3_m4_v3(kcd->curr.ob->world_to_object, no_global);
normalize_v3(no_global);
plane_from_point_normal_v3(plane, kcd->prev.cage, no_global);
if (isect_ray_plane_v3(curr_origin, curr_ray_normal, plane, &lambda, false)) {
if (isect_ray_plane_v3_factor(curr_origin, curr_ray_normal, kcd->prev.cage, no_global, &lambda))
{
madd_v3_v3v3fl(ray_hit, curr_origin, curr_ray_normal, lambda);
/* Calculate snap step. */

View File

@@ -492,17 +492,14 @@ void ED_view3d_win_to_3d(const View3D *v3d,
float lambda;
if (rv3d->is_persp) {
float plane[4];
copy_v3_v3(ray_origin, rv3d->viewinv[3]);
ED_view3d_win_to_vector(region, mval, ray_direction);
/* NOTE: we could use #isect_line_plane_v3()
* however we want the intersection to be in front of the view no matter what,
* so apply the unsigned factor instead. */
plane_from_point_normal_v3(plane, depth_pt, rv3d->viewinv[2]);
isect_ray_plane_v3_factor(ray_origin, ray_direction, depth_pt, rv3d->viewinv[2], &lambda);
isect_ray_plane_v3(ray_origin, ray_direction, plane, &lambda, false);
lambda = fabsf(lambda);
}
else {

View File

@@ -318,12 +318,12 @@ void transform_constraint_snap_axis_to_face(const TransInfo *t,
float r_out[3])
{
float lambda;
float face_plane[4];
const float *face_snap_point = t->tsnap.snap_target;
const float *face_normal = t->tsnap.snapNormal;
plane_from_point_normal_v3(face_plane, face_snap_point, face_normal);
bool is_aligned = fabsf(dot_v3v3(axis, face_plane)) < CONSTRAIN_EPSILON;
if (!is_aligned && isect_ray_plane_v3(t->tsnap.snap_source, axis, face_plane, &lambda, false)) {
bool is_aligned = fabsf(dot_v3v3(axis, face_normal)) < CONSTRAIN_EPSILON;
if (!is_aligned &&
isect_ray_plane_v3_factor(t->tsnap.snap_source, axis, face_snap_point, face_normal, &lambda))
{
mul_v3_v3fl(r_out, axis, lambda);
}
}