mirror of
https://github.com/thes3m/XNI
synced 2024-12-26 13:26:06 +01:00
Added user primitive rendering.
git-svn-id: http://xni.googlecode.com/svn/XNI@23 ac433895-eea3-a490-d80a-17149a75e588
This commit is contained in:
parent
b2ff169596
commit
668bba9869
@ -14,16 +14,16 @@
|
||||
uint packedValue;
|
||||
}
|
||||
|
||||
- (id) initWithRed:(int)red Green:(int)green Blue:(int)blue Alpha:(int)alpha;
|
||||
- (id) initWithRed:(int)red Green:(int)green Blue:(int)blue;
|
||||
- (id) initWithPercentageRed:(float)red Green:(float)green Blue:(float)blue Alpha:(float)alpha;
|
||||
- (id) initWithPercentageRed:(float)red Green:(float)green Blue:(float)blue;
|
||||
- (id) initWithRed:(int)red green:(int)green blue:(int)blue alpha:(int)alpha;
|
||||
- (id) initWithRed:(int)red green:(int)green blue:(int)blue;
|
||||
- (id) initWithPercentageRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha;
|
||||
- (id) initWithPercentageRed:(float)red green:(float)green blue:(float)blue;
|
||||
- (id) initWithColor:(Color*)color;
|
||||
|
||||
+ (Color*) colorWithRed:(int)red Green:(int)green Blue:(int)blue Alpha:(int)alpha;
|
||||
+ (Color*) colorWithRed:(int)red Green:(int)green Blue:(int)blue;
|
||||
+ (Color*) colorWithPercentageRed:(float)red Green:(float)green Blue:(float)blue Alpha:(float)alpha;
|
||||
+ (Color*) colorWithPercentageRed:(float)red Green:(float)green Blue:(float)blue;
|
||||
+ (Color*) colorWithRed:(int)red green:(int)green blue:(int)blue alpha:(int)alpha;
|
||||
+ (Color*) colorWithRed:(int)red green:(int)green blue:(int)blue;
|
||||
+ (Color*) colorWithPercentageRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha;
|
||||
+ (Color*) colorWithPercentageRed:(float)red green:(float)green blue:(float)blue;
|
||||
+ (Color*) colorWithColor:(Color*)color;
|
||||
|
||||
@property (nonatomic) Byte r;
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
// CONSTRUCTORS
|
||||
|
||||
- (id) initWithRed:(int)red Green:(int)green Blue:(int)blue Alpha:(int)alpha {
|
||||
- (id) initWithRed:(int)red green:(int)green blue:(int)blue alpha:(int)alpha {
|
||||
if (self = [super init]) {
|
||||
red = CLAMP_TO_BYTE(red);
|
||||
green = CLAMP_TO_BYTE(green) << 8;
|
||||
@ -26,36 +26,36 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithRed:(int)red Green:(int)green Blue:(int)blue {
|
||||
return [self initWithRed:red Green:green Blue:blue Alpha:255];
|
||||
- (id) initWithRed:(int)red green:(int)green blue:(int)blue {
|
||||
return [self initWithRed:red green:green blue:blue alpha:255];
|
||||
}
|
||||
|
||||
- (id) initWithPercentageRed:(float)red Green:(float)green Blue:(float)blue Alpha:(float)alpha {
|
||||
return [self initWithRed:255 * red Green:255 * green Blue:255 * blue Alpha:255 * alpha];
|
||||
- (id) initWithPercentageRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha {
|
||||
return [self initWithRed:255 * red green:255 * green blue:255 * blue alpha:255 * alpha];
|
||||
}
|
||||
|
||||
- (id) initWithPercentageRed:(float)red Green:(float)green Blue:(float)blue {
|
||||
return [self initWithPercentageRed:red Green:green Blue:blue Alpha:1];
|
||||
- (id) initWithPercentageRed:(float)red green:(float)green blue:(float)blue {
|
||||
return [self initWithPercentageRed:red green:green blue:blue alpha:1];
|
||||
}
|
||||
|
||||
- (id) initWithColor:(Color*)color {
|
||||
return [self initWithRed:color.r Green:color.g Blue:color.b Alpha:color.a];
|
||||
return [self initWithRed:color.r green:color.g blue:color.b alpha:color.a];
|
||||
}
|
||||
|
||||
+ (Color*) colorWithRed:(int)red Green:(int)green Blue:(int)blue Alpha:(int)alpha {
|
||||
return [[[Color alloc] initWithRed:red Green:green Blue:blue Alpha:alpha] autorelease];
|
||||
+ (Color*) colorWithRed:(int)red green:(int)green blue:(int)blue alpha:(int)alpha {
|
||||
return [[[Color alloc] initWithRed:red green:green blue:blue alpha:alpha] autorelease];
|
||||
}
|
||||
|
||||
+ (Color*) colorWithRed:(int)red Green:(int)green Blue:(int)blue {
|
||||
return [[[Color alloc] initWithRed:red Green:green Blue:blue] autorelease];
|
||||
+ (Color*) colorWithRed:(int)red green:(int)green blue:(int)blue {
|
||||
return [[[Color alloc] initWithRed:red green:green blue:blue] autorelease];
|
||||
}
|
||||
|
||||
+ (Color*) colorWithPercentageRed:(float)red Green:(float)green Blue:(float)blue Alpha:(float)alpha {
|
||||
return [[[Color alloc] initWithPercentageRed:red Green:green Blue:blue Alpha:alpha] autorelease];
|
||||
+ (Color*) colorWithPercentageRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha {
|
||||
return [[[Color alloc] initWithPercentageRed:red green:green blue:blue alpha:alpha] autorelease];
|
||||
}
|
||||
|
||||
+ (Color*) colorWithPercentageRed:(float)red Green:(float)green Blue:(float)blue {
|
||||
return [[[Color alloc] initWithPercentageRed:red Green:green Blue:blue] autorelease];
|
||||
+ (Color*) colorWithPercentageRed:(float)red green:(float)green blue:(float)blue {
|
||||
return [[[Color alloc] initWithPercentageRed:red green:green blue:blue] autorelease];
|
||||
}
|
||||
|
||||
+ (Color*) colorWithColor:(Color *)color {
|
||||
@ -86,146 +86,146 @@
|
||||
|
||||
|
||||
// Constants
|
||||
+ (Color*) aliceBlue {return [Color colorWithRed:240 Green:248 Blue:255 Alpha:255];}
|
||||
+ (Color*) antiqueWhite {return [Color colorWithRed:250 Green:235 Blue:215 Alpha:255];}
|
||||
+ (Color*) aqua {return [Color colorWithRed:0 Green:255 Blue:255 Alpha:255];}
|
||||
+ (Color*) aquamarine {return [Color colorWithRed:127 Green:255 Blue:212 Alpha:255];}
|
||||
+ (Color*) azure {return [Color colorWithRed:240 Green:255 Blue:255 Alpha:255];}
|
||||
+ (Color*) beige {return [Color colorWithRed:245 Green:245 Blue:220 Alpha:255];}
|
||||
+ (Color*) bisque {return [Color colorWithRed:255 Green:228 Blue:196 Alpha:255];}
|
||||
+ (Color*) black {return [Color colorWithRed:0 Green:0 Blue:0 Alpha:255];}
|
||||
+ (Color*) blanchedAlmond {return [Color colorWithRed:255 Green:235 Blue:205 Alpha:255];}
|
||||
+ (Color*) blue {return [Color colorWithRed:0 Green:0 Blue:255 Alpha:255];}
|
||||
+ (Color*) blueViolet {return [Color colorWithRed:138 Green:43 Blue:226 Alpha:255];}
|
||||
+ (Color*) brown {return [Color colorWithRed:165 Green:42 Blue:42 Alpha:255];}
|
||||
+ (Color*) burlyWood {return [Color colorWithRed:222 Green:184 Blue:135 Alpha:255];}
|
||||
+ (Color*) cadetBlue {return [Color colorWithRed:95 Green:158 Blue:160 Alpha:255];}
|
||||
+ (Color*) chartreuse {return [Color colorWithRed:127 Green:255 Blue:0 Alpha:255];}
|
||||
+ (Color*) chocolate {return [Color colorWithRed:210 Green:105 Blue:30 Alpha:255];}
|
||||
+ (Color*) coral {return [Color colorWithRed:255 Green:127 Blue:80 Alpha:255];}
|
||||
+ (Color*) cornflowerBlue {return [Color colorWithRed:100 Green:149 Blue:237 Alpha:255];}
|
||||
+ (Color*) cornsilk {return [Color colorWithRed:255 Green:248 Blue:220 Alpha:255];}
|
||||
+ (Color*) crimson {return [Color colorWithRed:220 Green:20 Blue:60 Alpha:255];}
|
||||
+ (Color*) cyan {return [Color colorWithRed:0 Green:255 Blue:255 Alpha:255];}
|
||||
+ (Color*) darkBlue {return [Color colorWithRed:0 Green:0 Blue:139 Alpha:255];}
|
||||
+ (Color*) darkCyan {return [Color colorWithRed:0 Green:139 Blue:139 Alpha:255];}
|
||||
+ (Color*) darkGoldenrod {return [Color colorWithRed:184 Green:134 Blue:11 Alpha:255];}
|
||||
+ (Color*) darkGray {return [Color colorWithRed:169 Green:169 Blue:169 Alpha:255];}
|
||||
+ (Color*) darkGreen {return [Color colorWithRed:0 Green:100 Blue:0 Alpha:255];}
|
||||
+ (Color*) darkKhaki {return [Color colorWithRed:189 Green:183 Blue:107 Alpha:255];}
|
||||
+ (Color*) darkMagenta {return [Color colorWithRed:139 Green:0 Blue:139 Alpha:255];}
|
||||
+ (Color*) darkOliveGreen {return [Color colorWithRed:85 Green:107 Blue:47 Alpha:255];}
|
||||
+ (Color*) darkOrange {return [Color colorWithRed:255 Green:140 Blue:0 Alpha:255];}
|
||||
+ (Color*) darkOrchid {return [Color colorWithRed:153 Green:50 Blue:204 Alpha:255];}
|
||||
+ (Color*) darkRed {return [Color colorWithRed:139 Green:0 Blue:0 Alpha:255];}
|
||||
+ (Color*) darkSalmon {return [Color colorWithRed:233 Green:150 Blue:122 Alpha:255];}
|
||||
+ (Color*) darkSeaGreen {return [Color colorWithRed:143 Green:188 Blue:139 Alpha:255];}
|
||||
+ (Color*) darkSlateBlue {return [Color colorWithRed:72 Green:61 Blue:139 Alpha:255];}
|
||||
+ (Color*) darkSlateGray {return [Color colorWithRed:47 Green:79 Blue:79 Alpha:255];}
|
||||
+ (Color*) darkTurquoise {return [Color colorWithRed:0 Green:206 Blue:209 Alpha:255];}
|
||||
+ (Color*) darkViolet {return [Color colorWithRed:148 Green:0 Blue:211 Alpha:255];}
|
||||
+ (Color*) deepPink {return [Color colorWithRed:255 Green:20 Blue:147 Alpha:255];}
|
||||
+ (Color*) deepSkyBlue {return [Color colorWithRed:0 Green:191 Blue:255 Alpha:255];}
|
||||
+ (Color*) dimGray {return [Color colorWithRed:105 Green:105 Blue:105 Alpha:255];}
|
||||
+ (Color*) dodgerBlue {return [Color colorWithRed:30 Green:144 Blue:255 Alpha:255];}
|
||||
+ (Color*) firebrick {return [Color colorWithRed:178 Green:34 Blue:34 Alpha:255];}
|
||||
+ (Color*) floralWhite {return [Color colorWithRed:255 Green:250 Blue:240 Alpha:255];}
|
||||
+ (Color*) forestGreen {return [Color colorWithRed:34 Green:139 Blue:34 Alpha:255];}
|
||||
+ (Color*) fuchsia {return [Color colorWithRed:255 Green:0 Blue:255 Alpha:255];}
|
||||
+ (Color*) gainsboro {return [Color colorWithRed:220 Green:220 Blue:220 Alpha:255];}
|
||||
+ (Color*) ghostWhite {return [Color colorWithRed:248 Green:248 Blue:255 Alpha:255];}
|
||||
+ (Color*) gold {return [Color colorWithRed:255 Green:215 Blue:0 Alpha:255];}
|
||||
+ (Color*) goldenrod {return [Color colorWithRed:218 Green:165 Blue:32 Alpha:255];}
|
||||
+ (Color*) gray {return [Color colorWithRed:128 Green:128 Blue:128 Alpha:255];}
|
||||
+ (Color*) green {return [Color colorWithRed:0 Green:128 Blue:0 Alpha:255];}
|
||||
+ (Color*) greenYellow {return [Color colorWithRed:173 Green:255 Blue:47 Alpha:255];}
|
||||
+ (Color*) honeydew {return [Color colorWithRed:240 Green:255 Blue:240 Alpha:255];}
|
||||
+ (Color*) hotPink {return [Color colorWithRed:255 Green:105 Blue:180 Alpha:255];}
|
||||
+ (Color*) indianRed {return [Color colorWithRed:205 Green:92 Blue:92 Alpha:255];}
|
||||
+ (Color*) indigo {return [Color colorWithRed:75 Green:0 Blue:130 Alpha:255];}
|
||||
+ (Color*) ivory {return [Color colorWithRed:255 Green:255 Blue:240 Alpha:255];}
|
||||
+ (Color*) khaki {return [Color colorWithRed:240 Green:230 Blue:140 Alpha:255];}
|
||||
+ (Color*) lavender {return [Color colorWithRed:230 Green:230 Blue:250 Alpha:255];}
|
||||
+ (Color*) lavenderBlush {return [Color colorWithRed:255 Green:240 Blue:245 Alpha:255];}
|
||||
+ (Color*) lawnGreen {return [Color colorWithRed:124 Green:252 Blue:0 Alpha:255];}
|
||||
+ (Color*) lemonChiffon {return [Color colorWithRed:255 Green:250 Blue:205 Alpha:255];}
|
||||
+ (Color*) lightBlue {return [Color colorWithRed:173 Green:216 Blue:230 Alpha:255];}
|
||||
+ (Color*) lightCoral {return [Color colorWithRed:240 Green:128 Blue:128 Alpha:255];}
|
||||
+ (Color*) lightCyan {return [Color colorWithRed:224 Green:255 Blue:255 Alpha:255];}
|
||||
+ (Color*) lightGoldenrodYellow {return [Color colorWithRed:250 Green:250 Blue:210 Alpha:255];}
|
||||
+ (Color*) lightGray {return [Color colorWithRed:211 Green:211 Blue:211 Alpha:255];}
|
||||
+ (Color*) lightGreen {return [Color colorWithRed:144 Green:238 Blue:144 Alpha:255];}
|
||||
+ (Color*) lightPink {return [Color colorWithRed:255 Green:182 Blue:193 Alpha:255];}
|
||||
+ (Color*) lightSalmon {return [Color colorWithRed:255 Green:160 Blue:122 Alpha:255];}
|
||||
+ (Color*) lightSeaGreen {return [Color colorWithRed:32 Green:178 Blue:170 Alpha:255];}
|
||||
+ (Color*) lightSkyBlue {return [Color colorWithRed:135 Green:206 Blue:250 Alpha:255];}
|
||||
+ (Color*) lightSlateGray {return [Color colorWithRed:119 Green:136 Blue:153 Alpha:255];}
|
||||
+ (Color*) lightSteelBlue {return [Color colorWithRed:176 Green:196 Blue:222 Alpha:255];}
|
||||
+ (Color*) lightYellow {return [Color colorWithRed:255 Green:255 Blue:224 Alpha:255];}
|
||||
+ (Color*) lime {return [Color colorWithRed:0 Green:255 Blue:0 Alpha:255];}
|
||||
+ (Color*) limeGreen {return [Color colorWithRed:50 Green:205 Blue:50 Alpha:255];}
|
||||
+ (Color*) linen {return [Color colorWithRed:250 Green:240 Blue:230 Alpha:255];}
|
||||
+ (Color*) magenta {return [Color colorWithRed:255 Green:0 Blue:255 Alpha:255];}
|
||||
+ (Color*) maroon {return [Color colorWithRed:128 Green:0 Blue:0 Alpha:255];}
|
||||
+ (Color*) mediumAquamarine {return [Color colorWithRed:102 Green:205 Blue:170 Alpha:255];}
|
||||
+ (Color*) mediumBlue {return [Color colorWithRed:0 Green:0 Blue:205 Alpha:255];}
|
||||
+ (Color*) mediumOrchid {return [Color colorWithRed:186 Green:85 Blue:211 Alpha:255];}
|
||||
+ (Color*) mediumPurple {return [Color colorWithRed:147 Green:112 Blue:219 Alpha:255];}
|
||||
+ (Color*) mediumSeaGreen {return [Color colorWithRed:60 Green:179 Blue:113 Alpha:255];}
|
||||
+ (Color*) mediumSlateBlue {return [Color colorWithRed:123 Green:104 Blue:238 Alpha:255];}
|
||||
+ (Color*) mediumSpringGreen {return [Color colorWithRed:0 Green:250 Blue:154 Alpha:255];}
|
||||
+ (Color*) mediumTurquoise {return [Color colorWithRed:72 Green:209 Blue:204 Alpha:255];}
|
||||
+ (Color*) mediumVioletRed {return [Color colorWithRed:199 Green:21 Blue:133 Alpha:255];}
|
||||
+ (Color*) midnightBlue {return [Color colorWithRed:25 Green:25 Blue:112 Alpha:255];}
|
||||
+ (Color*) mintCream {return [Color colorWithRed:245 Green:255 Blue:250 Alpha:255];}
|
||||
+ (Color*) mistyRose {return [Color colorWithRed:255 Green:228 Blue:225 Alpha:255];}
|
||||
+ (Color*) moccasin {return [Color colorWithRed:255 Green:228 Blue:181 Alpha:255];}
|
||||
+ (Color*) navajoWhite {return [Color colorWithRed:255 Green:222 Blue:173 Alpha:255];}
|
||||
+ (Color*) navy {return [Color colorWithRed:0 Green:0 Blue:128 Alpha:255];}
|
||||
+ (Color*) oldLace {return [Color colorWithRed:253 Green:245 Blue:230 Alpha:255];}
|
||||
+ (Color*) olive {return [Color colorWithRed:128 Green:128 Blue:0 Alpha:255];}
|
||||
+ (Color*) oliveDrab {return [Color colorWithRed:107 Green:142 Blue:35 Alpha:255];}
|
||||
+ (Color*) orange {return [Color colorWithRed:255 Green:165 Blue:0 Alpha:255];}
|
||||
+ (Color*) orangeRed {return [Color colorWithRed:255 Green:69 Blue:0 Alpha:255];}
|
||||
+ (Color*) orchid {return [Color colorWithRed:218 Green:112 Blue:214 Alpha:255];}
|
||||
+ (Color*) paleGoldenrod {return [Color colorWithRed:238 Green:232 Blue:170 Alpha:255];}
|
||||
+ (Color*) paleGreen {return [Color colorWithRed:152 Green:251 Blue:152 Alpha:255];}
|
||||
+ (Color*) paleTurquoise {return [Color colorWithRed:175 Green:238 Blue:238 Alpha:255];}
|
||||
+ (Color*) paleVioletRed {return [Color colorWithRed:219 Green:112 Blue:147 Alpha:255];}
|
||||
+ (Color*) papayaWhip {return [Color colorWithRed:255 Green:239 Blue:213 Alpha:255];}
|
||||
+ (Color*) peachPuff {return [Color colorWithRed:255 Green:218 Blue:185 Alpha:255];}
|
||||
+ (Color*) peru {return [Color colorWithRed:205 Green:133 Blue:63 Alpha:255];}
|
||||
+ (Color*) pink {return [Color colorWithRed:255 Green:192 Blue:203 Alpha:255];}
|
||||
+ (Color*) plum {return [Color colorWithRed:221 Green:160 Blue:221 Alpha:255];}
|
||||
+ (Color*) powderBlue {return [Color colorWithRed:176 Green:224 Blue:230 Alpha:255];}
|
||||
+ (Color*) purple {return [Color colorWithRed:128 Green:0 Blue:128 Alpha:255];}
|
||||
+ (Color*) red {return [Color colorWithRed:255 Green:0 Blue:0 Alpha:255];}
|
||||
+ (Color*) rosyBrown {return [Color colorWithRed:188 Green:143 Blue:143 Alpha:255];}
|
||||
+ (Color*) royalBlue {return [Color colorWithRed:65 Green:105 Blue:225 Alpha:255];}
|
||||
+ (Color*) saddleBrown {return [Color colorWithRed:139 Green:69 Blue:19 Alpha:255];}
|
||||
+ (Color*) salmon {return [Color colorWithRed:250 Green:128 Blue:114 Alpha:255];}
|
||||
+ (Color*) sandyBrown {return [Color colorWithRed:244 Green:164 Blue:96 Alpha:255];}
|
||||
+ (Color*) seaGreen {return [Color colorWithRed:46 Green:139 Blue:87 Alpha:255];}
|
||||
+ (Color*) seaShell {return [Color colorWithRed:255 Green:245 Blue:238 Alpha:255];}
|
||||
+ (Color*) sienna {return [Color colorWithRed:160 Green:82 Blue:45 Alpha:255];}
|
||||
+ (Color*) silver {return [Color colorWithRed:192 Green:192 Blue:192 Alpha:255];}
|
||||
+ (Color*) skyBlue {return [Color colorWithRed:135 Green:206 Blue:235 Alpha:255];}
|
||||
+ (Color*) slateBlue {return [Color colorWithRed:106 Green:90 Blue:205 Alpha:255];}
|
||||
+ (Color*) slateGray {return [Color colorWithRed:112 Green:128 Blue:144 Alpha:255];}
|
||||
+ (Color*) snow {return [Color colorWithRed:255 Green:250 Blue:250 Alpha:255];}
|
||||
+ (Color*) springGreen {return [Color colorWithRed:0 Green:255 Blue:127 Alpha:255];}
|
||||
+ (Color*) steelBlue {return [Color colorWithRed:70 Green:130 Blue:180 Alpha:255];}
|
||||
+ (Color*) tan {return [Color colorWithRed:210 Green:180 Blue:140 Alpha:255];}
|
||||
+ (Color*) teal {return [Color colorWithRed:0 Green:128 Blue:128 Alpha:255];}
|
||||
+ (Color*) thistle {return [Color colorWithRed:216 Green:191 Blue:216 Alpha:255];}
|
||||
+ (Color*) tomato {return [Color colorWithRed:255 Green:99 Blue:71 Alpha:255];}
|
||||
+ (Color*) transparent {return [Color colorWithRed:0 Green:0 Blue:0 Alpha:0];}
|
||||
+ (Color*) turquoise {return [Color colorWithRed:64 Green:224 Blue:208 Alpha:255];}
|
||||
+ (Color*) violet {return [Color colorWithRed:238 Green:130 Blue:238 Alpha:255];}
|
||||
+ (Color*) wheat {return [Color colorWithRed:245 Green:222 Blue:179 Alpha:255];}
|
||||
+ (Color*) white {return [Color colorWithRed:255 Green:255 Blue:255 Alpha:255];}
|
||||
+ (Color*) whiteSmoke {return [Color colorWithRed:245 Green:245 Blue:245 Alpha:255];}
|
||||
+ (Color*) yellow {return [Color colorWithRed:255 Green:255 Blue:0 Alpha:255];}
|
||||
+ (Color*) yellowGreen {return [Color colorWithRed:154 Green:205 Blue:50 Alpha:255];}
|
||||
+ (Color*) aliceBlue {return [Color colorWithRed:240 green:248 blue:255 alpha:255];}
|
||||
+ (Color*) antiqueWhite {return [Color colorWithRed:250 green:235 blue:215 alpha:255];}
|
||||
+ (Color*) aqua {return [Color colorWithRed:0 green:255 blue:255 alpha:255];}
|
||||
+ (Color*) aquamarine {return [Color colorWithRed:127 green:255 blue:212 alpha:255];}
|
||||
+ (Color*) azure {return [Color colorWithRed:240 green:255 blue:255 alpha:255];}
|
||||
+ (Color*) beige {return [Color colorWithRed:245 green:245 blue:220 alpha:255];}
|
||||
+ (Color*) bisque {return [Color colorWithRed:255 green:228 blue:196 alpha:255];}
|
||||
+ (Color*) black {return [Color colorWithRed:0 green:0 blue:0 alpha:255];}
|
||||
+ (Color*) blanchedAlmond {return [Color colorWithRed:255 green:235 blue:205 alpha:255];}
|
||||
+ (Color*) blue {return [Color colorWithRed:0 green:0 blue:255 alpha:255];}
|
||||
+ (Color*) blueViolet {return [Color colorWithRed:138 green:43 blue:226 alpha:255];}
|
||||
+ (Color*) brown {return [Color colorWithRed:165 green:42 blue:42 alpha:255];}
|
||||
+ (Color*) burlyWood {return [Color colorWithRed:222 green:184 blue:135 alpha:255];}
|
||||
+ (Color*) cadetBlue {return [Color colorWithRed:95 green:158 blue:160 alpha:255];}
|
||||
+ (Color*) chartreuse {return [Color colorWithRed:127 green:255 blue:0 alpha:255];}
|
||||
+ (Color*) chocolate {return [Color colorWithRed:210 green:105 blue:30 alpha:255];}
|
||||
+ (Color*) coral {return [Color colorWithRed:255 green:127 blue:80 alpha:255];}
|
||||
+ (Color*) cornflowerBlue {return [Color colorWithRed:100 green:149 blue:237 alpha:255];}
|
||||
+ (Color*) cornsilk {return [Color colorWithRed:255 green:248 blue:220 alpha:255];}
|
||||
+ (Color*) crimson {return [Color colorWithRed:220 green:20 blue:60 alpha:255];}
|
||||
+ (Color*) cyan {return [Color colorWithRed:0 green:255 blue:255 alpha:255];}
|
||||
+ (Color*) darkBlue {return [Color colorWithRed:0 green:0 blue:139 alpha:255];}
|
||||
+ (Color*) darkCyan {return [Color colorWithRed:0 green:139 blue:139 alpha:255];}
|
||||
+ (Color*) darkGoldenrod {return [Color colorWithRed:184 green:134 blue:11 alpha:255];}
|
||||
+ (Color*) darkGray {return [Color colorWithRed:169 green:169 blue:169 alpha:255];}
|
||||
+ (Color*) darkGreen {return [Color colorWithRed:0 green:100 blue:0 alpha:255];}
|
||||
+ (Color*) darkKhaki {return [Color colorWithRed:189 green:183 blue:107 alpha:255];}
|
||||
+ (Color*) darkMagenta {return [Color colorWithRed:139 green:0 blue:139 alpha:255];}
|
||||
+ (Color*) darkOliveGreen {return [Color colorWithRed:85 green:107 blue:47 alpha:255];}
|
||||
+ (Color*) darkOrange {return [Color colorWithRed:255 green:140 blue:0 alpha:255];}
|
||||
+ (Color*) darkOrchid {return [Color colorWithRed:153 green:50 blue:204 alpha:255];}
|
||||
+ (Color*) darkRed {return [Color colorWithRed:139 green:0 blue:0 alpha:255];}
|
||||
+ (Color*) darkSalmon {return [Color colorWithRed:233 green:150 blue:122 alpha:255];}
|
||||
+ (Color*) darkSeaGreen {return [Color colorWithRed:143 green:188 blue:139 alpha:255];}
|
||||
+ (Color*) darkSlateBlue {return [Color colorWithRed:72 green:61 blue:139 alpha:255];}
|
||||
+ (Color*) darkSlateGray {return [Color colorWithRed:47 green:79 blue:79 alpha:255];}
|
||||
+ (Color*) darkTurquoise {return [Color colorWithRed:0 green:206 blue:209 alpha:255];}
|
||||
+ (Color*) darkViolet {return [Color colorWithRed:148 green:0 blue:211 alpha:255];}
|
||||
+ (Color*) deepPink {return [Color colorWithRed:255 green:20 blue:147 alpha:255];}
|
||||
+ (Color*) deepSkyBlue {return [Color colorWithRed:0 green:191 blue:255 alpha:255];}
|
||||
+ (Color*) dimGray {return [Color colorWithRed:105 green:105 blue:105 alpha:255];}
|
||||
+ (Color*) dodgerBlue {return [Color colorWithRed:30 green:144 blue:255 alpha:255];}
|
||||
+ (Color*) firebrick {return [Color colorWithRed:178 green:34 blue:34 alpha:255];}
|
||||
+ (Color*) floralWhite {return [Color colorWithRed:255 green:250 blue:240 alpha:255];}
|
||||
+ (Color*) forestGreen {return [Color colorWithRed:34 green:139 blue:34 alpha:255];}
|
||||
+ (Color*) fuchsia {return [Color colorWithRed:255 green:0 blue:255 alpha:255];}
|
||||
+ (Color*) gainsboro {return [Color colorWithRed:220 green:220 blue:220 alpha:255];}
|
||||
+ (Color*) ghostWhite {return [Color colorWithRed:248 green:248 blue:255 alpha:255];}
|
||||
+ (Color*) gold {return [Color colorWithRed:255 green:215 blue:0 alpha:255];}
|
||||
+ (Color*) goldenrod {return [Color colorWithRed:218 green:165 blue:32 alpha:255];}
|
||||
+ (Color*) gray {return [Color colorWithRed:128 green:128 blue:128 alpha:255];}
|
||||
+ (Color*) green {return [Color colorWithRed:0 green:128 blue:0 alpha:255];}
|
||||
+ (Color*) greenYellow {return [Color colorWithRed:173 green:255 blue:47 alpha:255];}
|
||||
+ (Color*) honeydew {return [Color colorWithRed:240 green:255 blue:240 alpha:255];}
|
||||
+ (Color*) hotPink {return [Color colorWithRed:255 green:105 blue:180 alpha:255];}
|
||||
+ (Color*) indianRed {return [Color colorWithRed:205 green:92 blue:92 alpha:255];}
|
||||
+ (Color*) indigo {return [Color colorWithRed:75 green:0 blue:130 alpha:255];}
|
||||
+ (Color*) ivory {return [Color colorWithRed:255 green:255 blue:240 alpha:255];}
|
||||
+ (Color*) khaki {return [Color colorWithRed:240 green:230 blue:140 alpha:255];}
|
||||
+ (Color*) lavender {return [Color colorWithRed:230 green:230 blue:250 alpha:255];}
|
||||
+ (Color*) lavenderBlush {return [Color colorWithRed:255 green:240 blue:245 alpha:255];}
|
||||
+ (Color*) lawnGreen {return [Color colorWithRed:124 green:252 blue:0 alpha:255];}
|
||||
+ (Color*) lemonChiffon {return [Color colorWithRed:255 green:250 blue:205 alpha:255];}
|
||||
+ (Color*) lightBlue {return [Color colorWithRed:173 green:216 blue:230 alpha:255];}
|
||||
+ (Color*) lightCoral {return [Color colorWithRed:240 green:128 blue:128 alpha:255];}
|
||||
+ (Color*) lightCyan {return [Color colorWithRed:224 green:255 blue:255 alpha:255];}
|
||||
+ (Color*) lightGoldenrodYellow {return [Color colorWithRed:250 green:250 blue:210 alpha:255];}
|
||||
+ (Color*) lightGray {return [Color colorWithRed:211 green:211 blue:211 alpha:255];}
|
||||
+ (Color*) lightGreen {return [Color colorWithRed:144 green:238 blue:144 alpha:255];}
|
||||
+ (Color*) lightPink {return [Color colorWithRed:255 green:182 blue:193 alpha:255];}
|
||||
+ (Color*) lightSalmon {return [Color colorWithRed:255 green:160 blue:122 alpha:255];}
|
||||
+ (Color*) lightSeaGreen {return [Color colorWithRed:32 green:178 blue:170 alpha:255];}
|
||||
+ (Color*) lightSkyBlue {return [Color colorWithRed:135 green:206 blue:250 alpha:255];}
|
||||
+ (Color*) lightSlateGray {return [Color colorWithRed:119 green:136 blue:153 alpha:255];}
|
||||
+ (Color*) lightSteelBlue {return [Color colorWithRed:176 green:196 blue:222 alpha:255];}
|
||||
+ (Color*) lightYellow {return [Color colorWithRed:255 green:255 blue:224 alpha:255];}
|
||||
+ (Color*) lime {return [Color colorWithRed:0 green:255 blue:0 alpha:255];}
|
||||
+ (Color*) limeGreen {return [Color colorWithRed:50 green:205 blue:50 alpha:255];}
|
||||
+ (Color*) linen {return [Color colorWithRed:250 green:240 blue:230 alpha:255];}
|
||||
+ (Color*) magenta {return [Color colorWithRed:255 green:0 blue:255 alpha:255];}
|
||||
+ (Color*) maroon {return [Color colorWithRed:128 green:0 blue:0 alpha:255];}
|
||||
+ (Color*) mediumAquamarine {return [Color colorWithRed:102 green:205 blue:170 alpha:255];}
|
||||
+ (Color*) mediumBlue {return [Color colorWithRed:0 green:0 blue:205 alpha:255];}
|
||||
+ (Color*) mediumOrchid {return [Color colorWithRed:186 green:85 blue:211 alpha:255];}
|
||||
+ (Color*) mediumPurple {return [Color colorWithRed:147 green:112 blue:219 alpha:255];}
|
||||
+ (Color*) mediumSeaGreen {return [Color colorWithRed:60 green:179 blue:113 alpha:255];}
|
||||
+ (Color*) mediumSlateBlue {return [Color colorWithRed:123 green:104 blue:238 alpha:255];}
|
||||
+ (Color*) mediumSpringGreen {return [Color colorWithRed:0 green:250 blue:154 alpha:255];}
|
||||
+ (Color*) mediumTurquoise {return [Color colorWithRed:72 green:209 blue:204 alpha:255];}
|
||||
+ (Color*) mediumVioletRed {return [Color colorWithRed:199 green:21 blue:133 alpha:255];}
|
||||
+ (Color*) midnightBlue {return [Color colorWithRed:25 green:25 blue:112 alpha:255];}
|
||||
+ (Color*) mintCream {return [Color colorWithRed:245 green:255 blue:250 alpha:255];}
|
||||
+ (Color*) mistyRose {return [Color colorWithRed:255 green:228 blue:225 alpha:255];}
|
||||
+ (Color*) moccasin {return [Color colorWithRed:255 green:228 blue:181 alpha:255];}
|
||||
+ (Color*) navajoWhite {return [Color colorWithRed:255 green:222 blue:173 alpha:255];}
|
||||
+ (Color*) navy {return [Color colorWithRed:0 green:0 blue:128 alpha:255];}
|
||||
+ (Color*) oldLace {return [Color colorWithRed:253 green:245 blue:230 alpha:255];}
|
||||
+ (Color*) olive {return [Color colorWithRed:128 green:128 blue:0 alpha:255];}
|
||||
+ (Color*) oliveDrab {return [Color colorWithRed:107 green:142 blue:35 alpha:255];}
|
||||
+ (Color*) orange {return [Color colorWithRed:255 green:165 blue:0 alpha:255];}
|
||||
+ (Color*) orangeRed {return [Color colorWithRed:255 green:69 blue:0 alpha:255];}
|
||||
+ (Color*) orchid {return [Color colorWithRed:218 green:112 blue:214 alpha:255];}
|
||||
+ (Color*) paleGoldenrod {return [Color colorWithRed:238 green:232 blue:170 alpha:255];}
|
||||
+ (Color*) paleGreen {return [Color colorWithRed:152 green:251 blue:152 alpha:255];}
|
||||
+ (Color*) paleTurquoise {return [Color colorWithRed:175 green:238 blue:238 alpha:255];}
|
||||
+ (Color*) paleVioletRed {return [Color colorWithRed:219 green:112 blue:147 alpha:255];}
|
||||
+ (Color*) papayaWhip {return [Color colorWithRed:255 green:239 blue:213 alpha:255];}
|
||||
+ (Color*) peachPuff {return [Color colorWithRed:255 green:218 blue:185 alpha:255];}
|
||||
+ (Color*) peru {return [Color colorWithRed:205 green:133 blue:63 alpha:255];}
|
||||
+ (Color*) pink {return [Color colorWithRed:255 green:192 blue:203 alpha:255];}
|
||||
+ (Color*) plum {return [Color colorWithRed:221 green:160 blue:221 alpha:255];}
|
||||
+ (Color*) powderBlue {return [Color colorWithRed:176 green:224 blue:230 alpha:255];}
|
||||
+ (Color*) purple {return [Color colorWithRed:128 green:0 blue:128 alpha:255];}
|
||||
+ (Color*) red {return [Color colorWithRed:255 green:0 blue:0 alpha:255];}
|
||||
+ (Color*) rosyBrown {return [Color colorWithRed:188 green:143 blue:143 alpha:255];}
|
||||
+ (Color*) royalBlue {return [Color colorWithRed:65 green:105 blue:225 alpha:255];}
|
||||
+ (Color*) saddleBrown {return [Color colorWithRed:139 green:69 blue:19 alpha:255];}
|
||||
+ (Color*) salmon {return [Color colorWithRed:250 green:128 blue:114 alpha:255];}
|
||||
+ (Color*) sandyBrown {return [Color colorWithRed:244 green:164 blue:96 alpha:255];}
|
||||
+ (Color*) seaGreen {return [Color colorWithRed:46 green:139 blue:87 alpha:255];}
|
||||
+ (Color*) seaShell {return [Color colorWithRed:255 green:245 blue:238 alpha:255];}
|
||||
+ (Color*) sienna {return [Color colorWithRed:160 green:82 blue:45 alpha:255];}
|
||||
+ (Color*) silver {return [Color colorWithRed:192 green:192 blue:192 alpha:255];}
|
||||
+ (Color*) skyBlue {return [Color colorWithRed:135 green:206 blue:235 alpha:255];}
|
||||
+ (Color*) slateBlue {return [Color colorWithRed:106 green:90 blue:205 alpha:255];}
|
||||
+ (Color*) slateGray {return [Color colorWithRed:112 green:128 blue:144 alpha:255];}
|
||||
+ (Color*) snow {return [Color colorWithRed:255 green:250 blue:250 alpha:255];}
|
||||
+ (Color*) springGreen {return [Color colorWithRed:0 green:255 blue:127 alpha:255];}
|
||||
+ (Color*) steelBlue {return [Color colorWithRed:70 green:130 blue:180 alpha:255];}
|
||||
+ (Color*) tan {return [Color colorWithRed:210 green:180 blue:140 alpha:255];}
|
||||
+ (Color*) teal {return [Color colorWithRed:0 green:128 blue:128 alpha:255];}
|
||||
+ (Color*) thistle {return [Color colorWithRed:216 green:191 blue:216 alpha:255];}
|
||||
+ (Color*) tomato {return [Color colorWithRed:255 green:99 blue:71 alpha:255];}
|
||||
+ (Color*) transparent {return [Color colorWithRed:0 green:0 blue:0 alpha:0];}
|
||||
+ (Color*) turquoise {return [Color colorWithRed:64 green:224 blue:208 alpha:255];}
|
||||
+ (Color*) violet {return [Color colorWithRed:238 green:130 blue:238 alpha:255];}
|
||||
+ (Color*) wheat {return [Color colorWithRed:245 green:222 blue:179 alpha:255];}
|
||||
+ (Color*) white {return [Color colorWithRed:255 green:255 blue:255 alpha:255];}
|
||||
+ (Color*) whiteSmoke {return [Color colorWithRed:245 green:245 blue:245 alpha:255];}
|
||||
+ (Color*) yellow {return [Color colorWithRed:255 green:255 blue:0 alpha:255];}
|
||||
+ (Color*) yellowGreen {return [Color colorWithRed:154 green:205 blue:50 alpha:255];}
|
||||
|
||||
@end
|
||||
|
@ -17,7 +17,7 @@
|
||||
int height;
|
||||
}
|
||||
|
||||
- (id) initWithWidth:(int)theWidth Height:(int)theHeight;
|
||||
- (id) initWithWidth:(int)theWidth height:(int)theHeight;
|
||||
|
||||
@property (nonatomic) int width;
|
||||
@property (nonatomic) int height;
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
@implementation BitmapContent
|
||||
|
||||
- (id) initWithWidth:(int)theWidth Height:(int)theHeight {
|
||||
- (id) initWithWidth:(int)theWidth height:(int)theHeight {
|
||||
if (self = [super init]) {
|
||||
width = theWidth;
|
||||
height = theHeight;
|
||||
|
@ -18,7 +18,7 @@
|
||||
- (Byte4*) getPixelData;
|
||||
- (void) setPixelData:(Byte4*)sourceData;
|
||||
|
||||
- (Byte4) getPixelAtX:(int)x Y:(int)y;
|
||||
- (void) setPixelAtX:(int)x Y:(int)y Value:(Byte4)value;
|
||||
- (Byte4) getPixelAtX:(int)x y:(int)y;
|
||||
- (void) setPixelAtX:(int)x y:(int)y value:(Byte4)value;
|
||||
|
||||
@end
|
||||
|
@ -12,7 +12,7 @@
|
||||
@implementation ColorPixelBitmapContent
|
||||
|
||||
- (id) initWithWidth:(int)theWidth Height:(int)theHeight {
|
||||
if (self = [super initWithWidth:theWidth Height:theHeight Format:SurfaceFormatColor]) {
|
||||
if (self = [super initWithWidth:theWidth height:theHeight format:SurfaceFormatColor]) {
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@ -26,11 +26,11 @@
|
||||
[super setPixelData:sourceData];
|
||||
}
|
||||
|
||||
- (Byte4) getPixelAtX:(int)x Y:(int)y {
|
||||
- (Byte4) getPixelAtX:(int)x y:(int)y {
|
||||
return colorPixelData[x + y * width];
|
||||
}
|
||||
|
||||
- (void) setPixelAtX:(int)x Y:(int)y Value:(Byte4)value {
|
||||
- (void) setPixelAtX:(int)x y:(int)y value:(Byte4)value {
|
||||
colorPixelData[x + y * width] = value;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
int bytesPerPixel;
|
||||
}
|
||||
|
||||
- (id) initWithWidth:(int)theWidth Height:(int)theHeight Format:(SurfaceFormat)theFormat;
|
||||
- (id) initWithWidth:(int)theWidth height:(int)theHeight format:(SurfaceFormat)theFormat;
|
||||
|
||||
- (Byte*) getPixelAtX:(int)x Y:(int)y;
|
||||
- (void) setPixelAtX:(int)x Y:(int)y Value:(Byte*)value;
|
||||
|
@ -12,10 +12,10 @@
|
||||
|
||||
@implementation PixelBitmapContent
|
||||
|
||||
- (id) initWithWidth:(int)theWidth Height:(int)theHeight Format:(SurfaceFormat)theFormat {
|
||||
if (self = [super initWithWidth:theWidth Height:theHeight]) {
|
||||
- (id) initWithWidth:(int)theWidth height:(int)theHeight format:(SurfaceFormat)theFormat {
|
||||
if (self = [super initWithWidth:theWidth height:theHeight]) {
|
||||
format = theFormat;
|
||||
BOOL result = [VectorConverter tryGetSizeInBytesOfSurfaceFormat:format SizeInBytes:&bytesPerPixel];
|
||||
BOOL result = [VectorConverter tryGetSizeInBytesOfSurfaceFormat:format sizeInBytes:&bytesPerPixel];
|
||||
if (!result) {
|
||||
[NSException raise:@"ArgumentException" format:@"The provided format is not supported"];
|
||||
}
|
||||
|
@ -15,8 +15,8 @@
|
||||
|
||||
}
|
||||
|
||||
+ (BOOL) tryGetSizeInBytesOfSurfaceFormat:(SurfaceFormat)surfaceFormat SizeInBytes:(int*)sizeInBytes;
|
||||
+ (BOOL) tryGetSizeInBytesOfSurfaceFormat:(SurfaceFormat)surfaceFormat sizeInBytes:(int*)sizeInBytes;
|
||||
|
||||
+ (BOOL) tryGetVectorTypeOfSurfaceFormat:(SurfaceFormat)surfaceFormat VectorType:(Class*)type;
|
||||
+ (BOOL) tryGetVectorTypeOfSurfaceFormat:(SurfaceFormat)surfaceFormat vectorType:(Class*)type;
|
||||
|
||||
@end
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
@implementation VectorConverter
|
||||
|
||||
+ (BOOL) tryGetSizeInBytesOfSurfaceFormat:(SurfaceFormat)surfaceFormat SizeInBytes:(int*)sizeInBytes {
|
||||
+ (BOOL) tryGetSizeInBytesOfSurfaceFormat:(SurfaceFormat)surfaceFormat sizeInBytes:(int*)sizeInBytes {
|
||||
switch (surfaceFormat) {
|
||||
case SurfaceFormatColor:
|
||||
*sizeInBytes = sizeof(Byte4);
|
||||
@ -37,7 +37,7 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (BOOL) tryGetVectorTypeOfSurfaceFormat:(SurfaceFormat)surfaceFormat VectorType:(Class*)type {
|
||||
+ (BOOL) tryGetVectorTypeOfSurfaceFormat:(SurfaceFormat)surfaceFormat vectorType:(Class*)type {
|
||||
switch (surfaceFormat) {
|
||||
case SurfaceFormatColor:
|
||||
*type = [Vector4 class];
|
||||
|
@ -39,7 +39,7 @@
|
||||
CGContextRelease(textureContext);
|
||||
|
||||
// Create pixel bitmap content.
|
||||
PixelBitmapContent *bitmap = [[PixelBitmapContent alloc] initWithWidth:(int)width Height:(int)height Format:SurfaceFormatColor];
|
||||
PixelBitmapContent *bitmap = [[PixelBitmapContent alloc] initWithWidth:(int)width height:(int)height format:SurfaceFormatColor];
|
||||
[bitmap setPixelData:imageData];
|
||||
|
||||
// This bitmap is the only one in the mipmap chain.
|
||||
|
@ -25,14 +25,14 @@
|
||||
[bitmap tryGetFormat:&format];
|
||||
|
||||
Texture2D *texture = [[Texture2D alloc] initWithGraphicsDevice:graphicsDevice
|
||||
Width:bitmap.width
|
||||
Height:bitmap.height
|
||||
MipMaps:generateMipmaps
|
||||
Format:format];
|
||||
width:bitmap.width
|
||||
height:bitmap.height
|
||||
mipMaps:generateMipmaps
|
||||
format:format];
|
||||
|
||||
for (int i=0;i<[mipmaps count];i++) {
|
||||
bitmap = [mipmaps objectAtIndex:i];
|
||||
[texture setDataToLevel:i SourceRectangle:nil From:[bitmap getPixelData]];
|
||||
[texture setDataToLevel:i sourceRectangle:nil from:[bitmap getPixelData]];
|
||||
}
|
||||
|
||||
return texture;
|
||||
|
@ -32,7 +32,7 @@
|
||||
targetElapsedTime = 1.0 / 60.0;
|
||||
inactiveSleepTime = 1.0 / 5.0;
|
||||
maximumElapsedTime = 1.0 / 2.0;
|
||||
|
||||
|
||||
// Get the game host.
|
||||
gameHost = (GameHost*)[UIApplication sharedApplication];
|
||||
}
|
||||
|
72
Classes/Retronator/Xni/Framework/Graphics/BasicEffect.h
Normal file
72
Classes/Retronator/Xni/Framework/Graphics/BasicEffect.h
Normal file
@ -0,0 +1,72 @@
|
||||
//
|
||||
// BasicEffect.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Effect.h"
|
||||
|
||||
@interface BasicEffect : Effect {
|
||||
// Material
|
||||
float alpha;
|
||||
Vector3 *ambientColor;
|
||||
Vector3 *diffuseColor;
|
||||
Vector3 *emissiveColor;
|
||||
Vector3 *specularColor;
|
||||
float specularPower;
|
||||
BOOL vertexColorEnabled;
|
||||
|
||||
// Texturing
|
||||
BOOL textureEnabled;
|
||||
Texture2D *texture;
|
||||
|
||||
// Lighting
|
||||
BOOL lightingEnabled;
|
||||
Vector3 *ambientLightColor;
|
||||
DirectionalLight *directionalLight0;
|
||||
DirectionalLight *directionalLight1;
|
||||
DirectionalLight *directionalLight2;
|
||||
|
||||
// Fog
|
||||
BOOL fogEnabled;
|
||||
Vector3 *fogColor;
|
||||
float fogStart;
|
||||
float fogEnd;
|
||||
|
||||
// Transformations
|
||||
Matrix *projection;
|
||||
Matrix *view;
|
||||
Matrix *world;
|
||||
}
|
||||
|
||||
@property (nonatomic) float alpha;
|
||||
@property (nonatomic, retain) Vector3 *ambientColor;
|
||||
@property (nonatomic, retain) Vector3 *diffuseColor;
|
||||
@property (nonatomic, retain) Vector3 *emissiveColor;
|
||||
@property (nonatomic, retain) Vector3 *specularColor;
|
||||
@property (nonatomic) float specularPower;
|
||||
@property (nonatomic) BOOL vertexColorEnabled;
|
||||
|
||||
@property (nonatomic) BOOL textureEnabled;
|
||||
@property (nonatomic, retain) Texture2D *texture;
|
||||
|
||||
@property (nonatomic) BOOL lightingEnabled;
|
||||
@property (nonatomic, retain) Vector3 *ambientLightColor;
|
||||
@property (nonatomic, readonly) DirectionalLight *directionalLight0;
|
||||
@property (nonatomic, readonly) DirectionalLight *directionalLight1;
|
||||
@property (nonatomic, readonly) DirectionalLight *directionalLight2;
|
||||
|
||||
@property (nonatomic) BOOL fogEnabled;
|
||||
@property (nonatomic, retain) Vector3 *fogColor;
|
||||
@property (nonatomic) float fogStart;
|
||||
@property (nonatomic) float fogEnd;
|
||||
|
||||
@property (nonatomic, retain) Matrix *projection;
|
||||
@property (nonatomic, retain) Matrix *view;
|
||||
@property (nonatomic, retain) Matrix *world;
|
||||
|
||||
@end
|
196
Classes/Retronator/Xni/Framework/Graphics/BasicEffect.m
Normal file
196
Classes/Retronator/Xni/Framework/Graphics/BasicEffect.m
Normal file
@ -0,0 +1,196 @@
|
||||
//
|
||||
// BasicEffect.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "BasicEffect.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.h"
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
|
||||
@interface BasicEffectPass : EffectPass {
|
||||
BasicEffect *basicEffect;
|
||||
}
|
||||
|
||||
- (id) initWithBasicEffect:(BasicEffect*)theBasicEffect;
|
||||
|
||||
@end
|
||||
|
||||
@implementation BasicEffect
|
||||
|
||||
-(id) initWithGraphicsDevice:(GraphicsDevice *)theGraphicsDevice {
|
||||
if (self = [super initWithGraphicsDevice:theGraphicsDevice]) {
|
||||
// Create the main pass.
|
||||
BasicEffectPass *mainPass = [[BasicEffectPass alloc] initWithBasicEffect:self];
|
||||
NSArray *passes = [NSArray arrayWithObject:mainPass];
|
||||
|
||||
// Create the basic technique.
|
||||
EffectTechnique *basicTechnique = [[EffectTechnique alloc] initWithName:@"BasicEffect" passes:passes];
|
||||
|
||||
techniques = [NSDictionary dictionaryWithObject:basicTechnique forKey:basicTechnique.name];
|
||||
currentTechnique = basicTechnique;
|
||||
|
||||
// Set defaults.
|
||||
self.alpha = 1;
|
||||
self.ambientColor = [Vector3 zero];
|
||||
self.diffuseColor = [Vector3 zero];
|
||||
self.emissiveColor = [Vector3 zero];
|
||||
self.specularColor = [Vector3 zero];
|
||||
self.specularPower = 0;
|
||||
self.vertexColorEnabled = NO;
|
||||
|
||||
self.textureEnabled = NO;
|
||||
self.texture = nil;
|
||||
|
||||
self.lightingEnabled = NO;
|
||||
self.ambientLightColor = [Vector3 zero];
|
||||
directionalLight0 = [[DirectionalLight alloc] init];
|
||||
directionalLight1 = [[DirectionalLight alloc] init];
|
||||
directionalLight2 = [[DirectionalLight alloc] init];
|
||||
|
||||
self.fogEnabled = NO;
|
||||
self.fogColor = [Vector3 zero];
|
||||
self.fogStart = 0;
|
||||
self.fogEnd = 1;
|
||||
|
||||
self.projection = [Matrix identity];
|
||||
self.view = [Matrix identity];
|
||||
self.world = [Matrix identity];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@synthesize alpha;
|
||||
@synthesize ambientColor;
|
||||
@synthesize diffuseColor;
|
||||
@synthesize emissiveColor;
|
||||
@synthesize specularColor;
|
||||
@synthesize specularPower;
|
||||
@synthesize vertexColorEnabled;
|
||||
|
||||
@synthesize textureEnabled;
|
||||
@synthesize texture;
|
||||
|
||||
@synthesize lightingEnabled;
|
||||
@synthesize ambientLightColor;
|
||||
@synthesize directionalLight0;
|
||||
@synthesize directionalLight1;
|
||||
@synthesize directionalLight2;
|
||||
|
||||
@synthesize fogEnabled;
|
||||
@synthesize fogColor;
|
||||
@synthesize fogStart;
|
||||
@synthesize fogEnd;
|
||||
|
||||
@synthesize projection;
|
||||
@synthesize view;
|
||||
@synthesize world;
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[directionalLight0 release];
|
||||
[directionalLight1 release];
|
||||
[directionalLight2 release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface BasicEffectPass()
|
||||
|
||||
- (void) activateLight:(DirectionalLight*) light name:(uint)name;
|
||||
|
||||
@end
|
||||
|
||||
@implementation BasicEffectPass
|
||||
|
||||
- (id) initWithBasicEffect:(BasicEffect *)theBasicEffect {
|
||||
if (self = [super initWithName:@"BasicEffectPass"]) {
|
||||
basicEffect = theBasicEffect;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) apply {
|
||||
// Set material.
|
||||
Vector4Struct data;
|
||||
Vector4Set(&data, basicEffect.ambientColor.x, basicEffect.ambientColor.y, basicEffect.ambientColor.z, basicEffect.alpha);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float*)&data);
|
||||
|
||||
Vector4Set(&data, basicEffect.diffuseColor.x, basicEffect.diffuseColor.y, basicEffect.diffuseColor.z, basicEffect.alpha);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float*)&data);
|
||||
|
||||
Vector4Set(&data, basicEffect.specularColor.x, basicEffect.specularColor.y, basicEffect.specularColor.z, 1);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float*)&data);
|
||||
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, basicEffect.specularPower);
|
||||
|
||||
Vector4Set(&data, basicEffect.emissiveColor.x, basicEffect.emissiveColor.y, basicEffect.emissiveColor.z, 1);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (float*)&data);
|
||||
|
||||
if (basicEffect.vertexColorEnabled) {
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
} else {
|
||||
glDisable(GL_COLOR_MATERIAL);
|
||||
}
|
||||
|
||||
// Set texturing.
|
||||
if (basicEffect.textureEnabled) {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, basicEffect.texture.textureId);
|
||||
} else {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
// Set the projection matrix.
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixf((float*)basicEffect.projection.data);
|
||||
|
||||
// Set the model-view matrix.
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
// Multiply in reverse order, because our matrices assume vector transformation b = a * M,
|
||||
// while openGL will tranform b = M * a. So v_projectionspace = M_modelview * v_modelspace,
|
||||
// and our model-view matrix therefore should be view * world.
|
||||
glLoadMatrixf((float*)basicEffect.view.data);
|
||||
|
||||
// Set lighting now that we're in view coordinates.
|
||||
if (basicEffect.lightingEnabled) {
|
||||
glEnable(GL_LIGHTING);
|
||||
} else {
|
||||
glDisable(GL_LIGHTING);
|
||||
}
|
||||
Vector4Set(&data, basicEffect.ambientLightColor.x, basicEffect.ambientLightColor.y, basicEffect.ambientLightColor.z, 1);
|
||||
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, (float*)&data);
|
||||
[self activateLight:basicEffect.directionalLight0 name:GL_LIGHT0];
|
||||
[self activateLight:basicEffect.directionalLight1 name:GL_LIGHT1];
|
||||
[self activateLight:basicEffect.directionalLight2 name:GL_LIGHT2];
|
||||
|
||||
// Finally add the world component of the model-view matrix.
|
||||
glMultMatrixf((float*)basicEffect.world.data);
|
||||
}
|
||||
|
||||
- (void) activateLight:(DirectionalLight *)light name:(uint)lightName {
|
||||
if (light.enabled) {
|
||||
glEnable(lightName);
|
||||
} else {
|
||||
glDisable(lightName);
|
||||
return;
|
||||
}
|
||||
|
||||
Vector4Struct data;
|
||||
Vector4Set(&data, light.ambientColor.x, light.ambientColor.y, light.ambientColor.z, 1);
|
||||
glLightfv(lightName, GL_AMBIENT, (float*)&data);
|
||||
Vector4Set(&data, light.diffuseColor.x, light.diffuseColor.y, light.diffuseColor.z, 1);
|
||||
glLightfv(lightName, GL_DIFFUSE, (float*)&data);
|
||||
Vector4Set(&data, light.specularColor.x, light.specularColor.y, light.specularColor.z, 1);
|
||||
glLightfv(lightName, GL_SPECULAR, (float*)&data);
|
||||
Vector4Set(&data, light.direction.x, light.direction.y, light.direction.z, 0);
|
||||
glLightfv(lightName, GL_POSITION, (float*)&data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
27
Classes/Retronator/Xni/Framework/Graphics/DirectionalLight.h
Normal file
27
Classes/Retronator/Xni/Framework/Graphics/DirectionalLight.h
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// DirectionalLight.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.classes.h"
|
||||
|
||||
@interface DirectionalLight : NSObject {
|
||||
Vector3 *ambientColor;
|
||||
Vector3 *diffuseColor;
|
||||
Vector3 *direction;
|
||||
BOOL enabled;
|
||||
Vector3 *specularColor;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) Vector3 *ambientColor;
|
||||
@property (nonatomic, retain) Vector3 *diffuseColor;
|
||||
@property (nonatomic, retain) Vector3 *direction;
|
||||
@property (nonatomic) BOOL enabled;
|
||||
@property (nonatomic, retain) Vector3 *specularColor;
|
||||
|
||||
@end
|
33
Classes/Retronator/Xni/Framework/Graphics/DirectionalLight.m
Normal file
33
Classes/Retronator/Xni/Framework/Graphics/DirectionalLight.m
Normal file
@ -0,0 +1,33 @@
|
||||
//
|
||||
// DirectionalLight.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "DirectionalLight.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.h"
|
||||
|
||||
@implementation DirectionalLight
|
||||
|
||||
- (id) init {
|
||||
if (self = [super init]) {
|
||||
self.enabled = NO;
|
||||
self.ambientColor = [Vector3 zero];
|
||||
self.diffuseColor = [Vector3 zero];
|
||||
self.specularColor = [Vector3 zero];
|
||||
self.direction = [Vector3 zero];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@synthesize ambientColor;
|
||||
@synthesize diffuseColor;
|
||||
@synthesize direction;
|
||||
@synthesize enabled;
|
||||
@synthesize specularColor;
|
||||
|
||||
@end
|
||||
|
@ -8,9 +8,14 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "GraphicsResource.h"
|
||||
|
||||
@interface Effect : NSObject {
|
||||
|
||||
@interface Effect : GraphicsResource {
|
||||
EffectTechnique *currentTechnique;
|
||||
NSDictionary *techniques;
|
||||
}
|
||||
|
||||
@end
|
||||
@property (nonatomic, retain) EffectTechnique *currentTechnique;
|
||||
@property (nonatomic, readonly) NSDictionary *techniques;
|
||||
|
||||
@end
|
@ -11,4 +11,7 @@
|
||||
|
||||
@implementation Effect
|
||||
|
||||
@synthesize currentTechnique;
|
||||
@synthesize techniques;
|
||||
|
||||
@end
|
||||
|
22
Classes/Retronator/Xni/Framework/Graphics/EffectPass.h
Normal file
22
Classes/Retronator/Xni/Framework/Graphics/EffectPass.h
Normal file
@ -0,0 +1,22 @@
|
||||
//
|
||||
// EffectPass.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
|
||||
@interface EffectPass : NSObject {
|
||||
NSString *name;
|
||||
}
|
||||
|
||||
- (id) initWithName:(NSString*)theName;
|
||||
|
||||
@property (nonatomic, readonly) NSString *name;
|
||||
|
||||
- (void) apply;
|
||||
|
||||
@end
|
32
Classes/Retronator/Xni/Framework/Graphics/EffectPass.m
Normal file
32
Classes/Retronator/Xni/Framework/Graphics/EffectPass.m
Normal file
@ -0,0 +1,32 @@
|
||||
//
|
||||
// EffectPass.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "EffectPass.h"
|
||||
|
||||
|
||||
@implementation EffectPass
|
||||
|
||||
-(id) initWithName:(NSString *)theName {
|
||||
if (self = [super init]) {
|
||||
name = [theName retain];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@synthesize name;
|
||||
|
||||
- (void) apply {}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[name release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
21
Classes/Retronator/Xni/Framework/Graphics/EffectTechnique.h
Normal file
21
Classes/Retronator/Xni/Framework/Graphics/EffectTechnique.h
Normal file
@ -0,0 +1,21 @@
|
||||
//
|
||||
// EffectTechnique.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface EffectTechnique : NSObject {
|
||||
NSArray *passes;
|
||||
NSString *name;
|
||||
}
|
||||
|
||||
- (id) initWithName:(NSString*)theName passes:(NSArray*)thePasses;
|
||||
|
||||
@property (nonatomic, readonly) NSString *name;
|
||||
@property (nonatomic, readonly) NSArray *passes;
|
||||
|
||||
@end
|
31
Classes/Retronator/Xni/Framework/Graphics/EffectTechnique.m
Normal file
31
Classes/Retronator/Xni/Framework/Graphics/EffectTechnique.m
Normal file
@ -0,0 +1,31 @@
|
||||
//
|
||||
// EffectTechnique.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "EffectTechnique.h"
|
||||
|
||||
@implementation EffectTechnique
|
||||
|
||||
-(id) initWithName:(NSString *)theName passes:(NSArray *)thePasses {
|
||||
if (self = [super init]) {
|
||||
name = [theName retain];
|
||||
passes = [thePasses retain];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@synthesize name;
|
||||
@synthesize passes;
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[name release];
|
||||
[passes release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
@ -2,17 +2,17 @@
|
||||
#import <OpenGLES/ES2/gl.h>
|
||||
|
||||
typedef enum {
|
||||
BlendZero,
|
||||
BlendOne,
|
||||
BlendSourceColor,
|
||||
BlendInverseSourceColor,
|
||||
BlendSourceAlpha,
|
||||
BlendInverseSourceAlpha,
|
||||
BlendDestinationAlpha,
|
||||
BlendInverseDestinationAlpha,
|
||||
BlendDestinationColor,
|
||||
BlendInverseDestinationColor,
|
||||
BlendSourceAlphaSaturation,
|
||||
BlendZero = GL_ZERO,
|
||||
BlendOne = GL_ONE,
|
||||
BlendSourceColor = GL_SRC_COLOR,
|
||||
BlendInverseSourceColor = GL_ONE_MINUS_SRC_COLOR,
|
||||
BlendSourceAlpha = GL_SRC_ALPHA,
|
||||
BlendInverseSourceAlpha = GL_ONE_MINUS_SRC_ALPHA,
|
||||
BlendDestinationAlpha = GL_DST_ALPHA,
|
||||
BlendInverseDestinationAlpha = GL_ONE_MINUS_DST_ALPHA,
|
||||
BlendDestinationColor = GL_DST_COLOR,
|
||||
BlendInverseDestinationColor = GL_ONE_MINUS_DST_COLOR,
|
||||
BlendSourceAlphaSaturation = GL_SRC_ALPHA_SATURATE,
|
||||
BlendBlendFactor,
|
||||
BlendInverseBlendFactor
|
||||
} Blend;
|
||||
|
@ -24,12 +24,36 @@
|
||||
|
||||
// The OpenGL names for the buffers used to render to this view
|
||||
GLuint defaultFramebuffer, colorRenderbuffer, depthRenderbuffer;
|
||||
|
||||
// Device state
|
||||
Color *blendFactor;
|
||||
BlendState *blendState;
|
||||
DepthStencilState *depthStencilState;
|
||||
GraphicsDeviceStatus graphicsDeviceStatus;
|
||||
IndexBuffer *indices;
|
||||
RasterizerState *rasterizerState;
|
||||
int referenceStencil;
|
||||
SamplerStateCollection *samplerStates;
|
||||
TextureCollection *textures;
|
||||
|
||||
NSMutableArray *vertices;
|
||||
}
|
||||
|
||||
@property (nonatomic, readonly) GraphicsProfile graphicsProfile;
|
||||
|
||||
- (id) initWithGame:(Game*) theGame;
|
||||
|
||||
@property (nonatomic, retain) Color *blendFactor;
|
||||
@property (nonatomic, retain) BlendState *blendState;
|
||||
@property (nonatomic, retain) DepthStencilState *depthStencilState;
|
||||
@property (nonatomic, readonly) GraphicsDeviceStatus graphicsDeviceStatus;
|
||||
@property (nonatomic, readonly) GraphicsProfile graphicsProfile;
|
||||
@property (nonatomic, retain) IndexBuffer *indices;
|
||||
@property (nonatomic, retain) RasterizerState *rasterizerState;
|
||||
@property (nonatomic) int referenceStencil;
|
||||
@property (nonatomic, readonly) SamplerStateCollection *samplerStates;
|
||||
@property (nonatomic, readonly) TextureCollection *textures;
|
||||
|
||||
+ (int) getNumberOfVerticesForPrimitiveType:(PrimitiveType)primitiveType primitiveCount:(int)primitiveCount;
|
||||
|
||||
// Presentation
|
||||
- (void) reset;
|
||||
- (void) present;
|
||||
@ -38,6 +62,31 @@
|
||||
- (void) clearWithColor:(Color*)color;
|
||||
- (void) clearWithOptions:(ClearOptions)options color:(Color*)color depth:(float)depth stencil:(int)stencil;
|
||||
|
||||
// Vertex buffers
|
||||
- (NSArray*) getVertexBuffers;
|
||||
- (void) setVertexBuffer:(VertexBuffer*)vertexBuffer;
|
||||
- (void) setVertexBuffer:(VertexBuffer*)vertexBuffer vertexOffset:(int)vertexOffset;
|
||||
- (void) setVertexBuffers:(VertexBufferBinding*)vertexBuffer, ... NS_REQUIRES_NIL_TERMINATION;
|
||||
|
||||
// Drawing
|
||||
- (void) drawPrimitivesOfType:(PrimitiveType)primitiveType startingAt:(int)startVertex count:(int)primitiveCount;
|
||||
|
||||
- (void) drawIndexedPrimitivesOfType:(PrimitiveType)primitiveType offsetVerticesBy:(int)baseVertex
|
||||
startingAt:(int)startIndex count:(int)primitiveCount;
|
||||
|
||||
- (void) drawUserPrimitivesOfType:(PrimitiveType)primitiveType vertices:(VertexArray*)vertexData
|
||||
startingAt:(int)vertexOffset count:(int)primitiveCount;
|
||||
|
||||
- (void) drawUserPrimitivesOfType:(PrimitiveType)primitiveType
|
||||
vertices:(void*)vertexData ofType:(VertexDeclaration*) vertexDeclaration
|
||||
startingAt:(int)vertexOffset count:(int)primitiveCount;
|
||||
|
||||
- (void) drawUserIndexedPrimitivesOfType:(PrimitiveType)primitiveType
|
||||
vertices:(void*)vertexData ofType:(VertexDeclaration*) vertexDeclaration
|
||||
offsetVerticesBy:(int)vertexOffset indices:(void*)indexData dataType:(DataType)dataType
|
||||
startingAt:(int)indexOffset count:(int)primitiveCount;
|
||||
|
||||
|
||||
// Low level methods
|
||||
- (uint) createTexture;
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
#import "GraphicsDevice.h"
|
||||
#import <OpenGLES/ES1/gl.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.h"
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
@ -46,15 +47,82 @@
|
||||
glGenRenderbuffersOES(1, &depthRenderbuffer);
|
||||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
|
||||
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
|
||||
|
||||
|
||||
// Do the initial reset.
|
||||
[self reset];
|
||||
|
||||
// Initialize defaults.
|
||||
self.blendFactor = [Color white];
|
||||
self.blendState = [BlendState opaque];
|
||||
self.depthStencilState = [DepthStencilState defaultDepth];
|
||||
graphicsDeviceStatus = GraphicsDeviceStatusNormal;
|
||||
self.indices = nil;
|
||||
self.rasterizerState = [RasterizerState cullClockwise];
|
||||
self.referenceStencil = 0;
|
||||
samplerStates = [[SamplerStateCollection alloc] init];
|
||||
textures = [[TextureCollection alloc] init];
|
||||
[samplerStates insertObject:[SamplerState linearClamp] atIndex:0];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
#define FLAG_BLOCK(variable, parameter) if (variable) { glEnable(parameter); } else { glDisable(parameter);}
|
||||
|
||||
@synthesize blendFactor;
|
||||
@synthesize blendState;
|
||||
- (void) setBlendState:(BlendState*)value {
|
||||
if (value != blendState) {
|
||||
[value retain];
|
||||
[blendState release];
|
||||
blendState = value;
|
||||
|
||||
// Apply the blend state.
|
||||
glBlendFunc(blendState.colorSourceBlend, blendState.colorDestinationBlend);
|
||||
}
|
||||
}
|
||||
|
||||
@synthesize depthStencilState;
|
||||
- (void) depthStencilState:(DepthStencilState*)value {
|
||||
if (value != depthStencilState) {
|
||||
[value retain];
|
||||
[depthStencilState release];
|
||||
depthStencilState = value;
|
||||
}
|
||||
}
|
||||
|
||||
@synthesize graphicsDeviceStatus;
|
||||
@synthesize graphicsProfile;
|
||||
@synthesize indices;
|
||||
@synthesize rasterizerState;
|
||||
- (void) setRasterizerState:(RasterizerState*)value {
|
||||
if (value != rasterizerState) {
|
||||
[value retain];
|
||||
[rasterizerState release];
|
||||
rasterizerState = value;
|
||||
}
|
||||
}
|
||||
|
||||
@synthesize referenceStencil;
|
||||
@synthesize samplerStates;
|
||||
@synthesize textures;
|
||||
|
||||
+ (int) getNumberOfVerticesForPrimitiveType:(PrimitiveType)primitiveType primitiveCount:(int)primitiveCount {
|
||||
switch (primitiveType) {
|
||||
case PrimitiveTypeLineStrip:
|
||||
return primitiveCount + 1;
|
||||
case PrimitiveTypeLineList:
|
||||
return 2 * primitiveCount;
|
||||
case PrimitiveTypeTriangleStrip:
|
||||
return primitiveCount + 2;
|
||||
case PrimitiveTypeTriangleList:
|
||||
return 3 * primitiveCount;
|
||||
default:
|
||||
[NSException raise:@"NotImplementedException"
|
||||
format:@"The primitive type %i is not yet implemented.", primitiveType];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Presentation
|
||||
- (void) reset {
|
||||
@ -97,6 +165,36 @@
|
||||
glClear(options);
|
||||
}
|
||||
|
||||
// Vertex buffers
|
||||
- (NSArray*) getVertexBuffers {
|
||||
return [[NSArray arrayWithArray:vertices] autorelease];
|
||||
}
|
||||
|
||||
- (void) setVertexBuffer:(VertexBuffer*)vertexBuffer {
|
||||
VertexBufferBinding *binding = [[VertexBufferBinding alloc] initWithVertexBuffer:vertexBuffer];
|
||||
[vertices insertObject:binding atIndex:0];
|
||||
[binding release];
|
||||
}
|
||||
|
||||
- (void) setVertexBuffer:(VertexBuffer*)vertexBuffer vertexOffset:(int)vertexOffset {
|
||||
VertexBufferBinding *binding = [[VertexBufferBinding alloc] initWithVertexBuffer:vertexBuffer vertexOffset:vertexOffset];
|
||||
[vertices insertObject:binding atIndex:0];
|
||||
[binding release];
|
||||
}
|
||||
|
||||
- (void) setVertexBuffers:(VertexBufferBinding*)vertexBuffer, ... {
|
||||
if (vertexBuffer != nil) {
|
||||
va_list args;
|
||||
va_start(args, vertexBuffer);
|
||||
VertexBufferBinding *binding = vertexBuffer;
|
||||
for (int i = 0; binding; i++) {
|
||||
[vertices insertObject:binding atIndex:i];
|
||||
binding = va_arg(args, VertexBufferBinding*);
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
|
||||
// Low level methods
|
||||
- (uint) createTexture {
|
||||
GLuint textureId;
|
||||
@ -129,6 +227,23 @@
|
||||
|
||||
- (EAGLContext*) createContext { return nil; }
|
||||
|
||||
- (void) drawPrimitivesOfType:(PrimitiveType)primitiveType startingAt:(int)startVertex count:(int)primitiveCount {}
|
||||
|
||||
- (void) drawIndexedPrimitivesOfType:(PrimitiveType)primitiveType offsetVerticesBy:(int)baseVertex
|
||||
startingAt:(int)startIndex count:(int)primitiveCount {}
|
||||
|
||||
- (void) drawUserPrimitivesOfType:(PrimitiveType)primitiveType vertices:(VertexArray*)vertexData
|
||||
startingAt:(int)vertexOffset count:(int)primitiveCount {}
|
||||
|
||||
- (void) drawUserPrimitivesOfType:(PrimitiveType)primitiveType
|
||||
vertices:(void*)vertexData ofType:(VertexDeclaration*) vertexDeclaration
|
||||
startingAt:(int)vertexOffset count:(int)primitiveCount {}
|
||||
|
||||
- (void) drawUserIndexedPrimitivesOfType:(PrimitiveType)primitiveType
|
||||
vertices:(void*)vertexData ofType:(VertexDeclaration*) vertexDeclaration
|
||||
offsetVerticesBy:(int)vertexOffset indices:(void*)indexData dataType:(DataType)dataType
|
||||
startingAt:(int)indexOffset count:(int)primitiveCount {}
|
||||
|
||||
// Private methods
|
||||
|
||||
+ (void) getFormat:(GLenum*)format AndType:(GLenum*)type ForSurfaceFormat:(SurfaceFormat)surfaceFormat {
|
||||
@ -158,5 +273,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[blendState release];
|
||||
[depthStencilState release];
|
||||
[rasterizerState release];
|
||||
[samplerStates release];
|
||||
[textures release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
19
Classes/Retronator/Xni/Framework/Graphics/IndexBuffer.h
Normal file
19
Classes/Retronator/Xni/Framework/Graphics/IndexBuffer.h
Normal file
@ -0,0 +1,19 @@
|
||||
//
|
||||
// IndexBuffer.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "GraphicsResource.h"
|
||||
|
||||
@interface IndexBuffer : GraphicsResource {
|
||||
uint bufferID;
|
||||
}
|
||||
|
||||
@property (nonatomic, readonly) uint bufferId;
|
||||
|
||||
@end
|
16
Classes/Retronator/Xni/Framework/Graphics/IndexBuffer.m
Normal file
16
Classes/Retronator/Xni/Framework/Graphics/IndexBuffer.m
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// IndexBuffer.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "IndexBuffer.h"
|
||||
|
||||
|
||||
@implementation IndexBuffer
|
||||
|
||||
@synthesize bufferId;
|
||||
|
||||
@end
|
@ -12,7 +12,6 @@
|
||||
|
||||
|
||||
@interface ReachGraphicsDevice : GraphicsDevice {
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -8,10 +8,121 @@
|
||||
|
||||
#import "ReachGraphicsDevice.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
|
||||
@interface ReachGraphicsDevice()
|
||||
|
||||
- (void) enableVertexBuffers;
|
||||
- (void) disableVertexBuffers;
|
||||
|
||||
- (void) enableDeclaration:(VertexDeclaration*)vertexDeclaration forUserData:(void*)data;
|
||||
|
||||
- (void) enableDeclaration:(VertexDeclaration*)vertexDeclaration onStream:(int)stream useBuffers:(BOOL)useBuffers pointer:(void*)pointer;
|
||||
- (void) disableDeclaration:(VertexDeclaration*)vertexDeclaration;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation ReachGraphicsDevice
|
||||
|
||||
- (EAGLContext*) createContext {
|
||||
return [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
|
||||
}
|
||||
|
||||
- (void) drawUserPrimitivesOfType:(PrimitiveType)primitiveType vertices:(VertexArray*)vertexData
|
||||
startingAt:(int)vertexOffset count:(int)primitiveCount {
|
||||
[self drawUserPrimitivesOfType:primitiveType vertices:vertexData.array ofType:vertexData.vertexDeclaration
|
||||
startingAt:vertexOffset count:primitiveCount];
|
||||
}
|
||||
|
||||
- (void) drawUserPrimitivesOfType:(PrimitiveType)primitiveType
|
||||
vertices:(void *)vertexData ofType:(VertexDeclaration *)vertexDeclaration
|
||||
startingAt:(int)vertexOffset count:(int)primitiveCount {
|
||||
|
||||
[self enableDeclaration:vertexDeclaration forUserData:(vertexData + vertexOffset * vertexDeclaration.vertexStride)];
|
||||
|
||||
int count = [GraphicsDevice getNumberOfVerticesForPrimitiveType:primitiveType primitiveCount:primitiveCount];
|
||||
glDrawArrays(primitiveType, 0, count);
|
||||
|
||||
[self disableDeclaration:vertexDeclaration];
|
||||
}
|
||||
|
||||
// Private methods
|
||||
|
||||
- (void) enableVertexBuffers {
|
||||
// We need to enable the declarations set on the vertex buffers.
|
||||
for (int i=0;i<[vertices count];i++) {
|
||||
VertexBufferBinding *binding = [vertices objectAtIndex:i];
|
||||
[self enableDeclaration:binding.vertexBuffer.vertexDeclaration
|
||||
onStream:i useBuffers:YES pointer:(void*)binding.vertexOffset];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) enableDeclaration:(VertexDeclaration*)vertexDeclaration forUserData:(void*)data {
|
||||
[self enableDeclaration:vertexDeclaration onStream:0 useBuffers:NO pointer:data];
|
||||
}
|
||||
|
||||
- (void) enableDeclaration:(VertexDeclaration *)vertexDeclaration onStream:(int)stream useBuffers:(BOOL)useBuffers pointer:(void*)pointer {
|
||||
NSArray *vertexElements = vertexDeclaration.vertexElements;
|
||||
|
||||
int stride = vertexDeclaration.vertexStride;
|
||||
|
||||
for (VertexElement *vertexElement in vertexElements) {
|
||||
if (useBuffers) {
|
||||
// Bind the buffer the vertex element is using.
|
||||
VertexBufferBinding* binding = [vertices objectAtIndex:stream];
|
||||
glBindBuffer(GL_ARRAY_BUFFER, binding.vertexBuffer.bufferId);
|
||||
}
|
||||
|
||||
// Enable the state that the vertex element represents.
|
||||
glEnableClientState(vertexElement.vertexElementUsage);
|
||||
|
||||
// Create the pointer to the vertex element data.
|
||||
switch (vertexElement.vertexElementUsage) {
|
||||
case VertexElementUsagePosition:
|
||||
glVertexPointer([vertexElement getValueDimensions], [vertexElement getValueDataType],
|
||||
stride, pointer + vertexElement.offset);
|
||||
break;
|
||||
case VertexElementUsageNormal:
|
||||
glNormalPointer([vertexElement getValueDataType],
|
||||
stride, pointer + vertexElement.offset);
|
||||
break;
|
||||
case VertexElementUsageTextureCoordinate:
|
||||
glTexCoordPointer([vertexElement getValueDimensions], [vertexElement getValueDataType],
|
||||
stride, pointer + vertexElement.offset);
|
||||
break;
|
||||
case VertexElementUsageColor:
|
||||
glColorPointer([vertexElement getValueDimensions], [vertexElement getValueDataType],
|
||||
stride, pointer + vertexElement.offset);
|
||||
break;
|
||||
case VertexElementUsagePointSize:
|
||||
glPointSizePointerOES([vertexElement getValueDataType],
|
||||
stride, pointer + vertexElement.offset);
|
||||
break;
|
||||
default:
|
||||
[NSException raise:@"NotImplementedException"
|
||||
format:@"The vertex element usage %i is not yet implemented.", vertexElement.vertexElementUsage];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) disableVertexBuffers {
|
||||
// We need to disable the declarations set on the vertex buffers.
|
||||
for (int i=0;i<[vertices count];i++) {
|
||||
VertexBufferBinding *binding = [vertices objectAtIndex:i];
|
||||
[self disableDeclaration:binding.vertexBuffer.vertexDeclaration];
|
||||
}
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
- (void) disableDeclaration:(VertexDeclaration*)vertexDeclaration {
|
||||
NSArray *vertexElements = vertexDeclaration.vertexElements;
|
||||
for (VertexElement *vertexElement in vertexElements) {
|
||||
// Enable the state that the vertex element represents.
|
||||
glDisableClientState(vertexElement.vertexElementUsage);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,7 +1,15 @@
|
||||
#import "Enums.h"
|
||||
|
||||
@class GraphicsResource, Texture, Texture2D, Effect;
|
||||
@class BlendState, DepthStencilState, RasterizerState, SamplerState;
|
||||
@class GraphicsResource, Texture, Texture2D, Effect, EffectTechnique, EffectPass, BasicEffect, DirectionalLight;
|
||||
|
||||
#import "VertexStructs.h"
|
||||
@class VertexElement, VertexPositionColor, VertexPositionTexture, VertexDeclaration;
|
||||
@class VertexArray, VertexPositionColorArray, VertexPositionTextureArray;
|
||||
@class VertexBuffer, VertexBufferBinding, IndexBuffer;
|
||||
|
||||
@class BlendState, DepthStencilState, RasterizerState, SamplerState, SamplerStateCollection, TextureCollection;
|
||||
|
||||
@protocol IGraphicsDeviceService;
|
||||
@class GraphicsDevice, ReachGraphicsDevice, HiDefGraphicsDevice;
|
||||
|
||||
@class SpriteBatch;
|
||||
|
@ -3,10 +3,31 @@
|
||||
#import "Texture.h"
|
||||
#import "Texture2D.h"
|
||||
#import "Effect.h"
|
||||
#import "EffectTechnique.h"
|
||||
#import "EffectPass.h"
|
||||
#import "BasicEffect.h"
|
||||
#import "DirectionalLight.h"
|
||||
|
||||
#import "VertexStructs.h"
|
||||
#import "VertexElement.h"
|
||||
#import "VertexPositionColor.h"
|
||||
#import "VertexPositionTexture.h"
|
||||
#import "VertexDeclaration.h"
|
||||
|
||||
#import "VertexArray.h"
|
||||
#import "VertexPositionColorArray.h"
|
||||
#import "VertexPositionTextureArray.h"
|
||||
|
||||
#import "VertexBuffer.h"
|
||||
#import "VertexBufferBinding.h"
|
||||
#import "IndexBuffer.h"
|
||||
|
||||
#import "BlendState.h"
|
||||
#import "DepthStencilState.h"
|
||||
#import "RasterizerState.h"
|
||||
#import "SamplerState.h"
|
||||
#import "SamplerStateCollection.h"
|
||||
#import "TextureCollection.h"
|
||||
|
||||
#import "IGraphicsDeviceService.h"
|
||||
#import "GraphicsDevice.h"
|
||||
|
@ -0,0 +1,22 @@
|
||||
//
|
||||
// SamplerStateCollection.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.classes.h"
|
||||
|
||||
@interface SamplerStateCollection : NSObject {
|
||||
NSMutableArray *collection;
|
||||
}
|
||||
|
||||
- (int) count;
|
||||
- (SamplerState*)objectAtIndex:(NSUInteger)index;
|
||||
- (void)addObject:(SamplerState*)anObject;
|
||||
- (void)insertObject:(SamplerState*)anObject atIndex:(NSUInteger)index;
|
||||
|
||||
@end
|
@ -0,0 +1,46 @@
|
||||
//
|
||||
// SamplerStateCollection.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SamplerStateCollection.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
|
||||
@implementation SamplerStateCollection
|
||||
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
collection = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (int) count {
|
||||
return [collection count];
|
||||
}
|
||||
|
||||
- (SamplerState*)objectAtIndex:(NSUInteger)index {
|
||||
return (SamplerState*)[collection objectAtIndex:index];
|
||||
}
|
||||
|
||||
- (void)addObject:(SamplerState*)anObject {
|
||||
[collection addObject:anObject];
|
||||
}
|
||||
|
||||
- (void)insertObject:(SamplerState*)anObject atIndex:(NSUInteger)index {
|
||||
[collection insertObject:anObject atIndex:index];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[collection dealloc];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
@ -16,7 +16,7 @@
|
||||
int levelCount;
|
||||
}
|
||||
|
||||
- (id) initWithGraphicsDevice:(GraphicsDevice *)theGraphicsDevice SurfaceFormat:(SurfaceFormat)theFormat LevelCount:(int)theLevelCount;
|
||||
- (id) initWithGraphicsDevice:(GraphicsDevice *)theGraphicsDevice surfaceFormat:(SurfaceFormat)theFormat levelCount:(int)theLevelCount;
|
||||
|
||||
@property (nonatomic, readonly) uint textureId;
|
||||
@property (nonatomic) SurfaceFormat format;
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
@implementation Texture
|
||||
|
||||
- (id) initWithGraphicsDevice:(GraphicsDevice *)theGraphicsDevice SurfaceFormat:(SurfaceFormat)theFormat LevelCount:(int)theLevelCount {
|
||||
- (id) initWithGraphicsDevice:(GraphicsDevice *)theGraphicsDevice surfaceFormat:(SurfaceFormat)theFormat levelCount:(int)theLevelCount {
|
||||
if (self = [super initWithGraphicsDevice:theGraphicsDevice]) {
|
||||
format = theFormat;
|
||||
|
||||
|
@ -15,24 +15,24 @@
|
||||
int width;
|
||||
}
|
||||
|
||||
- (id) initWithGraphicsDevice:(GraphicsDevice*)theGraphicsDevice Width:(int)theWidth Height:(int)theHeight;
|
||||
- (id) initWithGraphicsDevice:(GraphicsDevice*)theGraphicsDevice Width:(int)theWidth Height:(int)theHeight MipMaps:(BOOL)generateMipMaps Format:(SurfaceFormat)theFormat;
|
||||
- (id) initWithGraphicsDevice:(GraphicsDevice*)theGraphicsDevice width:(int)theWidth height:(int)theHeight;
|
||||
- (id) initWithGraphicsDevice:(GraphicsDevice*)theGraphicsDevice width:(int)theWidth height:(int)theHeight mipMaps:(BOOL)generateMipMaps format:(SurfaceFormat)theFormat;
|
||||
|
||||
@property (nonatomic, readonly) Rectangle *bounds;
|
||||
@property (nonatomic, readonly) int height;
|
||||
@property (nonatomic, readonly) int width;
|
||||
|
||||
+ (Texture2D*) fromData:(NSData*)textureData GraphicsDevice:(GraphicsDevice*)graphicsDevice;
|
||||
//+ (Texture2D*) fromData:(NSData*)textureData GraphicsDevice:(GraphicsDevice*)graphicsDevice Width:(int)width Height:(int)height Zoom:(BOOL)zoom;
|
||||
+ (Texture2D*) fromData:(NSData*)textureData graphicsDevice:(GraphicsDevice*)graphicsDevice;
|
||||
//+ (Texture2D*) fromData:(NSData*)textureData graphicsDevice:(GraphicsDevice*)graphicsDevice width:(int)width height:(int)height zoom:(BOOL)zoom;
|
||||
|
||||
// - (void) getDataTo:(void *)data;
|
||||
// - (void) getDataTo:(void *)data StartIndex:(int)startIndex ElementCount:(int)elementCount;
|
||||
// - (void) getDataFromLevel:(int)level SourceRectangle:(Rectangle*)rect To:(void *)data StartIndex:(int)startIndex ElementCount:(int)elementCount;
|
||||
// - (void) getDataTo:(void *)data startIndex:(int)startIndex elementCount:(int)elementCount;
|
||||
// - (void) getDataFromLevel:(int)level sourceRectangle:(Rectangle*)rect to:(void *)data StartIndex:(int)startIndex elementCount:(int)elementCount;
|
||||
|
||||
- (void) setDataFrom:(void*)data;
|
||||
- (void) setDataToLevel:(int)level SourceRectangle:(Rectangle*)rect From:(void *)data;
|
||||
- (void) setDataToLevel:(int)level sourceRectangle:(Rectangle*)rect from:(void *)data;
|
||||
|
||||
// - (void) saveAsJpeg:(NSData*)textureData Width:(int)width Height:(int)height;
|
||||
// - (void) saveAsPng:(NSData*)textureData Width:(int)width Height:(int)height;
|
||||
// - (void) saveAsJpeg:(NSData*)textureData width:(int)width height:(int)height;
|
||||
// - (void) saveAsPng:(NSData*)textureData width:(int)width height:(int)height;
|
||||
|
||||
@end
|
||||
|
@ -15,15 +15,15 @@
|
||||
|
||||
@implementation Texture2D
|
||||
|
||||
- (id) initWithGraphicsDevice:(GraphicsDevice*)theGraphicsDevice Width:(int)theWidth Height:(int)theHeight {
|
||||
return [self initWithGraphicsDevice:theGraphicsDevice Width:theWidth Height:theHeight MipMaps:NO Format:SurfaceFormatColor];
|
||||
- (id) initWithGraphicsDevice:(GraphicsDevice*)theGraphicsDevice width:(int)theWidth height:(int)theHeight {
|
||||
return [self initWithGraphicsDevice:theGraphicsDevice width:theWidth height:theHeight mipMaps:NO format:SurfaceFormatColor];
|
||||
}
|
||||
|
||||
- (id) initWithGraphicsDevice:(GraphicsDevice *)theGraphicsDevice
|
||||
Width:(int)theWidth
|
||||
Height:(int)theHeight
|
||||
MipMaps:(BOOL)generateMipMaps
|
||||
Format:(SurfaceFormat)theFormat {
|
||||
width:(int)theWidth
|
||||
height:(int)theHeight
|
||||
mipMaps:(BOOL)generateMipMaps
|
||||
format:(SurfaceFormat)theFormat {
|
||||
int theLevelCount = 1;
|
||||
if (generateMipMaps) {
|
||||
int side = MIN(theWidth, theHeight);
|
||||
@ -32,7 +32,7 @@
|
||||
theLevelCount++;
|
||||
}
|
||||
}
|
||||
if (self = [super initWithGraphicsDevice:theGraphicsDevice SurfaceFormat:theFormat LevelCount:theLevelCount]) {
|
||||
if (self = [super initWithGraphicsDevice:theGraphicsDevice surfaceFormat:theFormat levelCount:theLevelCount]) {
|
||||
width = theWidth;
|
||||
height = theHeight;
|
||||
textureId = [graphicsDevice createTexture];
|
||||
@ -41,14 +41,14 @@
|
||||
}
|
||||
|
||||
- (Rectangle*) bounds {
|
||||
return [Rectangle rectangleWithX:0 Y:0 Width:width Height:height];
|
||||
return [Rectangle rectangleWithX:0 y:0 width:width height:height];
|
||||
}
|
||||
|
||||
@synthesize width;
|
||||
@synthesize height;
|
||||
|
||||
|
||||
+ (Texture2D*) fromData:(NSData*)textureData GraphicsDevice:(GraphicsDevice*)graphicsDevice {
|
||||
+ (Texture2D*) fromData:(NSData*)textureData graphicsDevice:(GraphicsDevice*)graphicsDevice {
|
||||
if (graphicsDevice == nil) {
|
||||
[NSException raise:@"ArgumentNullException" format:@"The graphics device cannot be null."];
|
||||
}
|
||||
@ -71,7 +71,7 @@
|
||||
CGContextTranslateCTM(textureContext, 0, 0);
|
||||
CGContextDrawImage(textureContext, CGRectMake(0, 0, width, height), image.CGImage);
|
||||
|
||||
Texture2D *texture = [[Texture2D alloc] initWithGraphicsDevice:graphicsDevice Width:(int)width Height:(int)height];
|
||||
Texture2D *texture = [[Texture2D alloc] initWithGraphicsDevice:graphicsDevice width:(int)width height:(int)height];
|
||||
[texture setDataFrom:imageData];
|
||||
|
||||
CGContextRelease(textureContext);
|
||||
@ -86,7 +86,7 @@
|
||||
}
|
||||
|
||||
|
||||
- (void) setDataToLevel:(int)level SourceRectangle:(Rectangle*)rect From:(void *)data {
|
||||
- (void) setDataToLevel:(int)level sourceRectangle:(Rectangle*)rect from:(void *)data {
|
||||
[graphicsDevice setData:data toTexture2D:self SourceRectangle:rect level:level];
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
//
|
||||
// TextureCollection.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.classes.h"
|
||||
|
||||
@interface TextureCollection : NSObject {
|
||||
NSMutableArray *collection;
|
||||
}
|
||||
|
||||
- (int) count;
|
||||
- (Texture*)objectAtIndex:(NSUInteger)index;
|
||||
- (void)addObject:(Texture*)anObject;
|
||||
- (void)insertObject:(Texture*)anObject atIndex:(NSUInteger)index;
|
||||
|
||||
@end
|
@ -0,0 +1,46 @@
|
||||
//
|
||||
// TextureCollection.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TextureCollection.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
|
||||
@implementation TextureCollection
|
||||
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
collection = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (int) count {
|
||||
return [collection count];
|
||||
}
|
||||
|
||||
- (Texture*)objectAtIndex:(NSUInteger)index {
|
||||
return (Texture*)[collection objectAtIndex:index];
|
||||
}
|
||||
|
||||
- (void)addObject:(Texture*)anObject {
|
||||
[collection addObject:anObject];
|
||||
}
|
||||
|
||||
- (void)insertObject:(Texture*)anObject atIndex:(NSUInteger)index {
|
||||
[collection insertObject:anObject atIndex:index];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[collection dealloc];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
@ -14,11 +14,11 @@
|
||||
Vector4Struct data;
|
||||
}
|
||||
|
||||
- (id) initWithX:(float)x Y:(float)y Z:(float)z W:(float)w;
|
||||
- (id) initWithX:(float)x y:(float)y z:(float)z w:(float)w;
|
||||
- (id) initWithStruct: (Vector4Struct*)vectorData;
|
||||
- (id) initWithVector: (Vector4*)vector;
|
||||
|
||||
+ (Vector4*) vectorWithX:(float)x Y:(float)y Z:(float)z W:(float)w;
|
||||
+ (Vector4*) vectorWithX:(float)x y:(float)y z:(float)z w:(float)w;
|
||||
+ (Vector4*) vectorWithStruct: (Vector4Struct*)vectorData;
|
||||
+ (Vector4*) vectorWithVector: (Vector4*)vector;
|
||||
|
||||
|
28
Classes/Retronator/Xni/Framework/Graphics/VertexArray.h
Normal file
28
Classes/Retronator/Xni/Framework/Graphics/VertexArray.h
Normal file
@ -0,0 +1,28 @@
|
||||
//
|
||||
// VertexArray.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "System.classes.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.classes.h"
|
||||
|
||||
@interface VertexArray : NSObject {
|
||||
AdaptiveArray *array;
|
||||
}
|
||||
|
||||
- (id) initWithItemSize:(int)itemSize initialCapacity:(int)initialCapacity;
|
||||
|
||||
@property (nonatomic, readonly) void *array;
|
||||
@property (nonatomic, readonly) int count;
|
||||
@property (nonatomic, readonly) int sizeInBytes;
|
||||
@property (nonatomic, readonly) VertexDeclaration *vertexDeclaration;
|
||||
|
||||
- (void) clear;
|
||||
- (void) addVertex:(void*)vertex;
|
||||
|
||||
@end
|
50
Classes/Retronator/Xni/Framework/Graphics/VertexArray.m
Normal file
50
Classes/Retronator/Xni/Framework/Graphics/VertexArray.m
Normal file
@ -0,0 +1,50 @@
|
||||
//
|
||||
// VertexArray.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "VertexArray.h"
|
||||
#import "System.h"
|
||||
|
||||
@implementation VertexArray
|
||||
|
||||
- (id) initWithItemSize:(int)itemSize initialCapacity:(int)initialCapacity {
|
||||
if (self = [super init]) {
|
||||
array = [[AdaptiveArray alloc] initWithItemSize:itemSize initialCapacity:initialCapacity];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void *) array {
|
||||
return array.array;
|
||||
}
|
||||
|
||||
- (int) count {
|
||||
return array.count;
|
||||
}
|
||||
|
||||
- (int) sizeInBytes {
|
||||
return array.count * array.itemSize;
|
||||
}
|
||||
|
||||
- (VertexDeclaration *) vertexDeclaration { return nil; }
|
||||
|
||||
- (void) clear {
|
||||
[array clear];
|
||||
}
|
||||
|
||||
- (void) addVertex:(void *)vertex {
|
||||
[array addItem:vertex];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[array release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
|
21
Classes/Retronator/Xni/Framework/Graphics/VertexBuffer.h
Normal file
21
Classes/Retronator/Xni/Framework/Graphics/VertexBuffer.h
Normal file
@ -0,0 +1,21 @@
|
||||
//
|
||||
// VertexBuffer.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "GraphicsResource.h"
|
||||
|
||||
@interface VertexBuffer : GraphicsResource {
|
||||
uint bufferId;
|
||||
VertexDeclaration *vertexDeclaration;
|
||||
}
|
||||
|
||||
@property (nonatomic, readonly) uint bufferId;
|
||||
@property (nonatomic, readonly) VertexDeclaration *vertexDeclaration;
|
||||
|
||||
@end
|
17
Classes/Retronator/Xni/Framework/Graphics/VertexBuffer.m
Normal file
17
Classes/Retronator/Xni/Framework/Graphics/VertexBuffer.m
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// VertexBuffer.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "VertexBuffer.h"
|
||||
|
||||
|
||||
@implementation VertexBuffer
|
||||
|
||||
@synthesize bufferId;
|
||||
@synthesize vertexDeclaration;
|
||||
|
||||
@end
|
@ -0,0 +1,27 @@
|
||||
//
|
||||
// VertexBufferBinding.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.classes.h"
|
||||
|
||||
@interface VertexBufferBinding : NSObject {
|
||||
int instanceFrequency;
|
||||
VertexBuffer *vertexBuffer;
|
||||
int vertexOffset;
|
||||
}
|
||||
|
||||
- (id) initWithVertexBuffer:(VertexBuffer*)theVertexBuffer;
|
||||
- (id) initWithVertexBuffer:(VertexBuffer*)theVertexBuffer vertexOffset:(int)theVertexOffset;
|
||||
- (id) initWithVertexBuffer:(VertexBuffer*)theVertexBuffer vertexOffset:(int)theVertexOffset instanceFrequency:(int)theInstanceFrequency;
|
||||
|
||||
@property (nonatomic, readonly) int instanceFrequency;
|
||||
@property (nonatomic, readonly) VertexBuffer *vertexBuffer;
|
||||
@property (nonatomic, readonly) int vertexOffset;
|
||||
|
||||
@end
|
@ -0,0 +1,43 @@
|
||||
//
|
||||
// VertexBufferBinding.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "VertexBufferBinding.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
|
||||
@implementation VertexBufferBinding
|
||||
|
||||
- (id) initWithVertexBuffer:(VertexBuffer *)theVertexBuffer {
|
||||
return [self initWithVertexBuffer:theVertexBuffer vertexOffset:0 instanceFrequency:0];
|
||||
}
|
||||
|
||||
- (id) initWithVertexBuffer:(VertexBuffer *)theVertexBuffer vertexOffset:(int)theVertexOffset {
|
||||
return [self initWithVertexBuffer:theVertexBuffer vertexOffset:theVertexOffset instanceFrequency:0];
|
||||
}
|
||||
|
||||
- (id) initWithVertexBuffer:(VertexBuffer *)theVertexBuffer vertexOffset:(int)theVertexOffset instanceFrequency:(int)theInstanceFrequency {
|
||||
if (self = [super init]) {
|
||||
vertexBuffer = [theVertexBuffer retain];
|
||||
vertexOffset = theVertexOffset;
|
||||
instanceFrequency = theInstanceFrequency;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@synthesize instanceFrequency;
|
||||
@synthesize vertexBuffer;
|
||||
@synthesize vertexOffset;
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[vertexBuffer release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
@ -0,0 +1,23 @@
|
||||
//
|
||||
// VertexDeclaration.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "GraphicsResource.h"
|
||||
|
||||
@interface VertexDeclaration : GraphicsResource {
|
||||
NSArray *vertexElements;
|
||||
int vertexStride;
|
||||
}
|
||||
|
||||
- (id) initWithElements:(NSArray*)theVertexElements;
|
||||
|
||||
@property (nonatomic, readonly) NSArray *vertexElements;
|
||||
@property (nonatomic, readonly) int vertexStride;
|
||||
|
||||
@end
|
@ -0,0 +1,37 @@
|
||||
//
|
||||
// VertexDeclaration.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "VertexDeclaration.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
|
||||
@implementation VertexDeclaration
|
||||
|
||||
- (id) initWithElements:(NSArray *)theVertexElements {
|
||||
if (self = [super init]) {
|
||||
vertexElements = [theVertexElements retain];
|
||||
|
||||
vertexStride = 0;
|
||||
for (VertexElement* vertexElement in vertexElements) {
|
||||
vertexStride += [vertexElement getSize];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@synthesize vertexElements;
|
||||
@synthesize vertexStride;
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[vertexElements release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
|
39
Classes/Retronator/Xni/Framework/Graphics/VertexElement.h
Normal file
39
Classes/Retronator/Xni/Framework/Graphics/VertexElement.h
Normal file
@ -0,0 +1,39 @@
|
||||
//
|
||||
// VertexElement.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.classes.h"
|
||||
|
||||
@interface VertexElement : NSObject {
|
||||
int offset;
|
||||
int usageIndex;
|
||||
VertexElementFormat vertexElementFormat;
|
||||
VertexElementUsage vertexElementUsage;
|
||||
}
|
||||
|
||||
- (id) initWithOffset:(int)theOffset format:(VertexElementFormat)elementFormat
|
||||
usage:(VertexElementUsage)elementUsage usageIndex:(Byte)theUsageIndex;
|
||||
|
||||
+ (VertexElement*) vertexElementWithOffset:(int)theOffset format:(VertexElementFormat)elementFormat
|
||||
usage:(VertexElementUsage)elementUsage usageIndex:(Byte)theUsageIndex;
|
||||
|
||||
@property (nonatomic) int offset;
|
||||
@property (nonatomic) int usageIndex;
|
||||
@property (nonatomic) VertexElementFormat vertexElementFormat;
|
||||
@property (nonatomic) VertexElementUsage vertexElementUsage;
|
||||
|
||||
+ (int) getSizeForFormat:(VertexElementFormat)format;
|
||||
+ (int) getValueDimensionsForFormat:(VertexElementFormat)format;
|
||||
+ (DataType) getValueDataTypeForFormat:(VertexElementFormat)format;
|
||||
|
||||
- (int) getSize;
|
||||
- (int) getValueDimensions;
|
||||
- (DataType) getValueDataType;
|
||||
|
||||
@end
|
102
Classes/Retronator/Xni/Framework/Graphics/VertexElement.m
Normal file
102
Classes/Retronator/Xni/Framework/Graphics/VertexElement.m
Normal file
@ -0,0 +1,102 @@
|
||||
//
|
||||
// VertexElement.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "VertexElement.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
|
||||
@implementation VertexElement
|
||||
|
||||
- (id) initWithOffset:(int)theOffset format:(VertexElementFormat)elementFormat
|
||||
usage:(VertexElementUsage)elementUsage usageIndex:(Byte)theUsageIndex {
|
||||
if (self = [super init]) {
|
||||
offset = theOffset;
|
||||
vertexElementFormat = elementFormat;
|
||||
vertexElementUsage = elementUsage;
|
||||
usageIndex = theUsageIndex;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (VertexElement*) vertexElementWithOffset:(int)theOffset format:(VertexElementFormat)elementFormat
|
||||
usage:(VertexElementUsage)elementUsage usageIndex:(Byte)theUsageIndex {
|
||||
return [[[VertexElement alloc] initWithOffset:theOffset format:elementFormat
|
||||
usage:elementUsage usageIndex:theUsageIndex] autorelease];
|
||||
}
|
||||
|
||||
@synthesize offset;
|
||||
@synthesize usageIndex;
|
||||
@synthesize vertexElementFormat;
|
||||
@synthesize vertexElementUsage;
|
||||
|
||||
+ (int) getSizeForFormat:(VertexElementFormat)format {
|
||||
switch (format) {
|
||||
case VertexElementFormatSingle:
|
||||
return sizeof(float);
|
||||
case VertexElementFormatVector2:
|
||||
return sizeof(Vector2Struct);
|
||||
case VertexElementFormatVector3:
|
||||
return sizeof(Vector3Struct);
|
||||
case VertexElementFormatVector4:
|
||||
return sizeof(Vector4Struct);
|
||||
case VertexElementFormatColor:
|
||||
return sizeof(uint);
|
||||
default:
|
||||
[NSException raise:@"NotImplementedException" format:@"The vertex element format %i is not yet implemented.", format];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
+ (int) getValueDimensionsForFormat:(VertexElementFormat)format {
|
||||
switch (format) {
|
||||
case VertexElementFormatSingle:
|
||||
return 1;
|
||||
case VertexElementFormatVector2:
|
||||
return 2;
|
||||
case VertexElementFormatVector3:
|
||||
return 3;
|
||||
case VertexElementFormatVector4:
|
||||
return 4;
|
||||
case VertexElementFormatColor:
|
||||
return 4;
|
||||
default:
|
||||
[NSException raise:@"NotImplementedException" format:@"The vertex element format %i is not yet implemented.", format];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
+ (DataType) getValueDataTypeForFormat:(VertexElementFormat)format {
|
||||
switch (format) {
|
||||
case VertexElementFormatSingle:
|
||||
return DataTypeFloat;
|
||||
case VertexElementFormatVector2:
|
||||
return DataTypeFloat;
|
||||
case VertexElementFormatVector3:
|
||||
return DataTypeFloat;
|
||||
case VertexElementFormatVector4:
|
||||
return DataTypeFloat;
|
||||
case VertexElementFormatColor:
|
||||
return DataTypeUnsignedByte;
|
||||
default:
|
||||
[NSException raise:@"NotImplementedException" format:@"The vertex element format %i is not yet implemented.", format];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
- (int) getSize {
|
||||
return [VertexElement getSizeForFormat:vertexElementFormat];
|
||||
}
|
||||
|
||||
- (int) getValueDimensions {
|
||||
return [VertexElement getValueDimensionsForFormat:vertexElementFormat];
|
||||
}
|
||||
|
||||
- (DataType) getValueDataType {
|
||||
return [VertexElement getValueDataTypeForFormat:vertexElementFormat];
|
||||
}
|
||||
@end
|
@ -0,0 +1,19 @@
|
||||
//
|
||||
// VertexPositionColor.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "VertexElement.h"
|
||||
|
||||
@interface VertexPositionColor : VertexElement {
|
||||
|
||||
}
|
||||
|
||||
+ (VertexDeclaration*) vertexDeclaration;
|
||||
|
||||
@end
|
@ -0,0 +1,35 @@
|
||||
//
|
||||
// VertexPositionColor.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "VertexPositionColor.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
|
||||
@implementation VertexPositionColor
|
||||
|
||||
VertexDeclaration *vertexDeclaration;
|
||||
|
||||
+ (void) initialize {
|
||||
NSArray *vertexElements = [NSArray arrayWithObjects:
|
||||
[VertexElement vertexElementWithOffset:offsetof(VertexPositionColorStruct, position)
|
||||
format:VertexElementFormatVector3
|
||||
usage:VertexElementUsagePosition
|
||||
usageIndex:0],
|
||||
[VertexElement vertexElementWithOffset:offsetof(VertexPositionColorStruct, color)
|
||||
format:VertexElementFormatColor
|
||||
usage:VertexElementUsageColor
|
||||
usageIndex:0], nil];
|
||||
|
||||
vertexDeclaration = [[VertexDeclaration alloc] initWithElements:vertexElements];
|
||||
}
|
||||
|
||||
+ (VertexDeclaration *) vertexDeclaration {
|
||||
return vertexDeclaration;
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,21 @@
|
||||
//
|
||||
// VertexPositionColorArray.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "VertexArray.h"
|
||||
|
||||
@interface VertexPositionColorArray : VertexArray {
|
||||
|
||||
}
|
||||
|
||||
- (id) initWithInitialCapacity:(int)initialCapacity;
|
||||
|
||||
- (void) addVertex:(VertexPositionColorStruct*)vertex;
|
||||
|
||||
@end
|
@ -0,0 +1,29 @@
|
||||
//
|
||||
// VertexPositionColorArray.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "VertexPositionColorArray.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
|
||||
@implementation VertexPositionColorArray
|
||||
|
||||
- (id) initWithInitialCapacity:(int)initialCapacity {
|
||||
if (self = [super initWithItemSize:sizeof(VertexPositionColorStruct) initialCapacity:initialCapacity]) {
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (VertexDeclaration *) vertexDeclaration {
|
||||
return [VertexPositionColor vertexDeclaration];
|
||||
}
|
||||
|
||||
- (void) addVertex:(VertexPositionColorStruct*)vertex {
|
||||
[super addVertex:vertex];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,19 @@
|
||||
//
|
||||
// VertexPositionTexture.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "VertexElement.h"
|
||||
|
||||
@interface VertexPositionTexture : VertexElement {
|
||||
|
||||
}
|
||||
|
||||
+ (VertexDeclaration*) vertexDeclaration;
|
||||
|
||||
@end
|
@ -0,0 +1,35 @@
|
||||
//
|
||||
// VertexPositionTexture.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "VertexPositionTexture.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
|
||||
@implementation VertexPositionTexture
|
||||
|
||||
VertexDeclaration *vertexDeclaration;
|
||||
|
||||
+ (void) initialize {
|
||||
NSArray *vertexElements = [NSArray arrayWithObjects:
|
||||
[VertexElement vertexElementWithOffset:offsetof(VertexPositionTextureStruct, position)
|
||||
format:VertexElementFormatVector3
|
||||
usage:VertexElementUsagePosition
|
||||
usageIndex:0],
|
||||
[VertexElement vertexElementWithOffset:offsetof(VertexPositionTextureStruct, texture)
|
||||
format:VertexElementFormatVector2
|
||||
usage:VertexElementUsageTextureCoordinate
|
||||
usageIndex:0], nil];
|
||||
|
||||
vertexDeclaration = [[VertexDeclaration alloc] initWithElements:vertexElements];
|
||||
}
|
||||
|
||||
+ (VertexDeclaration *) vertexDeclaration {
|
||||
return vertexDeclaration;
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,21 @@
|
||||
//
|
||||
// VertexPositionTextureArray.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "VertexArray.h"
|
||||
|
||||
@interface VertexPositionTextureArray : VertexArray {
|
||||
|
||||
}
|
||||
|
||||
- (id) initWithInitialCapacity:(int)initialCapacity;
|
||||
|
||||
- (void) addVertex:(VertexPositionTextureStruct*)vertex;
|
||||
|
||||
@end
|
@ -0,0 +1,29 @@
|
||||
//
|
||||
// VertexPositionTextureArray.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "VertexPositionTextureArray.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
|
||||
@implementation VertexPositionTextureArray
|
||||
|
||||
- (id) initWithInitialCapacity:(int)initialCapacity {
|
||||
if (self = [super initWithItemSize:sizeof(VertexPositionTextureStruct) initialCapacity:initialCapacity]) {
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (VertexDeclaration *) vertexDeclaration {
|
||||
return [VertexPositionTexture vertexDeclaration];
|
||||
}
|
||||
|
||||
- (void) addVertex:(VertexPositionTextureStruct*)vertex {
|
||||
[super addVertex:vertex];
|
||||
}
|
||||
|
||||
@end
|
29
Classes/Retronator/Xni/Framework/Graphics/VertexStructs.h
Normal file
29
Classes/Retronator/Xni/Framework/Graphics/VertexStructs.h
Normal file
@ -0,0 +1,29 @@
|
||||
#import "Retronator.Xni.Framework.classes.h"
|
||||
|
||||
typedef struct {
|
||||
Vector3Struct position;
|
||||
uint color;
|
||||
} VertexPositionColorStruct;
|
||||
|
||||
typedef struct {
|
||||
Vector3Struct position;
|
||||
Vector2Struct texture;
|
||||
} VertexPositionTextureStruct;
|
||||
|
||||
typedef struct {
|
||||
Vector3Struct position;
|
||||
Vector3Struct normal;
|
||||
Vector2Struct texture;
|
||||
} VertexPositionNormalTextureStruct;
|
||||
|
||||
typedef struct {
|
||||
Vector3Struct position;
|
||||
uint color;
|
||||
float size;
|
||||
} VertexPositionColorSizeStruct;
|
||||
|
||||
typedef struct {
|
||||
Vector3Struct position;
|
||||
uint color;
|
||||
Vector2Struct texture;
|
||||
} VertexPositionColorTextureStruct;
|
@ -17,7 +17,7 @@
|
||||
- (id) initWithStruct: (MatrixStruct*)matrixData;
|
||||
- (id) initWithMatrix: (Matrix*)matrix;
|
||||
|
||||
+ (Matrix*) matrixWithData: (MatrixStruct*)matrixData;
|
||||
+ (Matrix*) matrixWithStruct: (MatrixStruct*)matrixData;
|
||||
+ (Matrix*) matrixWithMatrix: (Matrix*)matrix;
|
||||
|
||||
+ (Matrix*) translation:(Vector3*)position;
|
||||
|
@ -8,7 +8,198 @@
|
||||
|
||||
#import "Matrix.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.h"
|
||||
|
||||
@implementation Matrix
|
||||
|
||||
- (id) initWithStruct: (MatrixStruct*)matrixStruct {
|
||||
if (self = [super init]) {
|
||||
data = *matrixStruct;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithMatrix: (Matrix*)matrix {
|
||||
return [self initWithStruct:matrix.data];
|
||||
}
|
||||
|
||||
+ (Matrix*) matrixWithStruct: (MatrixStruct*)matrixStruct {
|
||||
return [[[Matrix alloc] initWithStruct:matrixStruct] autorelease];
|
||||
}
|
||||
|
||||
+ (Matrix*) matrixWithMatrix: (Matrix*)matrix {
|
||||
return [[[Matrix alloc] initWithMatrix:matrix] autorelease];
|
||||
}
|
||||
|
||||
+ (Matrix*) translation:(Vector3*)position {
|
||||
Matrix *matrix = [Matrix identity];
|
||||
matrix.translation = position;
|
||||
return matrix;
|
||||
}
|
||||
|
||||
+ (Matrix*) scale:(Vector3 *)scale {
|
||||
Matrix *matrix = [Matrix identity];
|
||||
matrix.data->m11= scale.x;
|
||||
matrix.data->m22= scale.y;
|
||||
matrix.data->m33= scale.z;
|
||||
return matrix;
|
||||
}
|
||||
|
||||
+ (Matrix*) rotationAround:(Vector3 *)axis for:(float)angle {
|
||||
Vector3 *normalizedAxis = [[Vector3 vectorWithVector:axis] normalize];
|
||||
|
||||
float c = cosf(angle);
|
||||
float s = sinf(angle);
|
||||
float x = normalizedAxis.x;
|
||||
float y = normalizedAxis.y;
|
||||
float z = normalizedAxis.z;
|
||||
|
||||
Matrix *matrix = [Matrix zero];
|
||||
matrix.data->m11 = (x * x) * (1 - c) + c;
|
||||
matrix.data->m12 = (y * x) * (1 - c) + (z * s);
|
||||
matrix.data->m13 = (x * z) * (1 - c) - (y * s);
|
||||
matrix.data->m21 = (x * y) * (1 - c) - (z * s);
|
||||
matrix.data->m22 = (y * y) * (1 - c) + c;
|
||||
matrix.data->m23 = (y * z) * (1 - c) + (x * s);
|
||||
matrix.data->m31 = (x * z) * (1 - c) + (y * s);
|
||||
matrix.data->m32 = (y * z) * (1 - c) - (x * s);
|
||||
matrix.data->m33 = (z * z) * (1 - c) + c;
|
||||
matrix.data->m44 = 1;
|
||||
return matrix;
|
||||
}
|
||||
|
||||
+ (Matrix*) rotationWithQuaternion:(Quaternion *)quaternion {
|
||||
Quaternion *normalizedQuaternion = [[Quaternion quaternionWithQuaternion:quaternion] normalize];
|
||||
|
||||
float x = normalizedQuaternion.x;
|
||||
float y = normalizedQuaternion.y;
|
||||
float z = normalizedQuaternion.z;
|
||||
float w = normalizedQuaternion.w;
|
||||
|
||||
Matrix *matrix = [Matrix zero];
|
||||
matrix.data->m11 = 1 - 2 * ( y * y + z * z );
|
||||
matrix.data->m12 = 2 * ( x * y - z * w );
|
||||
matrix.data->m13 = 2 * ( x * z + y * w );
|
||||
matrix.data->m21 = 2 * ( x * y + z * w );
|
||||
matrix.data->m22 = 1 - 2 * ( x * x + z * z );
|
||||
matrix.data->m23 = 2 * ( y * z - x * w );
|
||||
matrix.data->m31 = 2 * ( x * z - y * w );
|
||||
matrix.data->m32 = 2 * ( y * z + x * w );
|
||||
matrix.data->m33 = 1 - 2 * ( x * x + y * y );
|
||||
matrix.data->m44 = 1;
|
||||
return matrix;
|
||||
}
|
||||
|
||||
+ (Matrix*) lookAt:(Vector3*)target from:(Vector3*)position up:(Vector3*)up {
|
||||
Vector3 *z = [[Vector3 subtract:position by:target] normalize];
|
||||
Vector3 *x = [[Vector3 crossProductOf:up with:z] normalize];
|
||||
Vector3 *y = [Vector3 crossProductOf:z with:x];
|
||||
Matrix *matrix = [Matrix zero];
|
||||
// First column
|
||||
matrix.data->m11 = x.x;
|
||||
matrix.data->m21 = x.y;
|
||||
matrix.data->m31 = x.z;
|
||||
// Second column
|
||||
matrix.data->m12 = y.x;
|
||||
matrix.data->m22 = y.y;
|
||||
matrix.data->m32 = y.z;
|
||||
// Third column
|
||||
matrix.data->m13 = z.x;
|
||||
matrix.data->m23 = z.y;
|
||||
matrix.data->m33 = z.z;
|
||||
// Translation
|
||||
matrix.data->m41 = -[Vector3 dotProductOf:x with:position];
|
||||
matrix.data->m42 = -[Vector3 dotProductOf:y with:position];
|
||||
matrix.data->m43 = -[Vector3 dotProductOf:z with:position];
|
||||
matrix.data->m44 = 1;
|
||||
return matrix;
|
||||
}
|
||||
|
||||
+ (Matrix*) perspectiveWithWidth:(float)width height:(float)height nearPlane:(float)nearPlane farPlane:(float)farPlane {
|
||||
Matrix *matrix = [Matrix zero];
|
||||
matrix.data->m11 = (2 * nearPlane) / width;
|
||||
matrix.data->m22 = (2 * nearPlane) / height;
|
||||
matrix.data->m33 = farPlane / (nearPlane - farPlane);
|
||||
matrix.data->m34 = -1;
|
||||
matrix.data->m43 = nearPlane * farPlane / (nearPlane - farPlane);
|
||||
return matrix;
|
||||
}
|
||||
|
||||
+ (Matrix*) perspectiveWithFieldOfView:(float)fieldOfView aspectRatio:(float)aspectRatio nearPlane:(float)nearPlane farPlane:(float)farPlane{
|
||||
float width = 2 * nearPlane * tanf(fieldOfView * 0.5f);
|
||||
float height = width / aspectRatio;
|
||||
return [Matrix perspectiveWithWidth:width height:height nearPlane:nearPlane farPlane:farPlane];
|
||||
}
|
||||
|
||||
+ (Matrix*) worldAt:(Vector3 *)position forward:(Vector3 *)forward up:(Vector3 *)up {
|
||||
Vector3 *z = [[Vector3 negate:forward] normalize];
|
||||
Vector3 *x = [[Vector3 crossProductOf:up with:z] normalize];
|
||||
Vector3 *y = [Vector3 crossProductOf:z with:x];
|
||||
Matrix *matrix = [Matrix identity];
|
||||
matrix.right = x;
|
||||
matrix.up = y;
|
||||
matrix.backward = z;
|
||||
matrix.translation = position;
|
||||
return matrix;
|
||||
}
|
||||
|
||||
// PROPERTIES
|
||||
|
||||
- (MatrixStruct*) data {return &data;}
|
||||
|
||||
// Main rows
|
||||
|
||||
- (Vector3 *) right {return [Vector3 vectorWithX:data.m11 y:data.m12 z:data.m13];}
|
||||
- (void) setRight:(Vector3 *)value {data.m11 = value.x; data.m12 = value.y; data.m13 = value.z;}
|
||||
|
||||
- (Vector3 *) up {return [Vector3 vectorWithX:data.m21 y:data.m22 z:data.m23];}
|
||||
- (void) setUp:(Vector3 *)value {data.m21 = value.x; data.m22 = value.y; data.m23 = value.z;}
|
||||
|
||||
- (Vector3 *) backward {return [Vector3 vectorWithX:data.m31 y:data.m32 z:data.m33];}
|
||||
- (void) setBackward:(Vector3 *)value {data.m31 = value.x; data.m32 = value.y; data.m33 = value.z;}
|
||||
|
||||
- (Vector3 *) translation {return [Vector3 vectorWithX:data.m41 y:data.m42 z:data.m43];}
|
||||
- (void) setTranslation:(Vector3 *)value {data.m41 = value.x; data.m42 = value.y; data.m43 = value.z;}
|
||||
|
||||
// Negative rows
|
||||
|
||||
- (Vector3 *) left {return [Vector3 vectorWithX:-data.m11 y:-data.m12 z:-data.m13];}
|
||||
- (void) setLeft:(Vector3 *)value {data.m11 = -value.x; data.m12 = -value.y; data.m13 = -value.z;}
|
||||
|
||||
- (Vector3 *) down {return [Vector3 vectorWithX:-data.m21 y:-data.m22 z:-data.m23];}
|
||||
- (void) setDown:(Vector3 *)value {data.m21 = -value.x; data.m22 = -value.y; data.m23 = -value.z;}
|
||||
|
||||
- (Vector3 *) forward {return [Vector3 vectorWithX:-data.m31 y:-data.m32 z:-data.m33];}
|
||||
- (void) setForward:(Vector3 *)value {data.m31 = -value.x; data.m32 = -value.y; data.m33 = -value.z;}
|
||||
|
||||
// METHODS
|
||||
|
||||
- (Matrix*) transpose {
|
||||
MatrixTranspose(self.data);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (Matrix*) inverse {
|
||||
MatrixInverse(self.data);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (Matrix*) multiplyWith:(Matrix*)value {
|
||||
MatrixStruct result;
|
||||
MatrixMultiply(self.data, value.data, &result);
|
||||
data = result;
|
||||
return self;
|
||||
}
|
||||
|
||||
// CONSTANTS
|
||||
|
||||
+ (id) zero {
|
||||
MatrixStruct MatrixStruct = MatrixMake(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
return [Matrix matrixWithStruct:&MatrixStruct];
|
||||
}
|
||||
+ (id) identity {
|
||||
MatrixStruct MatrixStruct = MatrixMake(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
return [Matrix matrixWithStruct:&MatrixStruct];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -14,7 +14,7 @@
|
||||
Vector4Struct data;
|
||||
}
|
||||
|
||||
- (id) initWithX:(float)x Y:(float)y Z:(float)z W:(float)w;
|
||||
- (id) initWithX:(float)x y:(float)y z:(float)z w:(float)w;
|
||||
- (id) initWithVectorPart:(Vector3*)vector scalarPart:(float)scalar;
|
||||
- (id) initWithStruct: (Vector4Struct*)quaternionData;
|
||||
- (id) initWithQuaternion: (Quaternion*)quaternion;
|
||||
|
@ -15,11 +15,11 @@
|
||||
RectangleStruct data;
|
||||
}
|
||||
|
||||
- (id) initWithX:(int)x Y:(int)y Width:(int)width Height:(int)height;
|
||||
- (id) initWithX:(int)x y:(int)y width:(int)width height:(int)height;
|
||||
- (id) initWithStruct:(RectangleStruct*) rectangleStruct;
|
||||
- (id) initWithRectangle:(Rectangle*) rectangle;
|
||||
|
||||
+ (Rectangle*) rectangleWithX:(int)x Y:(int)y Width:(int)width Height:(int)height;
|
||||
+ (Rectangle*) rectangleWithX:(int)x y:(int)y width:(int)width height:(int)height;
|
||||
+ (Rectangle*) rectangleWithStruct:(RectangleStruct*) rectangleStruct;
|
||||
+ (Rectangle*) rectangleWithRectangle:(Rectangle*) rectangle;
|
||||
+ (Rectangle*) rectangleWithCGRect:(CGRect) cgRect;
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
// CONSTRUCTORS
|
||||
|
||||
- (id) initWithX:(int)x Y:(int)y Width:(int)width Height:(int)height {
|
||||
- (id) initWithX:(int)x y:(int)y width:(int)width height:(int)height {
|
||||
if (self = [super init]) {
|
||||
data = RectangleMake(x, y, width, height);
|
||||
}
|
||||
@ -31,8 +31,8 @@
|
||||
return [self initWithStruct:rectangle.data];
|
||||
}
|
||||
|
||||
+ (Rectangle*) rectangleWithX:(int)x Y:(int)y Width:(int)width Height:(int)height {
|
||||
return [[[Rectangle alloc] initWithX:x Y:y Width:width Height:height] autorelease];
|
||||
+ (Rectangle*) rectangleWithX:(int)x y:(int)y width:(int)width height:(int)height {
|
||||
return [[[Rectangle alloc] initWithX:x y:y width:width height:height] autorelease];
|
||||
}
|
||||
|
||||
+ (Rectangle*) rectangleWithStruct:(RectangleStruct*) rectangleStruct {
|
||||
@ -44,8 +44,8 @@
|
||||
}
|
||||
|
||||
+ (Rectangle*) rectangleWithCGRect:(CGRect) cgRect {
|
||||
return [Rectangle rectangleWithX:cgRect.origin.x Y:cgRect.origin.y
|
||||
Width:cgRect.size.width Height:cgRect.size.height];
|
||||
return [Rectangle rectangleWithX:cgRect.origin.x y:cgRect.origin.y
|
||||
width:cgRect.size.width height:cgRect.size.height];
|
||||
}
|
||||
|
||||
// PROPERTIES
|
||||
@ -84,6 +84,6 @@
|
||||
|
||||
// CONSTANTS
|
||||
|
||||
+ (Rectangle*) empty {return [Rectangle rectangleWithX:0 Y:0 Width:0 Height:0];}
|
||||
+ (Rectangle*) empty {return [Rectangle rectangleWithX:0 y:0 width:0 height:0];}
|
||||
|
||||
@end
|
||||
|
@ -14,11 +14,11 @@
|
||||
Vector2Struct data;
|
||||
}
|
||||
|
||||
- (id) initWithX:(float)x Y:(float)y;
|
||||
- (id) initWithX:(float)x y:(float)y;
|
||||
- (id) initWithStruct: (Vector2Struct*)vectorData;
|
||||
- (id) initWithVector: (Vector2*)vector;
|
||||
|
||||
+ (Vector2*) vectorWithX:(float)x Y:(float)y;
|
||||
+ (Vector2*) vectorWithX:(float)x y:(float)y;
|
||||
+ (Vector2*) vectorWithStruct: (Vector2Struct*)vectorData;
|
||||
+ (Vector2*) vectorWithVector: (Vector2*)vector;
|
||||
|
||||
|
@ -14,11 +14,11 @@
|
||||
Vector3Struct data;
|
||||
}
|
||||
|
||||
- (id) initWithX:(float)x Y:(float)y Z:(float)z;
|
||||
- (id) initWithX:(float)x y:(float)y z:(float)z;
|
||||
- (id) initWithStruct: (Vector3Struct*)vectorData;
|
||||
- (id) initWithVector: (Vector3*)vector;
|
||||
|
||||
+ (Vector3*) vectorWithX:(float)x Y:(float)y Z:(float)z;
|
||||
+ (Vector3*) vectorWithX:(float)x y:(float)y z:(float)z;
|
||||
+ (Vector3*) vectorWithStruct: (Vector3Struct*)vectorData;
|
||||
+ (Vector3*) vectorWithVector: (Vector3*)vector;
|
||||
|
||||
|
@ -8,7 +8,167 @@
|
||||
|
||||
#import "Vector3.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.h"
|
||||
|
||||
@implementation Vector3
|
||||
|
||||
// CONSTRUCTORS
|
||||
|
||||
- (id) initWithX:(float)x y:(float)y z:(float)z {
|
||||
if (self = [super init]) {
|
||||
data = Vector3Make(x, y, z);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithStruct: (Vector3Struct*)vectorData {
|
||||
if (self = [super init]) {
|
||||
data = *vectorData;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithVector: (Vector3*)vector {
|
||||
return [self initWithStruct:vector.data];
|
||||
}
|
||||
|
||||
+ (Vector3*) vectorWithX:(float)x y:(float)y z:(float)z {
|
||||
return [[[Vector3 alloc] initWithX:x y:y z:z] autorelease];
|
||||
}
|
||||
|
||||
+ (Vector3*) vectorWithStruct: (Vector3Struct*)vectorData {
|
||||
return [[[Vector3 alloc] initWithStruct:vectorData] autorelease];
|
||||
}
|
||||
|
||||
+ (Vector3*) vectorWithVector: (Vector3*)vector {
|
||||
return [[[Vector3 alloc] initWithVector:vector] autorelease];
|
||||
}
|
||||
|
||||
// PROPERTIES
|
||||
|
||||
- (float) x {return data.x;}
|
||||
- (void) setX:(float)value {data.x = value;}
|
||||
|
||||
- (float) y {return data.y;}
|
||||
- (void) setY:(float)value {data.y = value;}
|
||||
|
||||
- (float) z {return data.z;}
|
||||
- (void) setZ:(float)value {data.z = value;}
|
||||
|
||||
- (Vector3Struct*) data {return &data;}
|
||||
|
||||
// METHODS
|
||||
|
||||
+ (Vector3*) normalize:(Vector3*)value {
|
||||
Vector3Struct resultData = *value.data;
|
||||
Vector3Normalize(&resultData);
|
||||
return [Vector3 vectorWithStruct:&resultData];
|
||||
}
|
||||
|
||||
+ (Vector3*) negate:(Vector3*)value {
|
||||
Vector3Struct resultData = *value.data;
|
||||
Vector3Negate(&resultData);
|
||||
return [Vector3 vectorWithStruct:&resultData];
|
||||
}
|
||||
|
||||
+ (Vector3*) add:(Vector3*)value1 to:(Vector3*)value2 {
|
||||
Vector3Struct resultData;
|
||||
Vector3Add(value1.data, value2.data, &resultData);
|
||||
return [Vector3 vectorWithStruct:&resultData];
|
||||
}
|
||||
|
||||
+ (Vector3*) subtract:(Vector3*)value1 by:(Vector3*)value2 {
|
||||
Vector3Struct resultData;
|
||||
Vector3Subtract(value1.data, value2.data, &resultData);
|
||||
return [Vector3 vectorWithStruct:&resultData];
|
||||
}
|
||||
|
||||
+ (Vector3*) multiply:(Vector3*)value by:(float)scalar {
|
||||
Vector3Struct resultData;
|
||||
Vector3Multiply(value.data, scalar, &resultData);
|
||||
return [Vector3 vectorWithStruct:&resultData];
|
||||
}
|
||||
|
||||
+ (Vector3*) crossProductOf:(Vector3*)value1 with:(Vector3*)value2 {
|
||||
Vector3Struct resultData;
|
||||
Vector3CrossProduct(value1.data, value2.data, &resultData);
|
||||
return [Vector3 vectorWithStruct:&resultData];
|
||||
}
|
||||
|
||||
+ (float) dotProductOf:(Vector3*)value1 with:(Vector3*)value2 {
|
||||
return Vector3DotProduct(value1.data, value2.data);
|
||||
}
|
||||
|
||||
+ (Vector3*) transform:(Vector3*)value with:(Matrix*)matrix {
|
||||
Vector3Struct resultData;
|
||||
Vector3Transform(value.data, matrix.data, &resultData);
|
||||
return [Vector3 vectorWithStruct:&resultData];
|
||||
}
|
||||
|
||||
+ (Vector3*) transformNormal:(Vector3*)value with:(Matrix*)matrix {
|
||||
Vector3Struct resultData;
|
||||
Vector3TransformNormal(value.data, matrix.data, &resultData);
|
||||
return [Vector3 vectorWithStruct:&resultData];
|
||||
}
|
||||
|
||||
- (float) length {
|
||||
return Vector3Length(self.data);
|
||||
}
|
||||
|
||||
- (float) lengthSquared {
|
||||
return Vector3LengthSquared(self.data);
|
||||
}
|
||||
|
||||
- (Vector3*) normalize {
|
||||
Vector3Normalize(&data);
|
||||
return self;
|
||||
}
|
||||
- (Vector3*) negate {
|
||||
Vector3Negate(&data);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (Vector3*) add:(Vector3*)value {
|
||||
Vector3Add(self.data, value.data, self.data);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (Vector3*) subtract:(Vector3*)value {
|
||||
Vector3Subtract(self.data, value.data, self.data);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (Vector3*) multiplyBy:(float)scalar {
|
||||
Vector3Multiply(self.data, scalar, self.data);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (Vector3*) transformWith:(Matrix*)matrix {
|
||||
Vector3Transform(self.data, matrix.data, self.data);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (Vector3*) transformNormalWith:(Matrix*)matrix {
|
||||
Vector3TransformNormal(self.data, matrix.data, self.data);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString *) description {
|
||||
return [NSString stringWithFormat:@"Vector(%f, %f, %f)", data.x, data.y, data.z];
|
||||
}
|
||||
|
||||
// Constants
|
||||
|
||||
+ (Vector3*) zero {return [Vector3 vectorWithX:0 y:0 z:0];}
|
||||
+ (Vector3*) one {return [Vector3 vectorWithX:1 y:1 z:1];}
|
||||
+ (Vector3*) unitX {return [Vector3 vectorWithX:1 y:0 z:0];}
|
||||
+ (Vector3*) unitY {return [Vector3 vectorWithX:0 y:1 z:0];}
|
||||
+ (Vector3*) unitZ {return [Vector3 vectorWithX:0 y:0 z:1];}
|
||||
+ (Vector3*) up {return [Vector3 vectorWithX:0 y:1 z:0];}
|
||||
+ (Vector3*) down {return [Vector3 vectorWithX:0 y:-1 z:0];}
|
||||
+ (Vector3*) left {return [Vector3 vectorWithX:-1 y:0 z:0];}
|
||||
+ (Vector3*) right {return [Vector3 vectorWithX:1 y:0 z:0];}
|
||||
+ (Vector3*) forward {return [Vector3 vectorWithX:0 y:0 z:-1];}
|
||||
+ (Vector3*) backward {return [Vector3 vectorWithX:0 y:0 z:1];}
|
||||
|
||||
@end
|
||||
|
50
Classes/System/AdaptiveArray.m
Normal file
50
Classes/System/AdaptiveArray.m
Normal file
@ -0,0 +1,50 @@
|
||||
//
|
||||
// AdaptiveArray.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 21.9.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AdaptiveArray.h"
|
||||
|
||||
@implementation AdaptiveArray
|
||||
|
||||
- (id) initWithItemSize:(int)theItemSize initialCapacity:(int)theCapacity {
|
||||
if (self = [super init]) {
|
||||
itemSize = theItemSize;
|
||||
capacity = theCapacity;
|
||||
array = malloc(capacity * itemSize);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@synthesize itemSize;
|
||||
@synthesize array;
|
||||
@synthesize count;
|
||||
|
||||
- (void) addItem:(void *)item {
|
||||
if (count == capacity) {
|
||||
// Resize array
|
||||
void* newArray = malloc(capacity * 2 * itemSize);
|
||||
memcpy(newArray, array, capacity * itemSize);
|
||||
free(array);
|
||||
array = newArray;
|
||||
capacity *= 2;
|
||||
}
|
||||
memcpy(array + count * itemSize, item, itemSize);
|
||||
count++;
|
||||
}
|
||||
|
||||
- (void) clear {
|
||||
count = 0;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
free(array);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -4,3 +4,6 @@
|
||||
|
||||
// Events
|
||||
@class Delegate, Event, EventArgs;
|
||||
|
||||
// Arrays
|
||||
@class AdaptiveArray;
|
||||
|
@ -5,4 +5,7 @@
|
||||
// Events
|
||||
#import "Delegate.h"
|
||||
#import "Event.h"
|
||||
#import "EventArgs.h"
|
||||
#import "EventArgs.h"
|
||||
|
||||
// Arrays
|
||||
#import "AdaptiveArray.h"
|
Loading…
x
Reference in New Issue
Block a user