Skip to content

Instantly share code, notes, and snippets.

@miguel-negrao
Created June 5, 2012 16:50
Show Gist options
  • Save miguel-negrao/2876191 to your computer and use it in GitHub Desktop.
Save miguel-negrao/2876191 to your computer and use it in GitHub Desktop.
FP3D - SuperCollider - drawing a cube
(
var width = 500, height = 400, rate = 0.005;
var u = UserView(nil, Rect(128, 64, width, height) );
var sides = [
// Front face
[[-1.0, -1.0, 1.0],
[1.0, -1.0, 1.0],
[1.0, 1.0, 1.0],
[-1.0, 1.0, 1.0]],
// Back face
[[-1.0, -1.0, -1.0],
[-1.0, 1.0, -1.0],
[1.0, 1.0, -1.0],
[1.0, -1.0, -1.0]],
// Top face
[[-1.0, 1.0, -1.0],
[-1.0, 1.0, 1.0],
[1.0, 1.0, 1.0],
[1.0, 1.0, -1.0]],
// Bottom face
[[-1.0, -1.0, -1.0],
[1.0, -1.0, -1.0],
[1.0, -1.0, 1.0],
[-1.0, -1.0, 1.0]],
// Right face
[[1.0, -1.0, -1.0],
[1.0, 1.0, -1.0],
[1.0, 1.0, 1.0],
[1.0, -1.0, 1.0]],
// Left face
[[-1.0, -1.0, -1.0],
[-1.0, -1.0, 1.0],
[-1.0, 1.0, 1.0],
[-1.0, 1.0, -1.0]]];
var poligons = sides.collect{ |vertices|
FP3DPoligon(
vertices,
[ FP3DTransform.mScale(0.5) ],
Color(0.0,0.0,0.0), 0.5, 0.5, 0.5, 0.5
);
};
var makeScene = { |trans|
FP3DScene( poligons, 200, 0.3, 2,
perspective: 0.1,
transforms: trans,
lightColor: Color(0.5,0.0,0.0),
lightDir: RealVector[0,1,1]
)
};
var set3DScene = { |trans| u.setDrawing( makeScene.(trans).drawing(width, height) ) };
var desc = Do(
m <- u.mouseMoveEN;
m.hold( Tuple4(nil,0,0,0) ).collect{ |t|
set3DScene.( [
FP3DTransform.mRotateY( t.at2 / 500 * 2pi ),
FP3DTransform.mRotateX( t.at3 / 400 * 2pi )
])
}.reactimate
);
var n = EventNetwork( desc );
Do(
n.actuate;
u.setPropIO(\background_, Color.white);
u.frontIO;
set3DScene.([])
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment