Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLUI Component Work #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions isgl3d.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,7 @@
8BDBA1D714CCFABE00BAEB8A /* PVRTShader.h in Headers */ = {isa = PBXBuildFile; fileRef = 8BDBA1C714CCFABE00BAEB8A /* PVRTShader.h */; };
8BDBA1D814CCFABE00BAEB8A /* PVRTTextureAPI.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8BDBA1C814CCFABE00BAEB8A /* PVRTTextureAPI.cpp */; };
8BDBA1D914CCFABE00BAEB8A /* PVRTTextureAPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 8BDBA1C914CCFABE00BAEB8A /* PVRTTextureAPI.h */; };
A0BE2C3F16220D6600ECA56E /* tex.png in Resources */ = {isa = PBXBuildFile; fileRef = 4E6075CB1521C9C40045AEFA /* tex.png */; };
AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -6183,6 +6184,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A0BE2C3F16220D6600ECA56E /* tex.png in Resources */,
17A95EF7132575A700D06694 /* capture.fsh in Resources */,
17A95EF8132575A700D06694 /* capture.vsh in Resources */,
17A95EF9132575A700D06694 /* generic.fsh in Resources */,
Expand Down
53 changes: 52 additions & 1 deletion isgl3d/primitives/Isgl3dPlane.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

/**
* The Isgl3dPlane constructs a planar mesh centered in the x-y plane, with z equal to 0.
* Optional offset parameters can be used to "move" the plane around in the x-y plane.
*
* An Isgl3dUVMap can be added to the plane to fine-tune the rendering of texture maps.
*
Expand All @@ -38,7 +39,9 @@
@interface Isgl3dPlane : Isgl3dPrimitive {
@protected
float _width;
float _height;
float _height;
float _offsetx;
float _offsety;
}


Expand All @@ -51,6 +54,17 @@
*/
+ (id)meshWithGeometry:(float)width height:(float)height nx:(int)nx ny:(int)ny;

/**
* Allocates and initialises (autorelease) plane with the specified geometry.
* @param width The width of the plane in the x-direction.
* @param height The height of the plane in the y-direction.
* @param nx The number of segments along the x-axis.
* @param ny The number of segments along the y-axis.
* @param offsetx The offset added to every x coordinate value.
* @param offsety The offset added to every y coordinate value.
*/
+ (id)meshWithGeometry:(float)width height:(float)height nx:(int)nx ny:(int)ny offsetx:(float)offsetx offsety:(float)offsety;

/**
* Allocates and initialises (autorelease) plane with the specified geometry and with a specific UV mapping.
* Examples of use:
Expand Down Expand Up @@ -79,6 +93,19 @@
*/
+ (id)meshWithGeometryAndUVMap:(float)width height:(float)height nx:(int)nx ny:(int)ny uvMap:(Isgl3dUVMap *)uvMap;

/**
* Allocates and initialises (autorelease) plane with the specified geometry and with a specific UV mapping.
*
* @param width The width of the plane in the x-direction.
* @param height The height of the plane in the y-direction.
* @param nx The number of segments along the x-axis.
* @param ny The number of segments along the y-axis.
* @param offsetx The offset added to every x coordinate value.
* @param offsety The offset added to every y coordinate value.
* @param uvMap The Isgl3dUVMap for mapping a texture material.
*/
+ (id)meshWithGeometryAndUVMap:(float)width height:(float)height nx:(int)nx ny:(int)ny offsetx:(float)offsetx offsety:(float)offsety uvMap:(Isgl3dUVMap *)uvMap;

/**
* Initialises the plane with the specified geometry.
* @param width The width of the plane in the x-direction.
Expand All @@ -88,6 +115,17 @@
*/
- (id)initWithGeometry:(float)width height:(float)height nx:(int)nx ny:(int)ny;

/**
* Initialises the plane with the specified geometry.
* @param width The width of the plane in the x-direction.
* @param height The height of the plane in the y-direction.
* @param nx The number of segments along the x-axis.
* @param ny The number of segments along the y-axis.
* @param offsetx The offset added to every x coordinate value.
* @param offsety The offset added to every y coordinate value.
*/
- (id)initWithGeometry:(float)width height:(float)height nx:(int)nx ny:(int)ny offsetx:(float)offsetx offsety:(float)offsety;

/**
* Initialises the plane with the specified geometry and with a specific UV mapping.
* Examples of use:
Expand Down Expand Up @@ -116,4 +154,17 @@
*/
- (id)initWithGeometryAndUVMap:(float)width height:(float)height nx:(int)nx ny:(int)ny uvMap:(Isgl3dUVMap *)uvMap;

/**
* Initialises the plane with the specified geometry and with a specific UV mapping.
*
* @param width The width of the plane in the x-direction.
* @param height The height of the plane in the y-direction.
* @param nx The number of segments along the x-axis.
* @param ny The number of segments along the y-axis.
* @param offsetx The offset added to every x coordinate value.
* @param offsety The offset added to every y coordinate value.
* @param uvMap The Isgl3dUVMap for mapping a texture material.
*/
- (id)initWithGeometryAndUVMap:(float)width height:(float)height nx:(int)nx ny:(int)ny offsetx:(float)offsetx offsety:(float)offsety uvMap:(Isgl3dUVMap *)uvMap;

@end
29 changes: 21 additions & 8 deletions isgl3d/primitives/Isgl3dPlane.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,38 @@ + (id)meshWithGeometry:(float)width height:(float)height nx:(int)nx ny:(int)ny {
return [[[self alloc] initWithGeometry:width height:height nx:nx ny:ny] autorelease];
}

+ (id)meshWithGeometry:(float)width height:(float)height nx:(int)nx ny:(int)ny offsetx:(float)offsetx offsety:(float)offsety {
return [[[self alloc] initWithGeometry:width height:height nx:nx ny:ny offsetx:offsetx offsety:offsety] autorelease];
}

+ (id)meshWithGeometryAndUVMap:(float)width height:(float)height nx:(int)nx ny:(int)ny uvMap:(Isgl3dUVMap *)uvMap {
return [[[self alloc] initWithGeometryAndUVMap:width height:height nx:nx ny:ny uvMap:uvMap] autorelease];
}

+ (id)meshWithGeometryAndUVMap:(float)width height:(float)height nx:(int)nx ny:(int)ny offsetx:(float)offsetx offsety:(float)offsety uvMap:(Isgl3dUVMap *)uvMap {
return [[[self alloc] initWithGeometryAndUVMap:width height:height nx:nx ny:ny offsetx:offsetx offsety:offsety uvMap:uvMap] autorelease];
}

- (id)initWithGeometry:(float)width height:(float)height nx:(int)nx ny:(int)ny {

if (self = [self initWithGeometryAndUVMap:width height:height nx:nx ny:ny uvMap:nil]) {
// Empty.
}

return self;
return [self initWithGeometryAndUVMap:width height:height nx:nx ny:ny offsetx:0.0 offsety:0.0 uvMap:nil];
}

- (id)initWithGeometry:(float)width height:(float)height nx:(int)nx ny:(int)ny offsetx:(float)offsetx offsety:(float)offsety {
return [self initWithGeometryAndUVMap:width height:height nx:nx ny:ny offsetx:offsetx offsety:offsety uvMap:nil];
}

- (id)initWithGeometryAndUVMap:(float)width height:(float)height nx:(int)nx ny:(int)ny uvMap:(Isgl3dUVMap *)uvMap {
return [self initWithGeometryAndUVMap:width height:height nx:nx ny:ny offsetx:0.0 offsety:0.0 uvMap:uvMap];
}

- (id)initWithGeometryAndUVMap:(float)width height:(float)height nx:(int)nx ny:(int)ny offsetx:(float)offsetx offsety:(float)offsety uvMap:(Isgl3dUVMap *)uvMap {
if (self = [super init]) {
_width = width;
_height = height;
_nx = nx;
_ny = ny;
_offsetx = offsetx;
_offsety = offsety;

if (uvMap) {
_uvMap = [uvMap retain];
Expand Down Expand Up @@ -94,13 +107,13 @@ - (void)fillVertexData:(Isgl3dFloatArray *)vertexData andIndices:(Isgl3dUShortAr
float uX, vX, uXY, vXY, iRatio, jRatio;

for (int i = 0; i <= _nx; i++) {
float x = -(_width / 2) + i * (_width / _nx);
float x = -(_width / 2) + i * (_width / _nx) + _offsetx;
iRatio = (float)i / _nx;
uX = _uvMap.uA + iRatio * uABVector;
vX = _uvMap.vA + iRatio * vABVector;

for (int j = 0; j <= _ny; j++) {
float y = -(_height / 2) + j * (_height / _ny);
float y = -(_height / 2) + j * (_height / _ny) + _offsety;
jRatio = 1. - (float)j / _ny;
uXY = uX + jRatio * uACVector;
vXY = vX + jRatio * vACVector;
Expand Down
10 changes: 7 additions & 3 deletions isgl3d/primitives/Isgl3dPrimitiveFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ - (Isgl3dGLMesh *) boneMesh {
- (Isgl3dGLMesh *) UIButtonMesh {
Isgl3dGLMesh * buttonMesh = [_primitives objectForKey:GLUIBUTTON_MESH];
if (!buttonMesh) {
buttonMesh = [Isgl3dPlane meshWithGeometry:GLUIBUTTON_WIDTH * [Isgl3dDirector sharedInstance].contentScaleFactor height:GLUIBUTTON_HEIGHT * [Isgl3dDirector sharedInstance].contentScaleFactor nx:2 ny:2];
float width = GLUIBUTTON_WIDTH * [Isgl3dDirector sharedInstance].contentScaleFactor;
float height = GLUIBUTTON_HEIGHT * [Isgl3dDirector sharedInstance].contentScaleFactor;
// UI components have the bottom-left corner at (width, height), so offset the plane by (width/2, height/2).
buttonMesh = [Isgl3dPlane meshWithGeometry:width height:height nx:2 ny:2 offsetx:width/2 offsety:height/2];
[_primitives setObject:buttonMesh forKey:GLUIBUTTON_MESH];
}
return buttonMesh;
Expand All @@ -98,7 +101,8 @@ - (Isgl3dGLMesh *) UILabelMeshWithWidth:(unsigned int)width height:(unsigned int
float uMax = contentSize.width / width;
float vMax = contentSize.height / height;

Isgl3dGLMesh * labelMesh = [Isgl3dPlane meshWithGeometryAndUVMap:contentSize.width height:contentSize.height nx:2 ny:2 uvMap:[Isgl3dUVMap uvMapWithUA:0 vA:0 uB:uMax vB:0 uC:0 vC:vMax]];
// UI components have the bottom-left corner at (width, height), so offset the plane by (width/2, height/2).
Isgl3dGLMesh * labelMesh = [Isgl3dPlane meshWithGeometryAndUVMap:contentSize.width height:contentSize.height nx:2 ny:2 offsetx:(float)contentSize.width/2 offsety:(float)contentSize.height/2 uvMap:[Isgl3dUVMap uvMapWithUA:0 vA:0 uB:uMax vB:0 uC:0 vC:vMax]];
// GLMesh * labelMesh = [[Plane alloc] initWithGeometryAndUVMap:width height:height nx:2 ny:2 uvMap:[UVMap uvMapWithUA:0 vA:0 uB:0.5 vB:0 uC:0 vC:0.5]];
return labelMesh;
}
Expand All @@ -107,7 +111,7 @@ - (Isgl3dPlane *) planeWithGeometry:(float)width height:(float)height nx:(int)nx
float uMax = material.contentSize.width / material.width;
float vMax = material.contentSize.height / material.height;

Isgl3dPlane * plane = [Isgl3dPlane meshWithGeometryAndUVMap:width height:height nx:nx ny:ny uvMap:[Isgl3dUVMap uvMapWithUA:0 vA:0 uB:uMax vB:0 uC:0 vC:vMax]];
Isgl3dPlane * plane = [Isgl3dPlane meshWithGeometryAndUVMap:width height:height nx:nx ny:ny offsetx:width/2 offsety:height/2 uvMap:[Isgl3dUVMap uvMapWithUA:0 vA:0 uB:uMax vB:0 uC:0 vC:vMax]];
return plane;
}

Expand Down
5 changes: 4 additions & 1 deletion isgl3d/ui/Isgl3dGLUIButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ - (id)initWithMaterial:(Isgl3dMaterial *)material {
- (id)initWithMaterial:(Isgl3dMaterial *)material width:(unsigned int)width height:(unsigned int)height {

float contentScaleFactor = [Isgl3dDirector sharedInstance].contentScaleFactor;
// UI components have the bottom-left corner at (width, height), so offset the plane by (width/2, height/2).
if ((self = [super initWithMesh:[Isgl3dPlane meshWithGeometry:width * contentScaleFactor
height:height * contentScaleFactor
nx:2
ny:2]
ny:2
offsetx:(float)width * contentScaleFactor / 2
offsety:(float)height * contentScaleFactor / 2]
andMaterial:material])) {
[self setWidth:width andHeight:height];
self.interactive = YES;
Expand Down
30 changes: 0 additions & 30 deletions isgl3d/ui/Isgl3dGLUIComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@
unsigned int _heightInPixels;

BOOL _meshDirty;

// "Fix left & top" stop pixel movement of component on specified side when resizing
BOOL _fixLeft;
BOOL _fixTop;

BOOL _centerX;
BOOL _centerY;
}

/**
Expand Down Expand Up @@ -103,29 +96,6 @@
*/
@property (nonatomic, readonly) unsigned int heightInPixels;

/**
* Fix left is used to correct undesirable behaviour when the component it resized (such as with an Isgl3dProgressBar). With
* fixLeft the left hand side of the component will not move.
*/
@property (nonatomic) BOOL fixLeft;

/**
* Fix top is used to correct undesirable behaviour when the component it resized (such as with an Isgl3dProgressBar). With
* fixTop the top of the component will not move.
*/
@property (nonatomic) BOOL fixTop;

/**
* Specifies whether the component should be centered horizontally on its x value.
*/
@property (nonatomic) BOOL centerX;

/**
* Specifies whether the component should be centered vertically on its y value.
*/
@property (nonatomic) BOOL centerY;


/**
* Initialises the component with a mesh and material.
* This is called automatically by the concrete Isgl3DGLUI components.
Expand Down
31 changes: 2 additions & 29 deletions isgl3d/ui/Isgl3dGLUIComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ @implementation Isgl3dGLUIComponent
@synthesize widthInPixels = _widthInPixels;
@synthesize height = _height;
@synthesize heightInPixels = _heightInPixels;
@synthesize fixLeft = _fixLeft;
@synthesize fixTop = _fixTop;
@synthesize centerX = _centerX;
@synthesize centerY = _centerY;

- (id)initWithMesh:(Isgl3dGLMesh *)mesh andMaterial:(Isgl3dMaterial *)material {
if ((self = [super initWithMesh:mesh andMaterial:material])) {
Expand All @@ -56,10 +52,6 @@ - (id)initWithMesh:(Isgl3dGLMesh *)mesh andMaterial:(Isgl3dMaterial *)material {
_heightInPixels = 0;
_meshDirty = YES;

_fixLeft = YES;
_fixTop = YES;
_centerX = NO;
_centerY = NO;
self.lightingEnabled = NO;
}
return self;
Expand Down Expand Up @@ -105,27 +97,8 @@ - (void)setWidthInPixels:(unsigned int)width andHeightInPixels:(unsigned int)hei

- (void)updateWorldTransformation:(Isgl3dMatrix4 *)parentTransformation {
if (_meshDirty) {
float x;
float y;
if (_centerX) {
x = 1.0 * _xInPixels;
} else {
if (_fixLeft) {
x = _xInPixels + (_widthInPixels + 1)/ 2;
} else {
x = _xInPixels + _widthInPixels / 2;
}
}

if (_centerY) {
y = _yInPixels;
} else {
if (_fixTop) {
y = (float)(_yInPixels + (_heightInPixels + 1) / 2);
} else {
y = (float)(_yInPixels + _heightInPixels / 2);
}
}
unsigned int x = _xInPixels;
unsigned int y = _yInPixels;

[self setPositionValues:x y:y z:self.z];
// NSLog(@"setting x = %f y = %f z = %f", x, y, self.z);
Expand Down
11 changes: 7 additions & 4 deletions isgl3d/ui/Isgl3dGLUIImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ + (id)imageWithMaterial:(Isgl3dMaterial *)material andRectangle:(CGRect)rectangl
- (id)initWithMaterial:(Isgl3dMaterial *)material width:(unsigned int)width height:(unsigned int)height {

float widthInPixels = width * [Isgl3dDirector sharedInstance].contentScaleFactor;
float heightInPixels = height * [Isgl3dDirector sharedInstance].contentScaleFactor;
if ((self = [super initWithMesh:[Isgl3dPlane meshWithGeometry:widthInPixels height:heightInPixels nx:2 ny:2] andMaterial:material])) {
float heightInPixels = height * [Isgl3dDirector sharedInstance].contentScaleFactor;
// UI components have the bottom-left corner at (width, height), so offset the plane by (width/2, height/2).
if ((self = [super initWithMesh:[Isgl3dPlane meshWithGeometry:widthInPixels height:heightInPixels nx:2 ny:2 offsetx:widthInPixels/2 offsety:heightInPixels/2] andMaterial:material])) {
[self setWidth:width andHeight:height];
}

Expand Down Expand Up @@ -75,8 +76,10 @@ - (id)initWithMaterial:(Isgl3dMaterial *)material andRectangle:(CGRect)rectangle
float vc = va + size.height * scaleFactor / materialHeight;

float widthInPixels = width * [Isgl3dDirector sharedInstance].contentScaleFactor;
float heightInPixels = height * [Isgl3dDirector sharedInstance].contentScaleFactor;
if ((self = [super initWithMesh:[Isgl3dPlane meshWithGeometryAndUVMap:widthInPixels height:heightInPixels nx:2 ny:2 uvMap:[Isgl3dUVMap uvMapWithUA:ua vA:va uB:ub vB:vb uC:uc vC:vc]] andMaterial:material])) {
float heightInPixels = height * [Isgl3dDirector sharedInstance].contentScaleFactor;

// UI components have the bottom-left corner at (width, height), so offset the plane by (width/2, height/2).
if ((self = [super initWithMesh:[Isgl3dPlane meshWithGeometryAndUVMap:widthInPixels height:heightInPixels nx:2 ny:2 offsetx:widthInPixels/2 offsety:heightInPixels/2 uvMap:[Isgl3dUVMap uvMapWithUA:ua vA:va uB:ub vB:vb uC:uc vC:vc]] andMaterial:material])) {
[self setWidth:width andHeight:height];
}

Expand Down
Loading