0

# 今日目標

• 繼續Debug Ray vs Rect的部分

# MISSION FAILED!

QAQ 今天又很晚下班了 只有單純的把昨天的部分再抄一遍，但還是理解不能....，目前我先測試上傳了，可能要到假日有時間再來理解可能會比較好，腦袋會比較清楚，然後這是我原本寫的，很亂，目前比較看不出問題在哪>

``````            ray_dir = V2F_ZERO;
contact_point = V2F_ZERO;
contact_norm = V2F_ZERO;
hit_near = false;
is_hit = true;

ray_dir = V2fSub(end_point, start_point);

V2f min_pos = obstacle.pos;
V2f near = V2fSub(min_pos, start_point);
near.x /= ray_dir.x;
near.y /= ray_dir.y;

V2f max_pos = { obstacle.pos.x + obstacle.rec.w, obstacle.pos.y + obstacle.rec.h };
V2f far = V2fSub( max_pos, start_point);
far.x /= ray_dir.x;
far.y /= ray_dir.y;

if (near.x > far.x) {
float tmp = near.x;
near.x = far.x;
far.x = tmp;
}

if (near.y > far.y) {
float tmp = near.y;
near.y = far.y;
far.y = tmp;
}

if (near.x > far.y || near.y > far.x) {
is_hit = false;
}

if (near.x > near.y) {
hit_near = near.x;
} else {
hit_near = near.y;
}

if (near.x > near.y) {
if (ray_dir.x < 0.0f) {
contact_norm.x = 1.0f;
contact_norm.y = 0.0f;
} else {
contact_norm.x = -1.0f;
contact_norm.y = 0.0f;
}
} else if (near.x < near.y) {
if (ray_dir.x < 0.0f) {
contact_norm.x = 0.0f;
contact_norm.y = -1.0f;
} else {
contact_norm.x = 0.0f;
contact_norm.y = 1.0f;
}
}

if (hit_near > 1.0f) {
is_hit = false;
}
``````