You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.3 KiB
Objective-C

#import "Model.h"
@implementation YSModel
-(id) initWithModel: (const char *) path {
if ( (self = [super init]) ) {
model = LoadModel( path );
}
return self;
}
-(id) initWithModel: (const char *) mdl_path andTexture: (const char *) tex_path {
if ( (self = [super init]) ) {
model = LoadModel( mdl_path );
texture = LoadTexture( tex_path );
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
}
return self;
}
-(void) setModel: (const char *) mdl_path {
model = LoadModel(mdl_path);
}
-(Model) model {
return model;
}
-(Vector3) pos {
return pos;
}
-(void) setPos: (Vector3) p {
pos = p;
}
-(void) setTexture: (const char *) tex_path {
//maybe unload previous texture if any
texture = LoadTexture( tex_path );
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
}
-(void) dealloc {
UnloadModel(model);
//unload texture too
[super dealloc];
}
-(void) draw {
DrawModel(model, pos, 1.0f, WHITE);
#define DEBUG
#ifdef DEBUG
[self drawBoundingBox];
#endif
}
-(void) drawBoundingBox {
BoundingBox bbox = GetModelBoundingBox(model);
bbox.min = Vector3Add(pos, bbox.min);
bbox.max = Vector3Add(pos, bbox.max);
DrawBoundingBox(bbox, RED);
}
@end