Skip to content

Instantly share code, notes, and snippets.

View Groogy's full-sized avatar

Groogy Groogy

View GitHub Profile
def self.translate(matrix : Matrix(T, 4, 16), translation : Vector(T, 3)) forall T
cpy = matrix.dup
cpy[3, 0] = translation.x
cpy[3, 1] = translation.y
cpy[3, 2] = translation.z
cpy
end
def self.translate(matrix : Matrix(T, 4, 16), translation : Vector(T, 3)) forall T
matrix[3, 0] = translation.x
private macro do_math(operator, times)
self[{{SIZE - times}}].{{operator}}(other[{{SIZE - times}})]
{% if times != 0 %}
, do_math({{operator}}, {{times - 1}})
{% end %}
end
def +(other : Vector(Type, Size))
self.class.new(do_math(:+, SIZE))
end
struct Vector2(Type)
SIZE = 2
TYPE = Type
ZERO = self.new()
ONE = self.new(1, 1)
property :x, :y
@x : Type
@y : Type
class FooBar
def initialize(@value = 0)
end
def value
@value
end
protected def value=(val)
@value = val
macro finished
{% for definition in Crystal::Clear::CLASS_COMPILE_DATA %}
class {{definition[0]}}
Crystal::Clear::CLASS_RUNTIME_DATA << Crystal::Clear::ClassData({{definition[0]}}).new()
def {{definition[1]}}
{% for condition in definition[2] %}
if(({{condition}}) == false)
raise Crystal::Clear::Exception.new("Failed {{definition[0]}} require contract: {{condition}}")
end
{% end %}
class Foo
invariant( some_other_test ) # Run at entry of every contract
# First argument run at function start, second argument run at function end
contract baz == true, @thing.nil? == false,
def bar(val)
@thing = val.do_thing
end
end
// In Update function
myTransform = sf::Transform::Identity
myTransform.translate(-originVector);
myTransform.roate(rotation);
// In Draw
states.transform = states.transform.combine(myTransform);
target.draw(sprite, states);
class BaseSubscriberInterface
{
publlic:
/* stuff */
};
class DerivedSubscriber : public BaseSubscriberInterface
{
public:
void funcThatReceivesMessage(const Message& message);
MessageType foo = MessageType(Messages.Base) ~ MessageType(Messages.Window) ~ MessageType(Messages.Foo);
writeln(foo.toString());
MessageType bar = MessageType("Base.Window.Foo");
writeln(bar.toString());
#version 330
vertex
{
layout(location = 0) in vec4 position;
void main()
{
gl_Position = position;
}
}