factor/examples/factoroids/models.factor

143 lines
3.2 KiB
Factor

USING: arrays gadgets generic hashtables io kernel math
namespaces opengl sdl sequences threads ;
IN: factoroids
TUPLE: face color normal polygon ;
: draw-face ( colors face -- )
[ face-color swap nth gl-color ] keep
( dup face-normal gl-normal )
face-polygon gl-fill-poly ;
TUPLE: model faces ;
: draw-model ( colors model -- )
model-faces [ draw-face ] each-with ;
: factoroid
T{ model f
{
T{ face f
0
{ 0 0 -1 }
{
{ -1/2 -1/2 -1/2 }
{ 1/2 -1/2 -1/2 }
{ 1/2 1/2 -1/2 }
{ -1/2 1/2 -1/2 }
}
}
T{ face f
0
{ 0 0 1 }
{
{ -1/2 -1/2 1/2 }
{ 1/2 -1/2 1/2 }
{ 1/2 1/2 1/2 }
{ -1/2 1/2 1/2 }
}
}
T{ face f
0
{ -1 0 0 }
{
{ -1/2 -1/2 -1/2 }
{ -1/2 -1/2 1/2 }
{ -1/2 1/2 1/2 }
{ -1/2 1/2 -1/2 }
}
}
T{ face f
0
{ 1 0 0 }
{
{ 1/2 -1/2 -1/2 }
{ 1/2 -1/2 1/2 }
{ 1/2 1/2 1/2 }
{ 1/2 1/2 -1/2 }
}
}
T{ face f
0
{ 0 -1 0 }
{
{ -1/2 -1/2 -1/2 }
{ -1/2 -1/2 1/2 }
{ 1/2 -1/2 1/2 }
{ 1/2 -1/2 -1/2 }
}
}
T{ face f
0
{ 0 1 0 }
{
{ -1/2 1/2 -1/2 }
{ -1/2 1/2 1/2 }
{ 1/2 1/2 1/2 }
{ 1/2 1/2 -1/2 }
}
}
}
} ;
: rocket
T{ model f
{
T{ face f
0
{ 0 -1 0 }
{
{ -1/2 0 -1/2 }
{ 0 1/2 -1/2 }
{ 1/2 0 -1/2 }
{ 0 -1/2 -1/2 }
}
}
T{ face f
1
f
{
{ -1/2 0 -1/2 }
{ 0 1/2 -1/2 }
{ 0 0 1/2 }
}
}
T{ face f
1
f
{
{ 0 1/2 -1/2 }
{ 1/2 0 -1/2 }
{ 0 0 1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