PageRenderTime 409ms CodeModel.GetById 201ms app.highlight 1ms RepoModel.GetById 206ms app.codeStats 0ms

/OJGL/GLPrimitive.j

http://github.com/tartiflop/ojgl
Unknown | 131 lines | 98 code | 33 blank | 0 comment | 0 complexity | e21775471c79022ed366ce240a006593 MD5 | raw file
  1@import <Foundation/CPObject.j>
  2@import "GLContext.j"
  3@import "GLRenderer.j"
  4@import "GLMaterial.j"
  5
  6@implementation GLPrimitive : CPObject {
  7	Array _vertices;
  8	Array _normals;
  9	Array _uvs;
 10	Array _indices;
 11	
 12	int _vertexBufferId;
 13	int _normalBufferId;
 14	int _uvBufferId;
 15	int _indicesBufferId;
 16
 17	GLMaterial _material;
 18	Matrix4D _transformation;
 19}
 20
 21- (id)init:(GLMaterial)material {
 22	self = [super init];
 23	
 24	if (self) {
 25		_material = material;
 26		[_material setPrimitive:self];
 27		
 28		_transformation = new Matrix4D();
 29	}
 30	
 31	return self;
 32}
 33
 34- (void)buildPrimitive {
 35	_vertices = [];
 36	_normals = [];
 37	_uvs = [];
 38	_indices = [];
 39
 40}
 41
 42- (void)prepareGL:(GLContext)glContext {
 43	
 44	// Initialise the material
 45	[_material prepareGL:glContext];
 46	
 47	// Create and initialise buffer data
 48	_vertexBufferId = [glContext createBufferFromArray:_vertices];
 49	_indicesBufferId = [glContext createBufferFromElementArray:_indices];
 50}
 51
 52- (void)prepareUVs:(GLContext)glContext  {
 53	// Create and initialise UV buffer data
 54	_uvBufferId = [glContext createBufferFromArray:_uvs];
 55}
 56
 57- (void)prepareNormals:(GLContext)glContext  {
 58	// Create and initialise normal buffer data
 59	_normalBufferId = [glContext createBufferFromArray:_normals];
 60}
 61
 62- (void)rotate:(float)angle x:(float)x y:(float)y z:(float)z {
 63	_transformation.rotate(angle, x, y, z);
 64}
 65
 66- (void)setRotation:(float)angle x:(float)x y:(float)y z:(float)z {
 67	_transformation.setRotation(angle, x, y, z);
 68}
 69
 70- (void)translate:(float)x y:(float)y z:(float)z {
 71	_transformation.translate(x, y, z);
 72}
 73
 74- (void)setTranslation:(float)x y:(float)y z:(float)z {
 75	_transformation.setTranslation(x, y, z);
 76}
 77
 78- (void)resetTransformation {
 79	_transformation.makeIdentity();
 80}
 81
 82- (Array)vertices {
 83	return _vertices;
 84}
 85
 86- (Array)normals {
 87	return _normals;
 88}
 89
 90- (Array)uvs {
 91	return _uvs;
 92}
 93
 94- (Array)indices {
 95	return _indices;
 96}
 97
 98- (int)numberOfElements {
 99	return _indices.length;
100}
101
102- (int)numberOfVertices {
103	return _vertices.length;
104}
105
106- (int)getUVBufferId {
107	return _uvBufferId;
108}
109
110- (int)getVertexBufferId {
111	return _vertexBufferId;
112}
113
114- (int)getNormalBufferId {
115	return _normalBufferId;
116}
117
118- (int)getIndicesBufferId {
119	return _indicesBufferId;
120}
121
122- (GLMaterial)getMaterial {
123	return _material;
124}
125
126- (Matrix4D)getTransformation {
127	return _transformation;
128}
129
130
131@end