PageRenderTime 29ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 1ms

/HelloOpenGL/HelloOpenGL/CC3Foundation.h

https://gitlab.com/praveenvelanati/ios-demo
C Header | 563 lines | 147 code | 117 blank | 299 comment | 0 complexity | 96a6f77ee083a2362702dd2668b5ac6d MD5 | raw file
  1. /*
  2. * CC3Foundation.h
  3. *
  4. * $Version: cocos3d 0.5.4 (f5cd4df5048c) on 2011-04-14 $
  5. * Author: Bill Hollings
  6. * Copyright (c) 2010-2011 The Brenwill Workshop Ltd. All rights reserved.
  7. * http://www.brenwill.com
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. * http://en.wikipedia.org/wiki/MIT_License
  28. */
  29. /** @file */ // Doxygen marker
  30. /** @mainpage cocos3d API reference
  31. *
  32. * @section intro About cocos3d
  33. *
  34. * Cocos3d extends cocos2d to add support for full 3D rendering, in combination with
  35. * normal cocos2d 2D rendering.
  36. *
  37. * Rendering of 3D objects is performed within a CC3Layer, which is a specialized cocos2d
  38. * layer. In your application, you will usually create a customized subclass of CC3Layer,
  39. * which you add to a CCScene, or other CCLayer, to act as a bridge between the 2D and
  40. * 3D rendering.
  41. *
  42. * The CC3Layer instance holds a reference to an instance of CC3World, which manages the
  43. * 3D model objects, including loading from 3D model files, such as PowerVR POD files.
  44. * You will usually create a customized subclass of CC3World to create and manage the
  45. * objects and dynamics of your 3D world.
  46. */
  47. /* Base library of definitions and functions for operating in a 3D world. */
  48. #import "ccTypes.h"
  49. #import "CC3Math.h"
  50. #import "CC3Logging.h"
  51. //#import "CCDirector.h"
  52. #pragma mark -
  53. #pragma mark 3D cartesian vector structure and functions
  54. /** A vector in 3D space. */
  55. typedef struct {
  56. GLfloat x; /**< The X-componenent of the vector. */
  57. GLfloat y; /**< The Y-componenent of the vector. */
  58. GLfloat z; /**< The Z-componenent of the vector. */
  59. } CC3Vector;
  60. /** A CC3Vector of zero length at the origin. */
  61. static const CC3Vector kCC3VectorZero = { 0.0, 0.0, 0.0 };
  62. /** A CC3Vector with each component equal to one, representing the diagonal of a unit cube. */
  63. static const CC3Vector kCC3VectorUnitCube = { 1.0, 1.0, 1.0 };
  64. /** The diagonal length of a unit cube. */
  65. static const GLfloat kCC3VectorUnitCubeLength = M_SQRT3;
  66. /** Unit vector pointing in the same direction as the positive X-axis. */
  67. static const CC3Vector kCC3VectorUnitXPositive = { 1.0, 0.0, 0.0 };
  68. /** Unit vector pointing in the same direction as the positive Y-axis. */
  69. static const CC3Vector kCC3VectorUnitYPositive = { 0.0, 1.0, 0.0 };
  70. /** Unit vector pointing in the same direction as the positive Z-axis. */
  71. static const CC3Vector kCC3VectorUnitZPositive = { 0.0, 0.0, 1.0 };
  72. /** Unit vector pointing in the same direction as the negative X-axis. */
  73. static const CC3Vector kCC3VectorUnitXNegative = {-1.0, 0.0, 0.0 };
  74. /** Unit vector pointing in the same direction as the negative Y-axis. */
  75. static const CC3Vector kCC3VectorUnitYNegative = { 0.0, -1.0, 0.0 };
  76. /** Unit vector pointing in the same direction as the negative Z-axis. */
  77. static const CC3Vector kCC3VectorUnitZNegative = { 0.0, 0.0, -1.0 };
  78. /** Returns a string description of the specified CC3Vector struct in the form "(x, y, z)" */
  79. NSString* NSStringFromCC3Vector(CC3Vector v);
  80. /** Returns a CC3Vector structure constructed from the vector components. */
  81. CC3Vector CC3VectorMake(GLfloat x, GLfloat y, GLfloat z);
  82. /** Convenience alias macro to create CC3Vectors with less keystrokes. */
  83. #define cc3v(X,Y,Z) CC3VectorMake((X),(Y),(Z))
  84. /** Returns whether the two vectors are equal by comparing their respective components. */
  85. BOOL CC3VectorsAreEqual(CC3Vector v1, CC3Vector v2);
  86. /**
  87. * Returns a vector whose components comprise the minimum value of each of the respective
  88. * components of the two specfied vectors. In general, do not expect this method to return
  89. * one of the specified vectors, but a new vector, each of the components of which is the
  90. * minimum value for that component between the two vectors.
  91. */
  92. CC3Vector CC3VectorMinimize(CC3Vector v1, CC3Vector v2);
  93. /**
  94. * Returns a vector whose components comprise the maximum value of each of the respective
  95. * components of the two specfied vectors. In general, do not expect this method to return
  96. * one of the specified vectors, but a new vector, each of the components of which is the
  97. * maximum value for that component between the two vectors.
  98. */
  99. CC3Vector CC3VectorMaximize(CC3Vector v1, CC3Vector v2);
  100. /**
  101. * Returns the scalar length of the specified CC3Vector from the origin.
  102. * This is calculated as sqrt(x*x + y*y + z*z) and will always be positive.
  103. */
  104. GLfloat CC3VectorLength(CC3Vector v);
  105. /**
  106. * Returns a normalized copy of the specified CC3Vector so that its length is 1.0.
  107. * If the length is zero, the original vector (a zero vector) is returned.
  108. */
  109. CC3Vector CC3VectorNormalize(CC3Vector v);
  110. /**
  111. * Returns a vector that is the negative of the specified vector in all directions.
  112. * For vectors that represent directions, the returned vector points in the direction
  113. * opposite to the original.
  114. */
  115. CC3Vector CC3VectorNegate(CC3Vector v);
  116. /**
  117. * Returns a CC3Vector that is the inverse of the specified vector in all directions,
  118. * such that scaling the original by the inverse using CC3VectorScale will result in a vector
  119. * of unit dimension in each direction (1.0, 1.0, 1.0). The result of this function is effectively
  120. * calculated by dividing each component of the original vector into 1.0 (1.0/x, 1.0/y, 1.0/z).
  121. * It is the responsibility of the caller to ensure that none of the components of the original is zero.
  122. */
  123. CC3Vector CC3VectorInvert(CC3Vector v);
  124. /**
  125. * Returns the result of adding the two specified vectors, by adding the corresponding components
  126. * of both vectors. This can also be thought of as a translation of the first vector by the second.
  127. */
  128. CC3Vector CC3VectorAdd(CC3Vector v, CC3Vector translation);
  129. /**
  130. * Returns the difference between two vectors, by subtracting the subtrahend from the minuend,
  131. * which is accomplished by subtracting each of the corresponding x,y,z components.
  132. */
  133. CC3Vector CC3VectorDifference(CC3Vector minuend, CC3Vector subtrahend);
  134. /**
  135. * Returns the difference between two rotation vectors, in terms of the minimal degrees,
  136. * along each axis, required to travel between the two roations, given that rotations
  137. * are cyclical with a period of 360 degrees. The result may be positive or negative,
  138. * but will always be between (+/-180 degrees).
  139. *
  140. * For example, the difference between 350 and 10 will yield -20 (ie- the smallest change
  141. * from 10 degrees to 350 degrees is -20 degrees) rather than +340 (from simple subtraction).
  142. * Similarly, the difference between 10 and 350 will yield +20 (ie- the smallest change from
  143. * 350 degrees to 10 degrees is +20 degrees) rather than -340 (from simple subtraction).
  144. */
  145. CC3Vector CC3VectorRotationalDifference(CC3Vector minuend, CC3Vector subtrahend);
  146. /** Returns the positive scalar distance between the ends of the two specified vectors. */
  147. GLfloat CC3VectorDistance(CC3Vector start, CC3Vector end);
  148. /**
  149. * Returns the result of scaling the original vector by the corresponding scale vector.
  150. * Scaling can be different for each axis. This has the effect of multiplying each component
  151. * of the vector by the corresponding component in the scale vector.
  152. */
  153. CC3Vector CC3VectorScale(CC3Vector v, CC3Vector scale);
  154. /** Returns the result of scaling the original vector by the corresponding scale factor uniformly along all axes. */
  155. CC3Vector CC3VectorScaleUniform(CC3Vector v, GLfloat scale);
  156. /** Returns the dot-product of the two given vectors (v1 . v2). */
  157. GLfloat CC3VectorDot(CC3Vector v1, CC3Vector v2);
  158. /** Returns the cross-product of the two given vectors (v1 x v2). */
  159. CC3Vector CC3VectorCross(CC3Vector v1, CC3Vector v2);
  160. /**
  161. * Returns a linear interpolation between two vectors, based on the blendFactor.
  162. * which should be between zero and one inclusive. The returned value is calculated
  163. * as v1 + (blendFactor * (v2 - v1)). If the blendFactor is either zero or one
  164. * exactly, this method short-circuits to simply return v1 or v2 respectively.
  165. */
  166. CC3Vector CC3VectorLerp(CC3Vector v1, CC3Vector v2, GLfloat blendFactor);
  167. /**
  168. * Defines a ray or line in 3D space, by specifying a starting location and direction.
  169. *
  170. * For a line, the startLocation can variously be interpreted as the location of any
  171. * point on the line.
  172. */
  173. typedef struct {
  174. CC3Vector startLocation; /**< The location where the ray starts. */
  175. CC3Vector direction; /**< The direction in which the ray points. */
  176. } CC3Ray;
  177. /**
  178. * Defines an axially-aligned-bounding-box (AABB), describing
  179. * a 3D volume by specifying the minimum and maximum 3D corners.
  180. */
  181. typedef struct {
  182. CC3Vector minimum; /**< The minimum corner (bottom-left-rear). */
  183. CC3Vector maximum; /**< The maximum corner (top-right-front). */
  184. } CC3BoundingBox;
  185. /**
  186. * Defines a simple vertex, containing location, normal, and texture coordinate
  187. * data. Useful for interleaving vertex data for presentation to the GL engine.
  188. */
  189. typedef struct {
  190. CC3Vector location; /**< The 3D location of the vertex. */
  191. CC3Vector normal; /**< The 3D normal at the vertex. */
  192. ccTex2F texCoord; /**< The 2D coordinate of this vertex on the texture. */
  193. } CCTexturedVertex;
  194. #pragma mark -
  195. #pragma mark 3D angular vector structure and functions
  196. /**
  197. * An angle such as a heading or inclination.
  198. * Can be measured in degrees or radians and may be positive or negative.
  199. */
  200. typedef GLfloat CC3Angle;
  201. /** Specifies a vector using angular coordinate axes. Angles are measured in degrees or radians. */
  202. typedef struct {
  203. CC3Angle heading; /**< The horizontal heading. */
  204. CC3Angle inclination; /**< The inclination from horizontal. */
  205. GLfloat radius; /**< The radial distance. */
  206. } CC3AngularVector;
  207. /** Returns a string description of the specified CC3AngularVector struct in the form "(heading, inclination, radius)" */
  208. NSString* NSStringFromCC3AngularVector(CC3AngularVector av);
  209. /** Returns an CC3AngularVector structure constructed from the vector components. */
  210. CC3AngularVector CC3AngularVectorMake(GLfloat heading, GLfloat inclination, GLfloat radius);
  211. /**
  212. * Returns an CC3AngularVector providing the heading, inclination & radius of the specified CC3Vector.
  213. * Heading is measured in degrees, in the X-Z plane, clockwise from the negative Z-axis.
  214. * Inclination is measured in degrees, with up being in the positive-Y direction.
  215. */
  216. CC3AngularVector CC3AngularVectorFromVector(CC3Vector v);
  217. /**
  218. * Returns a CC3Vector from the specified CC3AngularVector.
  219. * Heading is measured in degrees, in the X-Z plane, clockwise from the negative Z-axis.
  220. * Inclination is measured in degrees, with up being in the positive-Y direction.
  221. */
  222. CC3Vector CC3VectorFromAngularVector(CC3AngularVector av);
  223. /**
  224. * Returns the difference between two CC3AngularVectors, by subtracting the corresponding heading,
  225. * inclination & radial components. Note that this is NOT true vector arithmetic, which would
  226. * yield a completely different angular and radial results.
  227. */
  228. CC3AngularVector CC3AngularVectorDifference(CC3AngularVector minuend, CC3AngularVector subtrahend);
  229. #pragma mark -
  230. #pragma mark Cartesian vector in 4D homogeneous coordinate space structure and functions
  231. /** A homogeneous vector in 4D graphics matrix space. */
  232. typedef struct {
  233. GLfloat x; /**< The X-componenent of the vector. */
  234. GLfloat y; /**< The Y-componenent of the vector. */
  235. GLfloat z; /**< The Z-componenent of the vector. */
  236. GLfloat w; /**< The homogeneous ratio factor. */
  237. } CC3Vector4;
  238. /** A CC3Vector4 of zero length at the origin. */
  239. static const CC3Vector4 kCC3Vector4Zero = { 0.0, 0.0, 0.0, 0.0 };
  240. /** A CC3Vector4 that represents the identity quaternion. */
  241. static const CC3Vector4 kCC3Vector4QuaternionIdentity = { 0.0, 0.0, 0.0, 1.0 };
  242. /** Returns a string description of the specified CC3Vector4 struct in the form "(x, y, z, w)" */
  243. NSString* NSStringFromCC3Vector4(CC3Vector4 v);
  244. /** Returns a CC3Vector4 structure constructed from the vector components. */
  245. CC3Vector4 CC3Vector4Make(GLfloat x, GLfloat y, GLfloat z, GLfloat w);
  246. /** Returns a CC3Vector4 structure constructed from a 3D vector and a w component. */
  247. CC3Vector4 CC3Vector4FromCC3Vector(CC3Vector v, GLfloat w);
  248. /**
  249. * Returns a CC3Vector structure constructed from a CC3Vector4. The CC3Vector4 is first homogenized
  250. * (via CC3Vector4Homogenize), before copying the resulting x, y & z coordinates into the CC3Vector.
  251. */
  252. CC3Vector CC3VectorFromCC3Vector4(CC3Vector4 v);
  253. /** Returns whether the two vectors are equal by comparing their respective components. */
  254. BOOL CC3Vector4sAreEqual(CC3Vector4 v1, CC3Vector4 v2);
  255. /**
  256. * If the specified homogeneous vector represents a location (w is not zero), returns
  257. * a homoginized copy of the vector, by dividing each component by the w-component
  258. * (including the w-component itself, leaving it with a value of one).
  259. * If the specified vector is a direction (w is zero), the vector is returned unchanged.
  260. */
  261. CC3Vector4 CC3Vector4Homogenize(CC3Vector4 v);
  262. /**
  263. * Returns the scalar length of the specified vector from the origin, including the w-component
  264. * This is calculated as sqrt(x*x + y*y + z*z + w*w) and will always be positive.
  265. */
  266. GLfloat CC3Vector4Length(CC3Vector4 v);
  267. /** Returns a normalized copy of the specified vector so that its length is 1.0. The w-component is also normalized. */
  268. CC3Vector4 CC3Vector4Normalize(CC3Vector4 v);
  269. /** Returns a vector that is the negative of the specified vector in all directions. */
  270. CC3Vector4 CC3Vector4Negate(CC3Vector4 v);
  271. /** Returns the result of scaling the original vector by the corresponding scale factor uniformly along all axes. */
  272. CC3Vector4 CC3Vector4ScaleUniform(CC3Vector4 v, GLfloat scale);
  273. /**
  274. * Returns the result of translating the original vector by the corresponding translation amounts
  275. * in each direction. This corresponds to an addition of one vector to the other.
  276. */
  277. CC3Vector4 CC3Vector4Translate(CC3Vector4 v, CC3Vector4 translation);
  278. /** Returns the dot-product of the two given vectors (v1 . v2). */
  279. GLfloat CC3Vector4Dot(CC3Vector4 v1, CC3Vector4 v2);
  280. /**
  281. * Returns a spherical linear interpolation between two vectors, based on the blendFactor.
  282. * which should be between zero and one inclusive. The returned value is calculated
  283. * as v1 + (blendFactor * (v2 - v1)). If the blendFactor is either zero or one
  284. * exactly, this method short-circuits to simply return v1 or v2 respectively.
  285. */
  286. CC3Vector4 CC3Vector4Slerp(CC3Vector4 v1, CC3Vector4 v2, GLfloat blendFactor);
  287. #pragma mark -
  288. #pragma mark Plane and frustum structures and functions
  289. /** The coefficients of the equation for a plane in 3D space (ax + by + cz + d = 0). */
  290. typedef struct {
  291. GLfloat a; /**< The a coefficient in the planar equation. */
  292. GLfloat b; /**< The b coefficient in the planar equation. */
  293. GLfloat c; /**< The c coefficient in the planar equation. */
  294. GLfloat d; /**< The d coefficient in the planar equation. */
  295. } CC3Plane;
  296. /** Returns a string description of the specified CC3Plane struct in the form "(a, b, c, d)" */
  297. NSString* NSStringFromCC3Plane(CC3Plane p);
  298. /** Returns a CC3Plane structure constructed from the specified coefficients. */
  299. CC3Plane CC3PlaneMake(GLfloat a, GLfloat b, GLfloat c, GLfloat d);
  300. /**
  301. * Returns a CC3Plane structure that contains the specified points.
  302. *
  303. * The direction of the normal of the returned plane is dependent on the winding order
  304. * of the three points. Winding is done in the order the points are specified
  305. * (p1 -> p2 -> p3), and the normal will point in the direction that has the three points
  306. * winding in a counter-clockwise direction, according to a right-handed coordinate
  307. * system. If the direction of the normal is important, be sure to specify the three
  308. * points in the appropriate order.
  309. */
  310. CC3Plane CC3PlaneFromPoints(CC3Vector p1, CC3Vector p2, CC3Vector p3);
  311. /** Returns a normalized copy of the specified CC3Plane so that the length of its normal (a, b, c) is 1.0 */
  312. CC3Plane CC3PlaneNormalize(CC3Plane p);
  313. /** Returns the distance from the point represented by the vector to the specified normalized plane. */
  314. GLfloat CC3DistanceFromNormalizedPlane(CC3Plane p, CC3Vector v);
  315. /** Returns the normal of the plane, which is (a, b, c) from the planar equation. */
  316. CC3Vector CC3PlaneNormal(CC3Plane p);
  317. /**
  318. * Returns the location point of the intersection of the specified plane and a ray, which
  319. * is defined by a starting location and a direction.
  320. *
  321. * The returned result is a 4D vector, where the x, y & z components give the intersection
  322. * location in 3D space, and the w component gives the distance from the rayStart to the
  323. * intersection location. If this value is negative, the intersection point is in the
  324. * opposite direction to where the ray is pointing.
  325. *
  326. * If the ray is parallel to the plane, no intersection occurs, and the returned 4D vector
  327. * will be zeroed (equal to kCC3Vector4Zero).
  328. */
  329. //CC3Vector4 CC3RayIntersectionWithPlane(CC3Plane plane, CC3Vector rayStart, CC3Vector rayDir);
  330. /**
  331. * Returns the location of the point where the specified ray intersects the specified plane.
  332. *
  333. * The returned result is a 4D vector, where the x, y & z components give the intersection
  334. * location in 3D space, and the w component gives the distance from the startLocation of
  335. * the ray to the intersection location, in multiples of the ray direction vector. If this
  336. * value is negative, the intersection point is in the direction opposite to the direction
  337. * of the ray.
  338. *
  339. * If the ray is parallel to the plane, no intersection occurs, and the returned 4D vector
  340. * will be zeroed (equal to kCC3Vector4Zero).
  341. */
  342. CC3Vector4 CC3RayIntersectionWithPlane(CC3Ray ray, CC3Plane plane);
  343. #pragma mark -
  344. #pragma mark Viewport structure and functions
  345. /** GL viewport data */
  346. typedef struct {
  347. GLint x; /**< The X-position of the bottom-left corner of the viewport. */
  348. GLint y; /**< The Y-position of the bottom-left corner of the viewport. */
  349. GLsizei w; /**< The width of the viewport. */
  350. GLsizei h; /**< The height of the viewport. */
  351. } CC3Viewport;
  352. /** Returns a string description of the specified CC3Viewport struct in the form "(x, y, w, h)" */
  353. NSString* NSStringFromCC3Viewport(CC3Viewport vp);
  354. /** Returns a CC3Viewport structure constructed from the specified components. */
  355. CC3Viewport CC3ViewportMake(GLint x, GLint y, GLint w, GLint h);
  356. /** Returns whether the two viewports are equal by comparing their respective components. */
  357. BOOL CC3ViewportsAreEqual(CC3Viewport vp1, CC3Viewport vp2);
  358. /**
  359. * Returns whether the specified point lies within the specified viewport.
  360. * A point is considered inside the viewport if its coordinates lie inside
  361. * the viewport or on the minimum X or minimum Y edge.
  362. */
  363. BOOL CC3ViewportContainsPoint(CC3Viewport vp, CGPoint point);
  364. /** Returns the dimensions of the specified viewport as a rectangle. */
  365. CGRect CGRectFromCC3Viewport(CC3Viewport vp);
  366. #pragma mark -
  367. #pragma mark ccColor4F constants and functions
  368. /** Opaque Red */
  369. static const ccColor4F kCCC4FRed = { 1.0, 0.0, 0.0, 1.0 };
  370. /** Opaque Green */
  371. static const ccColor4F kCCC4FGreen = { 0.0, 1.0, 0.0, 1.0 };
  372. /** Opaque Blue */
  373. static const ccColor4F kCCC4FBlue = { 0.0, 0.0, 1.0, 1.0 };
  374. /** Opaque Cyan */
  375. static const ccColor4F kCCC4FCyan = { 0.0, 1.0, 1.0, 1.0 };
  376. /** Opaque Magenta */
  377. static const ccColor4F kCCC4FMagenta = { 1.0, 0.0, 1.0, 1.0 };
  378. /** Opaque Yellow */
  379. static const ccColor4F kCCC4FYellow = { 1.0, 1.0, 0.0, 1.0 };
  380. /** Opaque Light Gray */
  381. static const ccColor4F kCCC4FLightGray = { (2.0 / 3.0), (2.0 / 3.0), (2.0 / 3.0), 1.0 };
  382. /** Opaque Dark Gray */
  383. static const ccColor4F kCCC4FDarkGray = { (1.0 / 3.0), (1.0 / 3.0), (1.0 / 3.0), 1.0 };
  384. /** Opaque White */
  385. static const ccColor4F kCCC4FWhite = { 1.0, 1.0, 1.0, 1.0 };
  386. /** Opaque Black */
  387. static const ccColor4F kCCC4FBlack = { 0.0, 0.0, 0.0, 1.0 };
  388. /** Transparent Black */
  389. static const ccColor4F kCCC4FBlackTransparent = {0.0, 0.0, 0.0, 0.0};
  390. /** Returns a string description of the specified ccColor4F in the form "(r, g, b, a)" */
  391. NSString* NSStringFromCCC4F(ccColor4F rgba);
  392. /** Returns an ccColor4F structure constructed from the specified components */
  393. ccColor4F CCC4FMake(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
  394. /** Returns whether the two colors are equal by comparing their respective components. */
  395. BOOL CCC4FAreEqual(ccColor4F c1, ccColor4F c2);
  396. /**
  397. * Returns the result of adding the two specified colors, by adding the corresponding components.
  398. * Each of the resulting color components is clamped to be between 0.0 and 1.0.
  399. * This can also be thought of as a translation of the first color by the second.
  400. */
  401. ccColor4F CCC4FAdd(ccColor4F rgba, ccColor4F translation);
  402. /**
  403. * Returns the difference between two colors, by subtracting the subtrahend from the minuend,
  404. * which is accomplished by subtracting each of the corresponding r,g, b, a components.
  405. * Each of the resulting color components is clamped to be between 0.0 and 1.0.
  406. */
  407. ccColor4F CCC4FDifference(ccColor4F minuend, ccColor4F subtrahend);
  408. /**
  409. * Returns an ccColor4F structure whose values are those of the specified original color,
  410. * where each color component has been translated by the specified offset.
  411. * Each of the resulting color components is clamped to be between 0.0 and 1.0.
  412. */
  413. ccColor4F CCC4FUniformTranslate(ccColor4F rgba, GLfloat offset);
  414. /**
  415. * Returns an ccColor4F structure whose values are a weighted average of the specified base color
  416. * and the blend color. The parameter blendWeight should be between zero and one. A value of zero
  417. * will leave the base color unchanged. A value of one will result in the blend being the same as
  418. * the blend color.
  419. */
  420. ccColor4F CCC4FBlend(ccColor4F baseColor, ccColor4F blendColor, GLfloat blendWeight);
  421. /**
  422. * Returns a random ccColor4F where each component value between the specified min inclusive and
  423. * the specified max exclusive. This can be useful when creating particle systems.
  424. */
  425. ccColor4F RandomCCC4FBetween(ccColor4F min, ccColor4F max);
  426. /** Returns a GLfloat between 0 and 1 converted from the specified GLubyte value between 0 and 255. */
  427. GLfloat CCColorFloatFromByte(GLubyte colorValue);
  428. /** Returns a GLubyte between 0 and 255 converted from the specified GLfloat value between 0 and 1. */
  429. GLubyte CCColorByteFromFloat(GLfloat colorValue);
  430. #pragma mark -
  431. #pragma mark Miscellaneous extensions and functionality
  432. /** Extension category to support cocos3d functionality. */
  433. @interface NSObject (CC3)
  434. /**
  435. * Convenience method to automatically autorelease when copying objects.
  436. * Invokes the copy method to create a copy of this instance, autoreleases it, and returns it.
  437. */
  438. -(id) copyAutoreleased;
  439. @end
  440. /** Extension category to support cocos3d functionality. */
  441. @interface UIColor(CC3)
  442. /** Returns a transparent ccColor4F struct containing the RGBA values for this color. */
  443. -(ccColor4F) asCCColor4F;
  444. /** Returns an autoreleased UIColor instance created from the RGBA values in the specified ccColor4F. */
  445. +(UIColor*) colorWithCCColor4F: (ccColor4F) rgba;
  446. @end