This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Tests each segment for a hit. All calculations are done in screen space pixel coordinates | |
bool CollisionPath::hitTest(const ViewportPosition &selection_position) const | |
{ | |
const Vector2 &mouse_pixel_pos = selection_position.getPixelPosition(); | |
const Viewport &viewport = selection_position.getViewport(); | |
const Camera &camera = viewport.getCamera(); | |
const WorldLayer &layer = *getLayer(); | |
for(auto iter = anchors.begin(); iter != anchors.end()-1; ++iter) { | |
const Vector2 &segment_begin = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Default type traits for class Matrix | |
template <class type> | |
class DefaultMatrixTraits | |
{ | |
public: | |
static const type zero() { return (type)0; } | |
static const type one() { return (type)1; } | |
static const type two() { return (type)2; } | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fast SSE pow for range [0, 1] | |
// Adapted from C. Schlick with one more iteration each for exp(x) and ln(x) | |
// 8 muls, 5 adds, 1 rcp | |
inline __m128 _mm_fastpow_0_1_ps(__m128 x, __m128 y) | |
{ | |
static const __m128 fourOne = _mm_set1_ps(1.0f); | |
static const __m128 fourHalf = _mm_set1_ps(0.5f); | |
__m128 a = _mm_sub_ps(fourOne, y); | |
__m128 b = _mm_sub_ps(x, fourOne); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reconstruct worldspace depth value from z/w depth buffer | |
float depth = -(z_near * z_far) / (zbuffer_depth * (z_far - z_near) - z_far); | |
// Compute screenspace coordinate of pixel | |
float2 screenspace = (float2(pixel.xy) / float2(viewport_size.xy)) * 2.0f - 1.0f; | |
// Get direction of ray from camera through pixel | |
float3 ray_direction = normalize(camera_forward + camera_right * screenspace.x - camera_up * screenspace.y); | |
// Reconstruct world position from depth: depth in z buffer is distance to picture plane, not camera |