Skip to content

Instantly share code, notes, and snippets.

View ThePhD's full-sized avatar
🐑
Ready to roll!

The Phantom Derpstorm ThePhD

🐑
Ready to roll!
View GitHub Profile
reference_triangle operator[] ( std::size_t idx ) {
switch ( topology ) {
case PrimitiveTopology::TriangleList:
idx /= 3;
return reference_triangle( vertices[ indices[ idx ] ], vertices[ indices[ idx + 1 ] ], vertices[ indices[ idx + 2 ] ] );
break;
case PrimitiveTopology::TriangleStrip:
idx += 2;
return reference_triangle( vertices[ indices[ idx ] ], vertices[ indices[ idx - 1 ] ], vertices[ indices[ idx - 2 ] ] );
break;
@ThePhD
ThePhD / gist:8249647
Created January 4, 2014 00:33
unreachable
#pragma once
namespace Furrovine {
#ifdef _MSC_VER
#define unreachable __assume( 0 )
#elif _GCC_VER
#define unreachable __builtin_unreachable( )
#else
#error Define unreachable for this platform
@ThePhD
ThePhD / WHAT A WASTE.c++
Created January 4, 2014 16:57
WAAAAAAAAAAAAAAASTE
template <typename TString, typename ...Tn>
inline typename unqualified<TString>::type Format( TString&& format, Tn&&... argn ) {
typedef typename unqualified<TString>::type string_t;
const static ulword arg_count = sizeof...( Tn );
if ( arg_count < 1 ) {
return std::forward<TString>( format );
}
std::array<string_t, sizeof...( Tn )> convertedvalues = {
Convert::ToString( std::forward<Tn>( argn ) )...
@ThePhD
ThePhD / Blah.c++
Created January 20, 2014 02:23
I HOPE YOU'RE HAPPY
template <typename T>
Fur::optional<RHit<T>> intersect( const Fur::TRay3<T>& ray, const RSphere<T>& target ) {
Fur::TVector3<T> ray2sphere = target.position - ray.Origin;
T dist = ray2sphere.Dot( ray.Direction );
T ray2spheresquared = ray2sphere.Dot( ray2sphere );
T radiussquared = Radius * Radius;
if ( dist < 0
&& ray2spheresquared > radiussquared ) {
return nullopt;
float4x4 ViewProjection;
texture Tex0;
sampler Texture0;
void ImageVertex ( inout float4 position : SV_Position,
inout float4 color : COLOR0,
inout float2 tex : TEXCOORD0 ) {
position = mul(position, ViewProjection);
template <typename T, typename TValue, typename TIntermediate = double>
T color_normalize( TValue value, TValue valuemax = color_limits<TValue>::max( ), TValue valuemin = color_limits<TValue>::max( ), T max = color_limits<T>::max( ), T min = color_limits<T>::min( ) ) {
TIntermediate valuerange = static_cast<TIntermediate>( value - valuemin ) / static_cast<TIntermediate>( valuemax );
return static_cast<T>( valuerange * ( max - min ) );
}
@ThePhD
ThePhD / lerp.c++
Last active August 29, 2015 13:55
Lerp
template <typename T, ulword n, typename Tw>
RVector<T, n> lerp( const RVector<T, n>& from, const RVector<T, n>& towards, Tw weight ) {
weight = Mathema<Tw>::MiniMax( weight, static_cast<Tw>( 0 ), static_cast<Tw>( 1 ) );
Tw affweight = 1.0f - weight;
RVector<T, n> r;
for ( ulword i = 0; i < n; ++i ) {
r[ i ] = static_cast<T>( from[i] * weight + affweight * towards[i] );
}
return r;
}
namespace foo {
struct bar {
bar(qux a,
quux b);
int xxx;
double yyy;
};
}
#pragma once
struct adder {
template <typename Tl, typename Tr>
auto operator()( Tl&& left, Tr&& right )
-> decltype( left + right ) {
return left + right;
}
};
@ThePhD
ThePhD / lua_class.c++
Last active August 29, 2015 14:00
lua_class.c++
namespace sol {
template <typename... Tn>
struct constructors { };
template <typename T>
class lua_class {
public:
static const std::string classname;
static const std::string meta;