mirror of
https://github.com/mauiaaron/apple2.git
synced 2025-08-07 13:25:22 +00:00
Refactor for whitespace and clarity
This commit is contained in:
@@ -100,10 +100,8 @@ static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
|
||||
NSOpenGLPFADoubleBuffer,
|
||||
NSOpenGLPFADepthSize, 24,
|
||||
// Must specify the 3.2 Core Profile to use OpenGL 3.2
|
||||
#if ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
||||
NSOpenGLPFAOpenGLProfile,
|
||||
NSOpenGLProfileVersion3_2Core,
|
||||
#endif
|
||||
0
|
||||
};
|
||||
|
||||
@@ -116,7 +114,7 @@ static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
|
||||
|
||||
NSOpenGLContext* context = [[[NSOpenGLContext alloc] initWithFormat:pf shareContext:nil] autorelease];
|
||||
|
||||
#if ESSENTIAL_GL_PRACTICES_SUPPORT_GL3 && defined(DEBUG)
|
||||
#if defined(DEBUG)
|
||||
// When we're using a CoreProfile context, crash if we call a legacy OpenGL function
|
||||
// This will make it much more obvious where and when such a function call is made so
|
||||
// that we can remove such calls.
|
||||
|
@@ -6,7 +6,7 @@
|
||||
// Copyright (c) 2014 deadc0de.org. All rights reserved.
|
||||
//
|
||||
|
||||
#if ESSENTIAL_GL_PRACTICES_IOS
|
||||
#if TARGET_OS_IPHONE
|
||||
#import <UIKit/UIKit.h>
|
||||
#else
|
||||
#import <Cocoa/Cocoa.h>
|
||||
@@ -21,7 +21,7 @@ int main(int argc_, const char *argv_[])
|
||||
argc = argc_;
|
||||
argv = argv_;
|
||||
|
||||
#if ESSENTIAL_GL_PRACTICES_IOS
|
||||
#if TARGET_OS_IPHONE
|
||||
@autoreleasepool {
|
||||
retVal = UIApplicationMain(argc, argv, nil, nil);
|
||||
}
|
||||
|
@@ -305,7 +305,7 @@ static GLuint _build_program(demoSource *vertexSource, demoSource *fragmentSourc
|
||||
// with the proper version preprocessor string prepended
|
||||
float glLanguageVersion;
|
||||
|
||||
#if ESSENTIAL_GL_PRACTICES_IOS
|
||||
#if TARGET_OS_IPHONE
|
||||
sscanf((char *)glGetString(GL_SHADING_LANGUAGE_VERSION), "OpenGL ES GLSL ES %f", &glLanguageVersion);
|
||||
#else
|
||||
sscanf((char *)glGetString(GL_SHADING_LANGUAGE_VERSION), "%f", &glLanguageVersion);
|
||||
|
@@ -1,109 +1,41 @@
|
||||
/*
|
||||
File: glUtil.h
|
||||
Abstract:
|
||||
Includes the appropriate OpenGL headers (depending on whether this
|
||||
is built for iOS or OSX) and provides some API utility functions
|
||||
|
||||
Version: 1.7
|
||||
|
||||
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
|
||||
Inc. ("Apple") in consideration of your agreement to the following
|
||||
terms, and your use, installation, modification or redistribution of
|
||||
this Apple software constitutes acceptance of these terms. If you do
|
||||
not agree with these terms, please do not use, install, modify or
|
||||
redistribute this Apple software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and
|
||||
subject to these terms, Apple grants you a personal, non-exclusive
|
||||
license, under Apple's copyrights in this original Apple software (the
|
||||
"Apple Software"), to use, reproduce, modify and redistribute the Apple
|
||||
Software, with or without modifications, in source and/or binary forms;
|
||||
provided that if you redistribute the Apple Software in its entirety and
|
||||
without modifications, you must retain this notice and the following
|
||||
text and disclaimers in all such redistributions of the Apple Software.
|
||||
Neither the name, trademarks, service marks or logos of Apple Inc. may
|
||||
be used to endorse or promote products derived from the Apple Software
|
||||
without specific prior written permission from Apple. Except as
|
||||
expressly stated in this notice, no other rights or licenses, express or
|
||||
implied, are granted by Apple herein, including but not limited to any
|
||||
patent rights that may be infringed by your derivative works or by other
|
||||
works in which the Apple Software may be incorporated.
|
||||
|
||||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
|
||||
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
|
||||
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
|
||||
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
|
||||
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
|
||||
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
|
||||
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Copyright (C) 2013 Apple Inc. All Rights Reserved.
|
||||
|
||||
* Apple // emulator for *nix
|
||||
*
|
||||
* This software package is subject to the GNU General Public License
|
||||
* version 2 or later (your choice) as published by the Free Software
|
||||
* Foundation.
|
||||
*
|
||||
* THERE ARE NO WARRANTIES WHATSOEVER.
|
||||
*
|
||||
*/
|
||||
|
||||
// Modified sample code from https://developer.apple.com/library/mac/samplecode/GLEssentials/Introduction/Intro.html
|
||||
|
||||
#ifndef __GL_UTIL_H__
|
||||
#define __GL_UTIL_H__
|
||||
|
||||
#if ESSENTIAL_GL_PRACTICES_IOS
|
||||
|
||||
#import <OpenGLES/ES2/gl.h>
|
||||
#import <OpenGLES/ES2/glext.h>
|
||||
|
||||
#if defined(__APPLE__)
|
||||
# include <TargetConditionals.h>
|
||||
# if TARGET_OS_IPHONE
|
||||
# import <OpenGLES/ES2/gl.h>
|
||||
# import <OpenGLES/ES2/glext.h>
|
||||
# else
|
||||
# import <OpenGL/OpenGL.h>
|
||||
# import <OpenGL/gl3.h>
|
||||
# endif
|
||||
#elif defined(USE_GL3W)
|
||||
# include <GL3/gl3.h>
|
||||
# include <GL3/gl3w.h>
|
||||
#else
|
||||
# define GLEW_STATIC
|
||||
# include <GL/glew.h>
|
||||
# define FREEGLUT_STATIC
|
||||
# include <GL/freeglut.h>
|
||||
#endif
|
||||
|
||||
#import <OpenGL/OpenGL.h>
|
||||
|
||||
// OpenGL 3.2 is only supported on MacOS X Lion and later
|
||||
// CGL_VERSION_1_3 is defined as 1 on MacOS X Lion and later
|
||||
#if CGL_VERSION_1_3
|
||||
// Set to 0 to run on the Legacy OpenGL Profile
|
||||
#define ESSENTIAL_GL_PRACTICES_SUPPORT_GL3 1
|
||||
#else
|
||||
#define ESSENTIAL_GL_PRACTICES_SUPPORT_GL3 0
|
||||
#endif //!CGL_VERSION_1_3
|
||||
|
||||
#if ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
||||
#import <OpenGL/gl3.h>
|
||||
#else
|
||||
#import <OpenGL/gl.h>
|
||||
#endif //!ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
||||
|
||||
#endif // !ESSENTIAL_GL_PRACTICES_IOS
|
||||
|
||||
|
||||
//The name of the VertexArrayObject are slightly different in
|
||||
// OpenGLES, OpenGL Core Profile, and OpenGL Legacy
|
||||
// The arguments are exactly the same across these APIs however
|
||||
#if ESSENTIAL_GL_PRACTICES_IOS
|
||||
#define glBindVertexArray glBindVertexArrayOES
|
||||
#define glGenVertexArrays glGenVertexArraysOES
|
||||
#define glDeleteVertexArrays glDeleteVertexArraysOES
|
||||
#else
|
||||
#if ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
||||
#define glBindVertexArray glBindVertexArray
|
||||
#define glGenVertexArrays glGenVertexArrays
|
||||
#define glGenerateMipmap glGenerateMipmap
|
||||
#define glDeleteVertexArrays glDeleteVertexArrays
|
||||
#else
|
||||
#define glBindVertexArray glBindVertexArrayAPPLE
|
||||
#define glGenVertexArrays glGenVertexArraysAPPLE
|
||||
#define glGenerateMipmap glGenerateMipmapEXT
|
||||
#define glDeleteVertexArrays glDeleteVertexArraysAPPLE
|
||||
#endif //!ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
||||
#endif //!ESSENTIAL_GL_PRACTICES_IOS
|
||||
|
||||
static inline const char * GetGLErrorString(GLenum error)
|
||||
{
|
||||
static inline const char * GetGLErrorString(GLenum error) {
|
||||
const char *str;
|
||||
switch( error )
|
||||
{
|
||||
switch (error) {
|
||||
case GL_NO_ERROR:
|
||||
str = "GL_NO_ERROR";
|
||||
break;
|
||||
|
@@ -1,75 +1,34 @@
|
||||
/*
|
||||
File: imageUtil.h
|
||||
Abstract:
|
||||
Functions for loading an image files for textures.
|
||||
|
||||
Version: 1.7
|
||||
|
||||
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
|
||||
Inc. ("Apple") in consideration of your agreement to the following
|
||||
terms, and your use, installation, modification or redistribution of
|
||||
this Apple software constitutes acceptance of these terms. If you do
|
||||
not agree with these terms, please do not use, install, modify or
|
||||
redistribute this Apple software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and
|
||||
subject to these terms, Apple grants you a personal, non-exclusive
|
||||
license, under Apple's copyrights in this original Apple software (the
|
||||
"Apple Software"), to use, reproduce, modify and redistribute the Apple
|
||||
Software, with or without modifications, in source and/or binary forms;
|
||||
provided that if you redistribute the Apple Software in its entirety and
|
||||
without modifications, you must retain this notice and the following
|
||||
text and disclaimers in all such redistributions of the Apple Software.
|
||||
Neither the name, trademarks, service marks or logos of Apple Inc. may
|
||||
be used to endorse or promote products derived from the Apple Software
|
||||
without specific prior written permission from Apple. Except as
|
||||
expressly stated in this notice, no other rights or licenses, express or
|
||||
implied, are granted by Apple herein, including but not limited to any
|
||||
patent rights that may be infringed by your derivative works or by other
|
||||
works in which the Apple Software may be incorporated.
|
||||
|
||||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
|
||||
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
|
||||
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
|
||||
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
|
||||
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
|
||||
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
|
||||
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Copyright (C) 2013 Apple Inc. All Rights Reserved.
|
||||
|
||||
* Apple // emulator for *nix
|
||||
*
|
||||
* This software package is subject to the GNU General Public License
|
||||
* version 2 or later (your choice) as published by the Free Software
|
||||
* Foundation.
|
||||
*
|
||||
* THERE ARE NO WARRANTIES WHATSOEVER.
|
||||
*
|
||||
*/
|
||||
|
||||
// Modified sample code from https://developer.apple.com/library/mac/samplecode/GLEssentials/Introduction/Intro.html
|
||||
|
||||
#ifndef __IMAGE_UTIL_H__
|
||||
#define __IMAGE_UTIL_H__
|
||||
|
||||
#include "glUtil.h"
|
||||
|
||||
typedef struct demoImageRec
|
||||
{
|
||||
GLubyte* data;
|
||||
|
||||
typedef struct demoImageRec {
|
||||
GLubyte *data;
|
||||
GLsizei size;
|
||||
|
||||
GLuint width;
|
||||
GLuint height;
|
||||
GLenum format;
|
||||
GLenum type;
|
||||
|
||||
GLuint rowByteSize;
|
||||
|
||||
} demoImage;
|
||||
|
||||
demoImage* imgLoadImage(const char* filepathname, int flipVertical);
|
||||
demoImage *imgLoadImage(const char *filepathname, int flipVertical);
|
||||
|
||||
void imgDestroyImage(demoImage* image);
|
||||
void imgDestroyImage(demoImage *image);
|
||||
|
||||
#endif //__IMAGE_UTIL_H__
|
||||
|
||||
|
@@ -1,69 +1,31 @@
|
||||
/*
|
||||
File: imageUtil.m
|
||||
Abstract:
|
||||
Functions for loading an image files for textures.
|
||||
|
||||
Version: 1.7
|
||||
|
||||
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
|
||||
Inc. ("Apple") in consideration of your agreement to the following
|
||||
terms, and your use, installation, modification or redistribution of
|
||||
this Apple software constitutes acceptance of these terms. If you do
|
||||
not agree with these terms, please do not use, install, modify or
|
||||
redistribute this Apple software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and
|
||||
subject to these terms, Apple grants you a personal, non-exclusive
|
||||
license, under Apple's copyrights in this original Apple software (the
|
||||
"Apple Software"), to use, reproduce, modify and redistribute the Apple
|
||||
Software, with or without modifications, in source and/or binary forms;
|
||||
provided that if you redistribute the Apple Software in its entirety and
|
||||
without modifications, you must retain this notice and the following
|
||||
text and disclaimers in all such redistributions of the Apple Software.
|
||||
Neither the name, trademarks, service marks or logos of Apple Inc. may
|
||||
be used to endorse or promote products derived from the Apple Software
|
||||
without specific prior written permission from Apple. Except as
|
||||
expressly stated in this notice, no other rights or licenses, express or
|
||||
implied, are granted by Apple herein, including but not limited to any
|
||||
patent rights that may be infringed by your derivative works or by other
|
||||
works in which the Apple Software may be incorporated.
|
||||
|
||||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
|
||||
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
|
||||
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
|
||||
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
|
||||
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
|
||||
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
|
||||
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Copyright (C) 2013 Apple Inc. All Rights Reserved.
|
||||
|
||||
* Apple // emulator for *nix
|
||||
*
|
||||
* This software package is subject to the GNU General Public License
|
||||
* version 2 or later (your choice) as published by the Free Software
|
||||
* Foundation.
|
||||
*
|
||||
* THERE ARE NO WARRANTIES WHATSOEVER.
|
||||
*
|
||||
*/
|
||||
|
||||
// Modified sample code from https://developer.apple.com/library/mac/samplecode/GLEssentials/Introduction/Intro.html
|
||||
|
||||
#include "imageUtil.h"
|
||||
|
||||
#if ESSENTIAL_GL_PRACTICES_IOS
|
||||
#if TARGET_OS_IPHONE
|
||||
#import <UIKit/UIKit.h>
|
||||
#else
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#endif
|
||||
|
||||
demoImage* imgLoadImage(const char* filepathname, int flipVertical)
|
||||
{
|
||||
demoImage *imgLoadImage(const char *filepathname, int flipVertical) {
|
||||
NSString *filepathString = [[NSString alloc] initWithUTF8String:filepathname];
|
||||
|
||||
#if ESSENTIAL_GL_PRACTICES_IOS
|
||||
#if TARGET_OS_IPHONE
|
||||
UIImage* imageClass = [[UIImage alloc] initWithContentsOfFile:filepathString];
|
||||
#else
|
||||
NSImage *nsimage = [[NSImage alloc] initWithContentsOfFile: filepathString];
|
||||
|
||||
NSBitmapImageRep *imageClass = [[NSBitmapImageRep alloc] initWithData:[nsimage TIFFRepresentation]];
|
||||
[nsimage release];
|
||||
#endif
|
||||
@@ -76,7 +38,7 @@ demoImage* imgLoadImage(const char* filepathname, int flipVertical)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
demoImage* image = malloc(sizeof(demoImage));
|
||||
demoImage *image = malloc(sizeof(demoImage));
|
||||
image->width = CGImageGetWidth(cgImage);
|
||||
image->height = CGImageGetHeight(cgImage);
|
||||
image->rowByteSize = image->width * 4;
|
||||
@@ -86,16 +48,14 @@ demoImage* imgLoadImage(const char* filepathname, int flipVertical)
|
||||
|
||||
CGContextRef context = CGBitmapContextCreate(image->data, image->width, image->height, 8, image->rowByteSize, CGImageGetColorSpace(cgImage), kCGImageAlphaNoneSkipLast);
|
||||
CGContextSetBlendMode(context, kCGBlendModeCopy);
|
||||
if(flipVertical)
|
||||
{
|
||||
if (flipVertical) {
|
||||
CGContextTranslateCTM(context, 0.0, image->height);
|
||||
CGContextScaleCTM(context, 1.0, -1.0);
|
||||
}
|
||||
CGContextDrawImage(context, CGRectMake(0.0, 0.0, image->width, image->height), cgImage);
|
||||
CGContextRelease(context);
|
||||
|
||||
if(NULL == image->data)
|
||||
{
|
||||
if (!image->data) {
|
||||
[filepathString release];
|
||||
[imageClass release];
|
||||
|
||||
@@ -109,8 +69,8 @@ demoImage* imgLoadImage(const char* filepathname, int flipVertical)
|
||||
return image;
|
||||
}
|
||||
|
||||
void imgDestroyImage(demoImage* image)
|
||||
{
|
||||
void imgDestroyImage(demoImage* image) {
|
||||
free(image->data);
|
||||
free(image);
|
||||
}
|
||||
|
||||
|
@@ -1,59 +1,22 @@
|
||||
/*
|
||||
File: matrixUtil.c
|
||||
Abstract:
|
||||
Functions for performing matrix math.
|
||||
|
||||
Version: 1.7
|
||||
|
||||
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
|
||||
Inc. ("Apple") in consideration of your agreement to the following
|
||||
terms, and your use, installation, modification or redistribution of
|
||||
this Apple software constitutes acceptance of these terms. If you do
|
||||
not agree with these terms, please do not use, install, modify or
|
||||
redistribute this Apple software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and
|
||||
subject to these terms, Apple grants you a personal, non-exclusive
|
||||
license, under Apple's copyrights in this original Apple software (the
|
||||
"Apple Software"), to use, reproduce, modify and redistribute the Apple
|
||||
Software, with or without modifications, in source and/or binary forms;
|
||||
provided that if you redistribute the Apple Software in its entirety and
|
||||
without modifications, you must retain this notice and the following
|
||||
text and disclaimers in all such redistributions of the Apple Software.
|
||||
Neither the name, trademarks, service marks or logos of Apple Inc. may
|
||||
be used to endorse or promote products derived from the Apple Software
|
||||
without specific prior written permission from Apple. Except as
|
||||
expressly stated in this notice, no other rights or licenses, express or
|
||||
implied, are granted by Apple herein, including but not limited to any
|
||||
patent rights that may be infringed by your derivative works or by other
|
||||
works in which the Apple Software may be incorporated.
|
||||
|
||||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
|
||||
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
|
||||
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
|
||||
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
|
||||
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
|
||||
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
|
||||
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Copyright (C) 2013 Apple Inc. All Rights Reserved.
|
||||
|
||||
* Apple // emulator for *nix
|
||||
*
|
||||
* This software package is subject to the GNU General Public License
|
||||
* version 2 or later (your choice) as published by the Free Software
|
||||
* Foundation.
|
||||
*
|
||||
* THERE ARE NO WARRANTIES WHATSOEVER.
|
||||
*
|
||||
*/
|
||||
|
||||
// Modified sample code from https://developer.apple.com/library/mac/samplecode/GLEssentials/Introduction/Intro.html
|
||||
|
||||
#include "matrixUtil.h"
|
||||
#include "vectorUtil.h"
|
||||
#include <math.h>
|
||||
#include <memory.h>
|
||||
|
||||
void mtxMultiply(float* ret, const float* lhs, const float* rhs)
|
||||
{
|
||||
void mtxMultiply(float *ret, const float *lhs, const float *rhs) {
|
||||
// [ 0 4 8 12 ] [ 0 4 8 12 ]
|
||||
// [ 1 5 9 13 ] x [ 1 5 9 13 ]
|
||||
// [ 2 6 10 14 ] [ 2 6 10 14 ]
|
||||
@@ -76,11 +39,10 @@ void mtxMultiply(float* ret, const float* lhs, const float* rhs)
|
||||
ret[12] = lhs[ 0]*rhs[12] + lhs[ 4]*rhs[13] + lhs[ 8]*rhs[14] + lhs[12]*rhs[15];
|
||||
ret[13] = lhs[ 1]*rhs[12] + lhs[ 5]*rhs[13] + lhs[ 9]*rhs[14] + lhs[13]*rhs[15];
|
||||
ret[14] = lhs[ 2]*rhs[12] + lhs[ 6]*rhs[13] + lhs[10]*rhs[14] + lhs[14]*rhs[15];
|
||||
ret[15] = lhs[ 3]*rhs[12] + lhs[ 7]*rhs[13] + lhs[11]*rhs[14] + lhs[15]*rhs[15];}
|
||||
ret[15] = lhs[ 3]*rhs[12] + lhs[ 7]*rhs[13] + lhs[11]*rhs[14] + lhs[15]*rhs[15];
|
||||
}
|
||||
|
||||
|
||||
void mtxLoadPerspective(float* mtx, float fov, float aspect, float nearZ, float farZ)
|
||||
{
|
||||
void mtxLoadPerspective(float *mtx, float fov, float aspect, float nearZ, float farZ) {
|
||||
float f = 1.0f / tanf( (fov * (M_PI/180)) / 2.0f);
|
||||
|
||||
mtx[0] = f / aspect;
|
||||
@@ -104,12 +66,7 @@ void mtxLoadPerspective(float* mtx, float fov, float aspect, float nearZ, float
|
||||
mtx[15] = 0.0f;
|
||||
}
|
||||
|
||||
|
||||
void mtxLoadOrthographic(float* mtx,
|
||||
float left, float right,
|
||||
float bottom, float top,
|
||||
float nearZ, float farZ)
|
||||
{
|
||||
void mtxLoadOrthographic(float *mtx, float left, float right, float bottom, float top, float nearZ, float farZ) {
|
||||
//See appendix G of OpenGL Red Book
|
||||
|
||||
mtx[ 0] = 2.0f / (right - left);
|
||||
@@ -133,13 +90,11 @@ void mtxLoadOrthographic(float* mtx,
|
||||
mtx[15] = 1.0f;
|
||||
}
|
||||
|
||||
static inline float sgn(float val)
|
||||
{
|
||||
static inline float sgn(float val) {
|
||||
return (val > 0.0f) ? 1.0f : ((val < 0.0f) ? -1.0f : 0.0f);
|
||||
}
|
||||
|
||||
void mtxModifyObliqueProjection(float* mtx, const float* src, const float* plane)
|
||||
{
|
||||
void mtxModifyObliqueProjection(float *mtx, const float *src, const float *plane) {
|
||||
float vec[4];
|
||||
|
||||
memcpy(mtx, src, 16 * sizeof(float));
|
||||
@@ -163,8 +118,7 @@ void mtxModifyObliqueProjection(float* mtx, const float* src, const float* plane
|
||||
mtx[14] = vec[3];
|
||||
}
|
||||
|
||||
void mtxTranspose(float* mtx, const float* src)
|
||||
{
|
||||
void mtxTranspose(float *mtx, const float *src) {
|
||||
//Use a temp to swap in case mtx == src
|
||||
|
||||
float tmp;
|
||||
@@ -196,22 +150,17 @@ void mtxTranspose(float* mtx, const float* src)
|
||||
tmp = src[14];
|
||||
mtx[14] = src[11];
|
||||
mtx[11] = tmp;
|
||||
|
||||
}
|
||||
|
||||
void mtxInvert(float* mtx, const float* src)
|
||||
{
|
||||
void mtxInvert(float *mtx, const float *src) {
|
||||
float tmp[16];
|
||||
float val, val2, val_inv;
|
||||
int i, j, i4, i8, i12, ind;
|
||||
|
||||
mtxTranspose(tmp, src);
|
||||
|
||||
mtxLoadIdentity(mtx);
|
||||
|
||||
|
||||
for(i = 0; i != 4; i++)
|
||||
{
|
||||
for (i = 0; i != 4; i++) {
|
||||
val = tmp[(i << 2) + i];
|
||||
ind = i;
|
||||
|
||||
@@ -219,17 +168,14 @@ void mtxInvert(float* mtx, const float* src)
|
||||
i8 = i + 8;
|
||||
i12 = i + 12;
|
||||
|
||||
for (j = i + 1; j != 4; j++)
|
||||
{
|
||||
if(fabsf(tmp[(i << 2) + j]) > fabsf(val))
|
||||
{
|
||||
for (j = i + 1; j != 4; j++) {
|
||||
if (fabsf(tmp[(i << 2) + j]) > fabsf(val)) {
|
||||
ind = j;
|
||||
val = tmp[(i << 2) + j];
|
||||
}
|
||||
}
|
||||
|
||||
if(ind != i)
|
||||
{
|
||||
if (ind != i) {
|
||||
val2 = mtx[i];
|
||||
mtx[i] = mtx[ind];
|
||||
mtx[ind] = val2;
|
||||
@@ -269,8 +215,7 @@ void mtxInvert(float* mtx, const float* src)
|
||||
tmp[ind] = val2;
|
||||
}
|
||||
|
||||
if(val == 0)
|
||||
{
|
||||
if (val == 0) {
|
||||
mtxLoadIdentity(mtx);
|
||||
return;
|
||||
}
|
||||
@@ -289,8 +234,7 @@ void mtxInvert(float* mtx, const float* src)
|
||||
tmp[i12] *= val_inv;
|
||||
mtx[i12] *= val_inv;
|
||||
|
||||
if(i != 0)
|
||||
{
|
||||
if (i != 0) {
|
||||
val = tmp[i << 2];
|
||||
|
||||
tmp[0] -= tmp[i] * val;
|
||||
@@ -306,8 +250,7 @@ void mtxInvert(float* mtx, const float* src)
|
||||
mtx[12] -= mtx[i12] * val;
|
||||
}
|
||||
|
||||
if(i != 1)
|
||||
{
|
||||
if (i != 1) {
|
||||
val = tmp[(i << 2) + 1];
|
||||
|
||||
tmp[1] -= tmp[i] * val;
|
||||
@@ -323,8 +266,7 @@ void mtxInvert(float* mtx, const float* src)
|
||||
mtx[13] -= mtx[i12] * val;
|
||||
}
|
||||
|
||||
if(i != 2)
|
||||
{
|
||||
if (i != 2) {
|
||||
val = tmp[(i << 2) + 2];
|
||||
|
||||
tmp[2] -= tmp[i] * val;
|
||||
@@ -340,8 +282,7 @@ void mtxInvert(float* mtx, const float* src)
|
||||
mtx[14] -= mtx[i12] * val;
|
||||
}
|
||||
|
||||
if(i != 3)
|
||||
{
|
||||
if (i != 3) {
|
||||
val = tmp[(i << 2) + 3];
|
||||
|
||||
tmp[3] -= tmp[i] * val;
|
||||
@@ -359,8 +300,7 @@ void mtxInvert(float* mtx, const float* src)
|
||||
}
|
||||
}
|
||||
|
||||
void mtxLoadIdentity(float* mtx)
|
||||
{
|
||||
void mtxLoadIdentity(float *mtx) {
|
||||
// [ 0 4 8 12 ]
|
||||
// [ 1 5 9 13 ]
|
||||
// [ 2 6 10 14 ]
|
||||
@@ -372,9 +312,7 @@ void mtxLoadIdentity(float* mtx)
|
||||
mtx[11] = mtx[12] = mtx[13] = mtx[14] = 0.0;
|
||||
}
|
||||
|
||||
|
||||
void mtxLoadTranslate(float* mtx, float xTrans, float yTrans, float zTrans)
|
||||
{
|
||||
void mtxLoadTranslate(float *mtx, float xTrans, float yTrans, float zTrans) {
|
||||
|
||||
// [ 0 4 8 x ]
|
||||
// [ 1 5 9 y ]
|
||||
@@ -391,9 +329,7 @@ void mtxLoadTranslate(float* mtx, float xTrans, float yTrans, float zTrans)
|
||||
mtx[14] = zTrans;
|
||||
}
|
||||
|
||||
|
||||
void mtxLoadScale(float* mtx, float xScale, float yScale, float zScale)
|
||||
{
|
||||
void mtxLoadScale(float *mtx, float xScale, float yScale, float zScale) {
|
||||
// [ x 4 8 12 ]
|
||||
// [ 1 y 9 13 ]
|
||||
// [ 2 6 z 14 ]
|
||||
@@ -408,9 +344,7 @@ void mtxLoadScale(float* mtx, float xScale, float yScale, float zScale)
|
||||
mtx[11] = mtx[12] = mtx[13] = mtx[14] = 0.0;
|
||||
}
|
||||
|
||||
|
||||
void mtxLoadRotateX(float* mtx, float rad)
|
||||
{
|
||||
void mtxLoadRotateX(float *mtx, float rad) {
|
||||
// [ 0 4 8 12 ]
|
||||
// [ 1 cos -sin 13 ]
|
||||
// [ 2 sin cos 14 ]
|
||||
@@ -427,9 +361,7 @@ void mtxLoadRotateX(float* mtx, float rad)
|
||||
mtx[13] = mtx[14] = 0.0;
|
||||
}
|
||||
|
||||
|
||||
void mtxLoadRotateY(float* mtx, float rad)
|
||||
{
|
||||
void mtxLoadRotateY(float *mtx, float rad) {
|
||||
// [ cos 4 -sin 12 ]
|
||||
// [ 1 5 9 13 ]
|
||||
// [ sin 6 cos 14 ]
|
||||
@@ -446,9 +378,7 @@ void mtxLoadRotateY(float* mtx, float rad)
|
||||
mtx[13] = mtx[14] = 0.0;
|
||||
}
|
||||
|
||||
|
||||
void mtxLoadRotateZ(float* mtx, float rad)
|
||||
{
|
||||
void mtxLoadRotateZ(float *mtx, float rad) {
|
||||
// [ cos -sin 8 12 ]
|
||||
// [ sin cos 9 13 ]
|
||||
// [ 2 6 10 14 ]
|
||||
@@ -465,9 +395,7 @@ void mtxLoadRotateZ(float* mtx, float rad)
|
||||
mtx[13] = mtx[14] = 0.0;
|
||||
}
|
||||
|
||||
|
||||
void mtxLoadRotate(float* mtx, float deg, float xAxis, float yAxis, float zAxis)
|
||||
{
|
||||
void mtxLoadRotate(float *mtx, float deg, float xAxis, float yAxis, float zAxis) {
|
||||
float rad = deg * M_PI/180.0f;
|
||||
|
||||
float sin_a = sinf(rad);
|
||||
@@ -539,9 +467,7 @@ void mtxLoadRotate(float* mtx, float deg, float xAxis, float yAxis, float zAxis)
|
||||
mtx[15] = 1.0f;
|
||||
}
|
||||
|
||||
|
||||
void mtxTranslateApply(float* mtx, float xTrans, float yTrans, float zTrans)
|
||||
{
|
||||
void mtxTranslateApply(float *mtx, float xTrans, float yTrans, float zTrans) {
|
||||
// [ 0 4 8 12 ] [ 1 0 0 x ]
|
||||
// [ 1 5 9 13 ] x [ 0 1 0 y ]
|
||||
// [ 2 6 10 14 ] [ 0 0 1 z ]
|
||||
@@ -552,9 +478,7 @@ void mtxTranslateApply(float* mtx, float xTrans, float yTrans, float zTrans)
|
||||
mtx[14] += mtx[2]*xTrans + mtx[6]*yTrans + mtx[10]*zTrans;
|
||||
}
|
||||
|
||||
|
||||
void mtxScaleApply(float* mtx, float xScale, float yScale, float zScale)
|
||||
{
|
||||
void mtxScaleApply(float *mtx, float xScale, float yScale, float zScale) {
|
||||
// [ 0 4 8 12 ] [ x 0 0 0 ]
|
||||
// [ 1 5 9 13 ] x [ 0 y 0 0 ]
|
||||
// [ 2 6 10 14 ] [ 0 0 z 0 ]
|
||||
@@ -577,9 +501,7 @@ void mtxScaleApply(float* mtx, float xScale, float yScale, float zScale)
|
||||
mtx[11] *= xScale;
|
||||
}
|
||||
|
||||
|
||||
void mtxTranslateMatrix(float* mtx, float xTrans, float yTrans, float zTrans)
|
||||
{
|
||||
void mtxTranslateMatrix(float *mtx, float xTrans, float yTrans, float zTrans) {
|
||||
// [ 1 0 0 x ] [ 0 4 8 12 ]
|
||||
// [ 0 1 0 y ] x [ 1 5 9 13 ]
|
||||
// [ 0 0 1 z ] [ 2 6 10 14 ]
|
||||
@@ -602,9 +524,7 @@ void mtxTranslateMatrix(float* mtx, float xTrans, float yTrans, float zTrans)
|
||||
mtx[14] += zTrans * mtx[15];
|
||||
}
|
||||
|
||||
|
||||
void mtxRotateXApply(float* mtx, float deg)
|
||||
{
|
||||
void mtxRotateXApply(float *mtx, float deg) {
|
||||
// [ 0 4 8 12 ] [ 1 0 0 0 ]
|
||||
// [ 1 5 9 13 ] x [ 0 cos -sin 0 ]
|
||||
// [ 2 6 10 14 ] [ 0 sin cos 0 ]
|
||||
@@ -633,9 +553,7 @@ void mtxRotateXApply(float* mtx, float deg)
|
||||
mtx[11] = mtx[11]*cosrad - mtx07*sinrad;
|
||||
}
|
||||
|
||||
|
||||
void mtxRotateYApply(float* mtx, float deg)
|
||||
{
|
||||
void mtxRotateYApply(float *mtx, float deg) {
|
||||
// [ 0 4 8 12 ] [ cos 0 -sin 0 ]
|
||||
// [ 1 5 9 13 ] x [ 0 1 0 0 ]
|
||||
// [ 2 6 10 14 ] [ sin 0 cos 0 ]
|
||||
@@ -664,9 +582,7 @@ void mtxRotateYApply(float* mtx, float deg)
|
||||
mtx[11] = mtx[11]*cosrad - mtx03*sinrad;
|
||||
}
|
||||
|
||||
|
||||
void mtxRotateZApply(float* mtx, float deg)
|
||||
{
|
||||
void mtxRotateZApply(float *mtx, float deg) {
|
||||
// [ 0 4 8 12 ] [ cos -sin 0 0 ]
|
||||
// [ 1 5 9 13 ] x [ sin cos 0 0 ]
|
||||
// [ 2 6 10 14 ] [ 0 0 1 0 ]
|
||||
@@ -695,22 +611,14 @@ void mtxRotateZApply(float* mtx, float deg)
|
||||
mtx[ 7] = mtx[ 7]*cosrad - mtx03*sinrad;
|
||||
}
|
||||
|
||||
void mtxRotateApply(float* mtx, float deg, float xAxis, float yAxis, float zAxis)
|
||||
{
|
||||
if(yAxis == 0.0f && zAxis == 0.0f)
|
||||
{
|
||||
void mtxRotateApply(float *mtx, float deg, float xAxis, float yAxis, float zAxis) {
|
||||
if(yAxis == 0.0f && zAxis == 0.0f) {
|
||||
mtxRotateXApply(mtx, deg);
|
||||
}
|
||||
else if(xAxis == 0.0f && zAxis == 0.0f)
|
||||
{
|
||||
} else if(xAxis == 0.0f && zAxis == 0.0f) {
|
||||
mtxRotateYApply(mtx, deg);
|
||||
}
|
||||
else if(xAxis == 0.0f && yAxis == 0.0f)
|
||||
{
|
||||
} else if(xAxis == 0.0f && yAxis == 0.0f) {
|
||||
mtxRotateZApply(mtx, deg);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
float rad = deg * M_PI/180.0f;
|
||||
|
||||
float sin_a = sinf(rad);
|
||||
@@ -780,8 +688,7 @@ void mtxRotateApply(float* mtx, float deg, float xAxis, float yAxis, float zAxis
|
||||
}
|
||||
}
|
||||
|
||||
void mtxScaleMatrix(float* mtx, float xScale, float yScale, float zScale)
|
||||
{
|
||||
void mtxScaleMatrix(float *mtx, float xScale, float yScale, float zScale) {
|
||||
// [ x 0 0 0 ] [ 0 4 8 12 ]
|
||||
// [ 0 y 0 0 ] x [ 1 5 9 13 ]
|
||||
// [ 0 0 z 0 ] [ 2 6 10 14 ]
|
||||
@@ -803,9 +710,7 @@ void mtxScaleMatrix(float* mtx, float xScale, float yScale, float zScale)
|
||||
mtx[14] *= zScale;
|
||||
}
|
||||
|
||||
|
||||
void mtxRotateXMatrix(float* mtx, float rad)
|
||||
{
|
||||
void mtxRotateXMatrix(float *mtx, float rad) {
|
||||
// [ 1 0 0 0 ] [ 0 4 8 12 ]
|
||||
// [ 0 cos -sin 0 ] x [ 1 5 9 13 ]
|
||||
// [ 0 sin cos 0 ] [ 2 6 10 14 ]
|
||||
@@ -832,9 +737,7 @@ void mtxRotateXMatrix(float* mtx, float rad)
|
||||
mtx[14] = sinrad*mtx13 + cosrad*mtx[14];
|
||||
}
|
||||
|
||||
|
||||
void mtxRotateYMatrix(float* mtx, float rad)
|
||||
{
|
||||
void mtxRotateYMatrix(float *mtx, float rad) {
|
||||
// [ cos 0 -sin 0 ] [ 0 4 8 12 ]
|
||||
// [ 0 1 0 0 ] x [ 1 5 9 13 ]
|
||||
// [ sin 0 cos 0 ] [ 2 6 10 14 ]
|
||||
@@ -861,9 +764,7 @@ void mtxRotateYMatrix(float* mtx, float rad)
|
||||
mtx[14] = sinrad*mtx12 + cosrad*mtx[14];
|
||||
}
|
||||
|
||||
|
||||
void mtxRotateZMatrix(float* mtx, float rad)
|
||||
{
|
||||
void mtxRotateZMatrix(float *mtx, float rad) {
|
||||
// [ cos -sin 0 0 ] [ 0 4 8 12 ]
|
||||
// [ sin cos 0 0 ] x [ 1 5 9 13 ]
|
||||
// [ 0 0 1 0 ] [ 2 6 10 14 ]
|
||||
@@ -890,8 +791,7 @@ void mtxRotateZMatrix(float* mtx, float rad)
|
||||
mtx[13] = sinrad*mtx12 + cosrad*mtx[13];
|
||||
}
|
||||
|
||||
void mtxRotateMatrix(float* mtx, float rad, float xAxis, float yAxis, float zAxis)
|
||||
{
|
||||
void mtxRotateMatrix(float *mtx, float rad, float xAxis, float yAxis, float zAxis) {
|
||||
float rotMtx[16];
|
||||
|
||||
mtxLoadRotate(rotMtx, rad, xAxis, yAxis, zAxis);
|
||||
@@ -899,19 +799,14 @@ void mtxRotateMatrix(float* mtx, float rad, float xAxis, float yAxis, float zAxi
|
||||
mtxMultiply(mtx, rotMtx, mtx);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mtx3x3LoadIdentity(float* mtx)
|
||||
{
|
||||
void mtx3x3LoadIdentity(float *mtx) {
|
||||
mtx[0] = mtx[4] = mtx[8] = 1.0f;
|
||||
|
||||
mtx[1] = mtx[2] = mtx[3] =
|
||||
mtx[5] = mtx[6] = mtx[7] = 0.0f;
|
||||
|
||||
}
|
||||
|
||||
void mtx3x3FromTopLeftOf4x4(float* mtx, const float* src)
|
||||
{
|
||||
void mtx3x3FromTopLeftOf4x4(float *mtx, const float *src) {
|
||||
mtx[0] = src[0];
|
||||
mtx[1] = src[1];
|
||||
mtx[2] = src[2];
|
||||
@@ -923,8 +818,7 @@ void mtx3x3FromTopLeftOf4x4(float* mtx, const float* src)
|
||||
mtx[8] = src[10];
|
||||
}
|
||||
|
||||
void mtx3x3Transpose(float* mtx, const float* src)
|
||||
{
|
||||
void mtx3x3Transpose(float *mtx, const float *src) {
|
||||
float tmp;
|
||||
mtx[0] = src[0];
|
||||
mtx[4] = src[4];
|
||||
@@ -943,17 +837,14 @@ void mtx3x3Transpose(float* mtx, const float* src)
|
||||
mtx[7] = tmp;
|
||||
}
|
||||
|
||||
|
||||
void mtx3x3Invert(float* mtx, const float* src)
|
||||
{
|
||||
void mtx3x3Invert(float *mtx, const float *src) {
|
||||
float cpy[9];
|
||||
float det =
|
||||
src[0] * (src[4]*src[8] - src[7]*src[5]) -
|
||||
src[1] * (src[3]*src[8] - src[6]*src[5]) +
|
||||
src[2] * (src[3]*src[7] - src[6]*src[4]);
|
||||
|
||||
if ( fabs( det ) < 0.0005 )
|
||||
{
|
||||
if ( fabs( det ) < 0.0005 ) {
|
||||
mtx3x3LoadIdentity(mtx);
|
||||
return;
|
||||
}
|
||||
@@ -973,8 +864,7 @@ void mtx3x3Invert(float* mtx, const float* src)
|
||||
mtx[8] = cpy[0]*cpy[4] - cpy[1]*cpy[3] / det;
|
||||
}
|
||||
|
||||
void mtx3x3Multiply(float* mtx, const float* lhs, const float* rhs)
|
||||
{
|
||||
void mtx3x3Multiply(float *mtx, const float *lhs, const float *rhs) {
|
||||
mtx[0] = lhs[0]*rhs[0] + lhs[3] * rhs[1] + lhs[6] * rhs[2];
|
||||
mtx[1] = lhs[1]*rhs[0] + lhs[4] * rhs[1] + lhs[7] * rhs[2];
|
||||
mtx[2] = lhs[2]*rhs[0] + lhs[5] * rhs[1] + lhs[8] * rhs[2];
|
||||
|
@@ -1,52 +1,16 @@
|
||||
/*
|
||||
File: matrixUtil.h
|
||||
Abstract:
|
||||
Functions for performing matrix math.
|
||||
|
||||
Version: 1.7
|
||||
|
||||
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
|
||||
Inc. ("Apple") in consideration of your agreement to the following
|
||||
terms, and your use, installation, modification or redistribution of
|
||||
this Apple software constitutes acceptance of these terms. If you do
|
||||
not agree with these terms, please do not use, install, modify or
|
||||
redistribute this Apple software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and
|
||||
subject to these terms, Apple grants you a personal, non-exclusive
|
||||
license, under Apple's copyrights in this original Apple software (the
|
||||
"Apple Software"), to use, reproduce, modify and redistribute the Apple
|
||||
Software, with or without modifications, in source and/or binary forms;
|
||||
provided that if you redistribute the Apple Software in its entirety and
|
||||
without modifications, you must retain this notice and the following
|
||||
text and disclaimers in all such redistributions of the Apple Software.
|
||||
Neither the name, trademarks, service marks or logos of Apple Inc. may
|
||||
be used to endorse or promote products derived from the Apple Software
|
||||
without specific prior written permission from Apple. Except as
|
||||
expressly stated in this notice, no other rights or licenses, express or
|
||||
implied, are granted by Apple herein, including but not limited to any
|
||||
patent rights that may be infringed by your derivative works or by other
|
||||
works in which the Apple Software may be incorporated.
|
||||
|
||||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
|
||||
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
|
||||
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
|
||||
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
|
||||
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
|
||||
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
|
||||
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Copyright (C) 2013 Apple Inc. All Rights Reserved.
|
||||
|
||||
* Apple // emulator for *nix
|
||||
*
|
||||
* This software package is subject to the GNU General Public License
|
||||
* version 2 or later (your choice) as published by the Free Software
|
||||
* Foundation.
|
||||
*
|
||||
* THERE ARE NO WARRANTIES WHATSOEVER.
|
||||
*
|
||||
*/
|
||||
|
||||
// Modified sample code from https://developer.apple.com/library/mac/samplecode/GLEssentials/Introduction/Intro.html
|
||||
|
||||
#ifndef __MATRIX_UTIL_H__
|
||||
#define __MATRIX_UTIL_H__
|
||||
|
||||
@@ -60,99 +24,94 @@
|
||||
// [ 3 7 11 15 ]
|
||||
|
||||
// MTX = LeftHandSideMatrix * RightHandSideMatrix
|
||||
void mtxMultiply(float* ret, const float* lhs, const float* rhs);
|
||||
void mtxMultiply(float *ret, const float *lhs, const float *rhs);
|
||||
|
||||
// MTX = IdentityMatrix
|
||||
void mtxLoadIdentity(float* mtx);
|
||||
void mtxLoadIdentity(float *mtx);
|
||||
|
||||
// MTX = Transpos(SRC)
|
||||
void mtxTranspose(float* mtx, const float* src);
|
||||
void mtxTranspose(float *mtx, const float *src);
|
||||
|
||||
// MTX = src^-1
|
||||
void mtxInvert(float* mtx, const float* src);
|
||||
void mtxInvert(float *mtx, const float *src);
|
||||
|
||||
// MTX = PerspectiveProjectionMatrix
|
||||
void mtxLoadPerspective(float* mtx, float fov, float aspect, float nearZ, float farZ);
|
||||
void mtxLoadPerspective(float *mtx, float fov, float aspect, float nearZ, float farZ);
|
||||
|
||||
// MTX = OrthographicProjectionMatrix
|
||||
void mtxLoadOrthographic(float* mtx,
|
||||
float left, float right,
|
||||
float bottom, float top,
|
||||
float nearZ, float farZ);
|
||||
void mtxLoadOrthographic(float *mtx, float left, float right, float bottom, float top, float nearZ, float farZ);
|
||||
|
||||
// MTX = ObliqueProjectionMatrix(src, clipPlane)
|
||||
void mtxModifyObliqueProjection(float* mtx, const float* src, const float* plane);
|
||||
void mtxModifyObliqueProjection(float *mtx, const float *src, const float *plane);
|
||||
|
||||
// MTX = TranlationMatrix
|
||||
void mtxLoadTranslate(float* mtx, float xTrans, float yTrans, float zTrans);
|
||||
void mtxLoadTranslate(float *mtx, float xTrans, float yTrans, float zTrans);
|
||||
|
||||
// MTX = ScaleMatrix
|
||||
void mtxLoadScale(float* mtx, float xScale, float yScale, float zScale);
|
||||
void mtxLoadScale(float *mtx, float xScale, float yScale, float zScale);
|
||||
|
||||
// MTX = RotateXYZMatrix
|
||||
void mtxLoadRotate(float*mtx, float deg, float xAxis, float , float zAxis);
|
||||
void mtxLoadRotate(float *mtx, float deg, float xAxis, float , float zAxis);
|
||||
|
||||
// MTX = RotateXMatrix
|
||||
void mtxLoadRotateX(float* mtx, float deg);
|
||||
void mtxLoadRotateX(float *mtx, float deg);
|
||||
|
||||
// MTX = RotateYMatrix
|
||||
void mtxLoadRotateY(float* mtx, float deg);
|
||||
void mtxLoadRotateY(float *mtx, float deg);
|
||||
|
||||
// MTX = RotateZMatrix
|
||||
void mtxLoadRotateZ(float* mtx, float deg);
|
||||
void mtxLoadRotateZ(float *mtx, float deg);
|
||||
|
||||
// MTX = MTX * TranslationMatrix - Similar to glTranslate
|
||||
void mtxTranslateApply(float* mtx, float xTrans, float yTrans, float zTrans);
|
||||
void mtxTranslateApply(float *mtx, float xTrans, float yTrans, float zTrans);
|
||||
|
||||
// MTX = MTX * ScaleMatrix - Similar to glScale
|
||||
void mtxScaleApply(float* mtx, float xScale, float yScale, float zScale);
|
||||
void mtxScaleApply(float *mtx, float xScale, float yScale, float zScale);
|
||||
|
||||
// MTX = MTX * RotateXYZMatrix - Similar to glRotate
|
||||
void mtxRotateApply(float* mtx, float deg, float xAxis, float yAxis, float zAxis);
|
||||
void mtxRotateApply(float *mtx, float deg, float xAxis, float yAxis, float zAxis);
|
||||
|
||||
// MTX = MTX * RotateXMatrix
|
||||
void mtxRotateXApply(float* mtx, float rad);
|
||||
void mtxRotateXApply(float *mtx, float rad);
|
||||
|
||||
// MTX = MTX * RotateYMatrix
|
||||
void mtxRotateYApply(float* mtx, float rad);
|
||||
void mtxRotateYApply(float *mtx, float rad);
|
||||
|
||||
// MTX = MTX * RotateZMatrix
|
||||
void mtxRotateZApply(float* mtx, float rad);
|
||||
void mtxRotateZApply(float *mtx, float rad);
|
||||
|
||||
// MTX = TranslationMatrix * MTX
|
||||
void mtxTranslateMatrix(float* mtx, float xTrans, float yTrans, float zTrans);
|
||||
void mtxTranslateMatrix(float *mtx, float xTrans, float yTrans, float zTrans);
|
||||
|
||||
// MTX = ScaleMatrix * MTX
|
||||
void mtxScaleMatrix(float* mtx, float xScale, float yScale, float zScale);
|
||||
void mtxScaleMatrix(float *mtx, float xScale, float yScale, float zScale);
|
||||
|
||||
// MTX = RotateXYZMatrix * MTX
|
||||
void mtxRotateMatrix(float* mtx, float rad, float xAxis, float yAxis, float zAxis);
|
||||
void mtxRotateMatrix(float *mtx, float rad, float xAxis, float yAxis, float zAxis);
|
||||
|
||||
// MTX = RotateXMatrix * MTX
|
||||
void mtxRotateXMatrix(float* mtx, float rad);
|
||||
void mtxRotateXMatrix(float *mtx, float rad);
|
||||
|
||||
// MTX = RotateYMatrix * MTX
|
||||
void mtxRotateYMatrix(float* mtx, float rad);
|
||||
void mtxRotateYMatrix(float *mtx, float rad);
|
||||
|
||||
// MTX = RotateZMatrix * MTX
|
||||
void mtxRotateZMatrix(float* mtx, float rad);
|
||||
|
||||
// 3x3 MTX = 3x3 IdendityMatrix
|
||||
void mtx3x3LoadIdentity(float* mtx);
|
||||
void mtxRotateZMatrix(float *mtx, float rad);
|
||||
|
||||
// 3x3 MTX = 3x3 IdentityMatrix
|
||||
void mtx3x3LoadIdentity(float *mtx);
|
||||
|
||||
// 3x3 MTX = 3x3 LHS x 3x3 RHS
|
||||
void mtx3x3Multiply(float* mtx, const float* lhs, const float* rhs);
|
||||
|
||||
void mtx3x3Multiply(float *mtx, const float *lhs, const float *rhs);
|
||||
|
||||
// 3x3 MTX = TopLeft of MTX
|
||||
void mtx3x3FromTopLeftOf4x4(float* mtx, const float* src);
|
||||
void mtx3x3FromTopLeftOf4x4(float *mtx, const float *src);
|
||||
|
||||
// 3x3 MTX = Transpose(3x3 SRC)
|
||||
void mtx3x3Transpose(float* mtx, const float* src);
|
||||
void mtx3x3Transpose(float *mtx, const float *src);
|
||||
|
||||
// 3x3 MTX = 3x3 SRC^-1
|
||||
void mtx3x3Invert(float* mtx, const float* src);
|
||||
void mtx3x3Invert(float *mtx, const float *src);
|
||||
|
||||
#endif //__MATRIX_UTIL_H__
|
||||
|
||||
|
@@ -1,68 +1,28 @@
|
||||
/*
|
||||
File: modelUtil.c
|
||||
Abstract:
|
||||
Functions for loading a model file for vertex arrays. The model file
|
||||
format used is a simple "binary blob" invented for the purpose of
|
||||
this sample code.
|
||||
|
||||
Version: 1.7
|
||||
|
||||
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
|
||||
Inc. ("Apple") in consideration of your agreement to the following
|
||||
terms, and your use, installation, modification or redistribution of
|
||||
this Apple software constitutes acceptance of these terms. If you do
|
||||
not agree with these terms, please do not use, install, modify or
|
||||
redistribute this Apple software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and
|
||||
subject to these terms, Apple grants you a personal, non-exclusive
|
||||
license, under Apple's copyrights in this original Apple software (the
|
||||
"Apple Software"), to use, reproduce, modify and redistribute the Apple
|
||||
Software, with or without modifications, in source and/or binary forms;
|
||||
provided that if you redistribute the Apple Software in its entirety and
|
||||
without modifications, you must retain this notice and the following
|
||||
text and disclaimers in all such redistributions of the Apple Software.
|
||||
Neither the name, trademarks, service marks or logos of Apple Inc. may
|
||||
be used to endorse or promote products derived from the Apple Software
|
||||
without specific prior written permission from Apple. Except as
|
||||
expressly stated in this notice, no other rights or licenses, express or
|
||||
implied, are granted by Apple herein, including but not limited to any
|
||||
patent rights that may be infringed by your derivative works or by other
|
||||
works in which the Apple Software may be incorporated.
|
||||
|
||||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
|
||||
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
|
||||
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
|
||||
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
|
||||
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
|
||||
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
|
||||
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Copyright (C) 2013 Apple Inc. All Rights Reserved.
|
||||
|
||||
* Apple // emulator for *nix
|
||||
*
|
||||
* This software package is subject to the GNU General Public License
|
||||
* version 2 or later (your choice) as published by the Free Software
|
||||
* Foundation.
|
||||
*
|
||||
* THERE ARE NO WARRANTIES WHATSOEVER.
|
||||
*
|
||||
*/
|
||||
|
||||
// Modified sample code from https://developer.apple.com/library/mac/samplecode/GLEssentials/Introduction/Intro.html
|
||||
|
||||
#include "modelUtil.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct modelHeaderRec
|
||||
{
|
||||
typedef struct modelHeaderRec {
|
||||
char fileIdentifier[30];
|
||||
unsigned int majorVersion;
|
||||
unsigned int minorVersion;
|
||||
} modelHeader;
|
||||
|
||||
typedef struct modelTOCRec
|
||||
{
|
||||
typedef struct modelTOCRec {
|
||||
unsigned int attribHeaderSize;
|
||||
unsigned int byteElementOffset;
|
||||
unsigned int bytePositionOffset;
|
||||
@@ -70,8 +30,7 @@ typedef struct modelTOCRec
|
||||
unsigned int byteNormalOffset;
|
||||
} modelTOC;
|
||||
|
||||
typedef struct modelAttribRec
|
||||
{
|
||||
typedef struct modelAttribRec {
|
||||
unsigned int byteSize;
|
||||
GLenum datatype;
|
||||
GLenum primType; //If index data
|
||||
@@ -79,89 +38,68 @@ typedef struct modelAttribRec
|
||||
unsigned int numElements;
|
||||
} modelAttrib;
|
||||
|
||||
demoModel* mdlLoadModel(const char* filepathname)
|
||||
{
|
||||
if(NULL == filepathname)
|
||||
{
|
||||
demoModel *mdlLoadModel(const char *filepathname) {
|
||||
if (!filepathname) {
|
||||
return NULL;
|
||||
}
|
||||
demoModel *model = (demoModel *)calloc(sizeof(demoModel), 1);
|
||||
if (!model) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
demoModel* model = (demoModel*) calloc(sizeof(demoModel), 1);
|
||||
size_t sizeRead = 0;
|
||||
int error = 0;
|
||||
FILE *curFile = fopen(filepathname, "r");
|
||||
|
||||
if(NULL == model)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
size_t sizeRead;
|
||||
int error;
|
||||
FILE* curFile = fopen(filepathname, "r");
|
||||
|
||||
if(!curFile)
|
||||
{
|
||||
if (!curFile) {
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
modelHeader header;
|
||||
|
||||
modelHeader header = { 0 };
|
||||
sizeRead = fread(&header, 1, sizeof(modelHeader), curFile);
|
||||
|
||||
if(sizeRead != sizeof(modelHeader))
|
||||
{
|
||||
if (sizeRead != sizeof(modelHeader)) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(strncmp(header.fileIdentifier, "AppleOpenGLDemoModelWWDC2010", sizeof(header.fileIdentifier)))
|
||||
{
|
||||
if (strncmp(header.fileIdentifier, "AppleOpenGLDemoModelWWDC2010", sizeof(header.fileIdentifier))) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(header.majorVersion != 0 && header.minorVersion != 1)
|
||||
{
|
||||
if (header.majorVersion != 0 && header.minorVersion != 1) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
modelTOC toc;
|
||||
|
||||
modelTOC toc = { 0 };
|
||||
sizeRead = fread(&toc, 1, sizeof(modelTOC), curFile);
|
||||
|
||||
if(sizeRead != sizeof(modelTOC))
|
||||
{
|
||||
if (sizeRead != sizeof(modelTOC)) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(toc.attribHeaderSize > sizeof(modelAttrib))
|
||||
{
|
||||
if (toc.attribHeaderSize > sizeof(modelAttrib)) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
modelAttrib attrib;
|
||||
|
||||
modelAttrib attrib = { 0 };
|
||||
error = fseek(curFile, toc.byteElementOffset, SEEK_SET);
|
||||
|
||||
if(error < 0)
|
||||
{
|
||||
if (error < 0) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sizeRead = fread(&attrib, 1, toc.attribHeaderSize, curFile);
|
||||
|
||||
if(sizeRead != toc.attribHeaderSize)
|
||||
{
|
||||
if (sizeRead != toc.attribHeaderSize) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
@@ -172,52 +110,42 @@ demoModel* mdlLoadModel(const char* filepathname)
|
||||
model->numElements = attrib.numElements;
|
||||
|
||||
// OpenGL ES cannot use UNSIGNED_INT elements
|
||||
// So if the model has UI element...
|
||||
if(GL_UNSIGNED_INT == model->elementType)
|
||||
{
|
||||
//...Load the UI elements and convert to UNSIGNED_SHORT
|
||||
// so if the model has UI element...
|
||||
if (GL_UNSIGNED_INT == model->elementType) {
|
||||
// ...load the UI elements and convert to UNSIGNED_SHORT
|
||||
|
||||
GLubyte* uiElements = (GLubyte*) malloc(model->elementArraySize);
|
||||
GLubyte *uiElements = (GLubyte *)malloc(model->elementArraySize);
|
||||
size_t ushortElementArraySize = model->numElements * sizeof(GLushort);
|
||||
model->elements = (GLubyte*)malloc(ushortElementArraySize);
|
||||
model->elements = (GLubyte *)malloc(ushortElementArraySize);
|
||||
|
||||
sizeRead = fread(uiElements, 1, model->elementArraySize, curFile);
|
||||
|
||||
if(sizeRead != model->elementArraySize)
|
||||
{
|
||||
if (sizeRead != model->elementArraySize) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GLuint elemNum = 0;
|
||||
for(elemNum = 0; elemNum < model->numElements; elemNum++)
|
||||
{
|
||||
//We can't handle this model if an element is out of the UNSIGNED_INT range
|
||||
if(((GLuint*)uiElements)[elemNum] >= 0xFFFF)
|
||||
{
|
||||
for (elemNum = 0; elemNum < model->numElements; elemNum++) {
|
||||
// can't handle this model if an element is out of the UNSIGNED_INT range
|
||||
if (((GLuint *)uiElements)[elemNum] >= 0xFFFF) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
((GLushort*)model->elements)[elemNum] = ((GLuint*)uiElements)[elemNum];
|
||||
((GLushort *)model->elements)[elemNum] = ((GLuint *)uiElements)[elemNum];
|
||||
}
|
||||
|
||||
free(uiElements);
|
||||
|
||||
|
||||
model->elementType = GL_UNSIGNED_SHORT;
|
||||
model->elementArraySize = model->numElements * sizeof(GLushort);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
model->elements = (GLubyte*)malloc(model->elementArraySize);
|
||||
|
||||
sizeRead = fread(model->elements, 1, model->elementArraySize, curFile);
|
||||
|
||||
if(sizeRead != model->elementArraySize)
|
||||
{
|
||||
if (sizeRead != model->elementArraySize) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
@@ -225,11 +153,8 @@ demoModel* mdlLoadModel(const char* filepathname)
|
||||
}
|
||||
|
||||
fseek(curFile, toc.bytePositionOffset, SEEK_SET);
|
||||
|
||||
sizeRead = fread(&attrib, 1, toc.attribHeaderSize, curFile);
|
||||
|
||||
if(sizeRead != toc.attribHeaderSize)
|
||||
{
|
||||
if (sizeRead != toc.attribHeaderSize) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
@@ -242,27 +167,21 @@ demoModel* mdlLoadModel(const char* filepathname)
|
||||
model->positions = (GLubyte*) malloc(model->positionArraySize);
|
||||
|
||||
sizeRead = fread(model->positions, 1, model->positionArraySize, curFile);
|
||||
|
||||
if(sizeRead != model->positionArraySize)
|
||||
{
|
||||
if (sizeRead != model->positionArraySize) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
error = fseek(curFile, toc.byteTexcoordOffset, SEEK_SET);
|
||||
|
||||
if(error < 0)
|
||||
{
|
||||
if (error < 0) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sizeRead = fread(&attrib, 1, toc.attribHeaderSize, curFile);
|
||||
|
||||
if(sizeRead != toc.attribHeaderSize)
|
||||
{
|
||||
if (sizeRead != toc.attribHeaderSize) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
@@ -272,9 +191,8 @@ demoModel* mdlLoadModel(const char* filepathname)
|
||||
model->texcoordType = attrib.datatype;
|
||||
model->texcoordSize = attrib.sizePerElement;
|
||||
|
||||
//Must have the same number of texcoords as positions
|
||||
if(model->numVertices != attrib.numElements)
|
||||
{
|
||||
// must have the same number of texcoords as positions
|
||||
if (model->numVertices != attrib.numElements) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
@@ -283,18 +201,14 @@ demoModel* mdlLoadModel(const char* filepathname)
|
||||
model->texcoords = (GLubyte*) malloc(model->texcoordArraySize);
|
||||
|
||||
sizeRead = fread(model->texcoords, 1, model->texcoordArraySize, curFile);
|
||||
|
||||
if(sizeRead != model->texcoordArraySize)
|
||||
{
|
||||
if (sizeRead != model->texcoordArraySize) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
error = fseek(curFile, toc.byteNormalOffset, SEEK_SET);
|
||||
|
||||
if(error < 0)
|
||||
{
|
||||
if (error < 0) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
@@ -302,8 +216,7 @@ demoModel* mdlLoadModel(const char* filepathname)
|
||||
|
||||
sizeRead = fread(&attrib, 1, toc.attribHeaderSize, curFile);
|
||||
|
||||
if(sizeRead != toc.attribHeaderSize)
|
||||
{
|
||||
if (sizeRead != toc.attribHeaderSize) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
@@ -313,9 +226,8 @@ demoModel* mdlLoadModel(const char* filepathname)
|
||||
model->normalType = attrib.datatype;
|
||||
model->normalSize = attrib.sizePerElement;
|
||||
|
||||
//Must have the same number of normals as positions
|
||||
if(model->numVertices != attrib.numElements)
|
||||
{
|
||||
// must have the same number of normals as positions
|
||||
if (model->numVertices != attrib.numElements) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
@@ -324,9 +236,7 @@ demoModel* mdlLoadModel(const char* filepathname)
|
||||
model->normals = (GLubyte*) malloc(model->normalArraySize );
|
||||
|
||||
sizeRead = fread(model->normals, 1, model->normalArraySize , curFile);
|
||||
|
||||
if(sizeRead != model->normalArraySize)
|
||||
{
|
||||
if (sizeRead != model->normalArraySize) {
|
||||
fclose(curFile);
|
||||
mdlDestroyModel(model);
|
||||
return NULL;
|
||||
@@ -337,8 +247,7 @@ demoModel* mdlLoadModel(const char* filepathname)
|
||||
return model;
|
||||
}
|
||||
|
||||
demoModel* mdlLoadQuadModel()
|
||||
{
|
||||
demoModel *mdlLoadQuadModel() {
|
||||
GLfloat posArray[] = {
|
||||
-200.0f, 0.0f, -200.0f,
|
||||
200.0f, 0.0f, -200.0f,
|
||||
@@ -360,16 +269,14 @@ demoModel* mdlLoadQuadModel()
|
||||
0.0f, 0.0f, 1.0f,
|
||||
};
|
||||
|
||||
GLushort elementArray[] =
|
||||
{
|
||||
GLushort elementArray[] = {
|
||||
0, 2, 1,
|
||||
0, 3, 2
|
||||
};
|
||||
|
||||
demoModel* model = (demoModel*) calloc(sizeof(demoModel), 1);
|
||||
demoModel *model = (demoModel *)calloc(sizeof(demoModel), 1);
|
||||
|
||||
if(NULL == model)
|
||||
{
|
||||
if (!model) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -397,7 +304,6 @@ demoModel* mdlLoadQuadModel()
|
||||
|
||||
model->primType = GL_TRIANGLES;
|
||||
|
||||
|
||||
model->numElements = sizeof(elementArray) / sizeof(GLushort);
|
||||
model->elementType = GL_UNSIGNED_SHORT;
|
||||
model->numVertices = model->positionArraySize / (model->positionSize * sizeof(GLfloat));
|
||||
@@ -405,10 +311,8 @@ demoModel* mdlLoadQuadModel()
|
||||
return model;
|
||||
}
|
||||
|
||||
void mdlDestroyModel(demoModel* model)
|
||||
{
|
||||
if(NULL == model)
|
||||
{
|
||||
void mdlDestroyModel(demoModel *model) {
|
||||
if (!model) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -1,61 +1,22 @@
|
||||
/*
|
||||
File: modelUtil.h
|
||||
Abstract:
|
||||
Functions for loading a model file for vertex arrays. The model file
|
||||
format used is a simple "binary blob" invented for the purpose of
|
||||
this sample code.
|
||||
|
||||
Version: 1.7
|
||||
|
||||
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
|
||||
Inc. ("Apple") in consideration of your agreement to the following
|
||||
terms, and your use, installation, modification or redistribution of
|
||||
this Apple software constitutes acceptance of these terms. If you do
|
||||
not agree with these terms, please do not use, install, modify or
|
||||
redistribute this Apple software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and
|
||||
subject to these terms, Apple grants you a personal, non-exclusive
|
||||
license, under Apple's copyrights in this original Apple software (the
|
||||
"Apple Software"), to use, reproduce, modify and redistribute the Apple
|
||||
Software, with or without modifications, in source and/or binary forms;
|
||||
provided that if you redistribute the Apple Software in its entirety and
|
||||
without modifications, you must retain this notice and the following
|
||||
text and disclaimers in all such redistributions of the Apple Software.
|
||||
Neither the name, trademarks, service marks or logos of Apple Inc. may
|
||||
be used to endorse or promote products derived from the Apple Software
|
||||
without specific prior written permission from Apple. Except as
|
||||
expressly stated in this notice, no other rights or licenses, express or
|
||||
implied, are granted by Apple herein, including but not limited to any
|
||||
patent rights that may be infringed by your derivative works or by other
|
||||
works in which the Apple Software may be incorporated.
|
||||
|
||||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
|
||||
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
|
||||
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
|
||||
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
|
||||
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
|
||||
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
|
||||
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Copyright (C) 2013 Apple Inc. All Rights Reserved.
|
||||
|
||||
* Apple // emulator for *nix
|
||||
*
|
||||
* This software package is subject to the GNU General Public License
|
||||
* version 2 or later (your choice) as published by the Free Software
|
||||
* Foundation.
|
||||
*
|
||||
* THERE ARE NO WARRANTIES WHATSOEVER.
|
||||
*
|
||||
*/
|
||||
|
||||
// Modified sample code from https://developer.apple.com/library/mac/samplecode/GLEssentials/Introduction/Intro.html
|
||||
|
||||
#ifndef __MODEL_UTIL_H__
|
||||
#define __MODEL_UTIL_H__
|
||||
|
||||
#include "glUtil.h"
|
||||
|
||||
typedef struct demoModelRec
|
||||
{
|
||||
typedef struct demoModelRec {
|
||||
GLuint numVertices;
|
||||
|
||||
GLubyte *positions;
|
||||
@@ -82,10 +43,10 @@ typedef struct demoModelRec
|
||||
|
||||
} demoModel;
|
||||
|
||||
demoModel* mdlLoadModel(const char* filepathname);
|
||||
demoModel *mdlLoadModel(const char *filepathname);
|
||||
|
||||
demoModel* mdlLoadQuadModel();
|
||||
demoModel *mdlLoadQuadModel();
|
||||
|
||||
void mdlDestroyModel(demoModel* model);
|
||||
void mdlDestroyModel(demoModel *model);
|
||||
|
||||
#endif //__MODEL_UTIL_H__
|
||||
|
@@ -1,80 +1,38 @@
|
||||
/*
|
||||
File: sourceUtil.c
|
||||
Abstract:
|
||||
Functions for loading source files for shaders.
|
||||
|
||||
Version: 1.7
|
||||
|
||||
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
|
||||
Inc. ("Apple") in consideration of your agreement to the following
|
||||
terms, and your use, installation, modification or redistribution of
|
||||
this Apple software constitutes acceptance of these terms. If you do
|
||||
not agree with these terms, please do not use, install, modify or
|
||||
redistribute this Apple software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and
|
||||
subject to these terms, Apple grants you a personal, non-exclusive
|
||||
license, under Apple's copyrights in this original Apple software (the
|
||||
"Apple Software"), to use, reproduce, modify and redistribute the Apple
|
||||
Software, with or without modifications, in source and/or binary forms;
|
||||
provided that if you redistribute the Apple Software in its entirety and
|
||||
without modifications, you must retain this notice and the following
|
||||
text and disclaimers in all such redistributions of the Apple Software.
|
||||
Neither the name, trademarks, service marks or logos of Apple Inc. may
|
||||
be used to endorse or promote products derived from the Apple Software
|
||||
without specific prior written permission from Apple. Except as
|
||||
expressly stated in this notice, no other rights or licenses, express or
|
||||
implied, are granted by Apple herein, including but not limited to any
|
||||
patent rights that may be infringed by your derivative works or by other
|
||||
works in which the Apple Software may be incorporated.
|
||||
|
||||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
|
||||
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
|
||||
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
|
||||
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
|
||||
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
|
||||
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
|
||||
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Copyright (C) 2013 Apple Inc. All Rights Reserved.
|
||||
|
||||
* Apple // emulator for *nix
|
||||
*
|
||||
* This software package is subject to the GNU General Public License
|
||||
* version 2 or later (your choice) as published by the Free Software
|
||||
* Foundation.
|
||||
*
|
||||
* THERE ARE NO WARRANTIES WHATSOEVER.
|
||||
*
|
||||
*/
|
||||
|
||||
// Based on sample code from https://developer.apple.com/library/mac/samplecode/GLEssentials/Introduction/Intro.html
|
||||
|
||||
#include "sourceUtil.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
demoSource* srcLoadSource(const char* filepathname)
|
||||
{
|
||||
demoSource* source = (demoSource*) calloc(sizeof(demoSource), 1);
|
||||
demoSource *srcLoadSource(const char *filepathname) {
|
||||
demoSource *source = (demoSource *)calloc(sizeof(demoSource), 1);
|
||||
|
||||
// Check the file name suffix to determine what type of shader this is
|
||||
const char* suffixBegin = filepathname + strlen(filepathname) - 4;
|
||||
const char *suffixBegin = filepathname + strlen(filepathname) - 4;
|
||||
|
||||
if(0 == strncmp(suffixBegin, ".fsh", 4))
|
||||
{
|
||||
if (!strncmp(suffixBegin, ".fsh", 4)) {
|
||||
source->shaderType = GL_FRAGMENT_SHADER;
|
||||
}
|
||||
else if(0 == strncmp(suffixBegin, ".vsh", 4))
|
||||
{
|
||||
} else if (!strncmp(suffixBegin, ".vsh", 4)) {
|
||||
source->shaderType = GL_VERTEX_SHADER;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Unknown suffix
|
||||
source->shaderType = 0;
|
||||
}
|
||||
|
||||
FILE* curFile = fopen(filepathname, "r");
|
||||
FILE *curFile = fopen(filepathname, "r");
|
||||
|
||||
// Get the size of the source
|
||||
fseek(curFile, 0, SEEK_END);
|
||||
@@ -98,8 +56,8 @@ demoSource* srcLoadSource(const char* filepathname)
|
||||
return source;
|
||||
}
|
||||
|
||||
void srcDestroySource(demoSource* source)
|
||||
{
|
||||
void srcDestroySource(demoSource *source) {
|
||||
free(source->string);
|
||||
free(source);
|
||||
}
|
||||
|
||||
|
@@ -1,69 +1,29 @@
|
||||
/*
|
||||
File: sourceUtil.h
|
||||
Abstract:
|
||||
Functions for loading source files for shaders.
|
||||
|
||||
Version: 1.7
|
||||
|
||||
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
|
||||
Inc. ("Apple") in consideration of your agreement to the following
|
||||
terms, and your use, installation, modification or redistribution of
|
||||
this Apple software constitutes acceptance of these terms. If you do
|
||||
not agree with these terms, please do not use, install, modify or
|
||||
redistribute this Apple software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and
|
||||
subject to these terms, Apple grants you a personal, non-exclusive
|
||||
license, under Apple's copyrights in this original Apple software (the
|
||||
"Apple Software"), to use, reproduce, modify and redistribute the Apple
|
||||
Software, with or without modifications, in source and/or binary forms;
|
||||
provided that if you redistribute the Apple Software in its entirety and
|
||||
without modifications, you must retain this notice and the following
|
||||
text and disclaimers in all such redistributions of the Apple Software.
|
||||
Neither the name, trademarks, service marks or logos of Apple Inc. may
|
||||
be used to endorse or promote products derived from the Apple Software
|
||||
without specific prior written permission from Apple. Except as
|
||||
expressly stated in this notice, no other rights or licenses, express or
|
||||
implied, are granted by Apple herein, including but not limited to any
|
||||
patent rights that may be infringed by your derivative works or by other
|
||||
works in which the Apple Software may be incorporated.
|
||||
|
||||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
|
||||
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
|
||||
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
|
||||
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
|
||||
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
|
||||
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
|
||||
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Copyright (C) 2013 Apple Inc. All Rights Reserved.
|
||||
|
||||
* Apple // emulator for *nix
|
||||
*
|
||||
* This software package is subject to the GNU General Public License
|
||||
* version 2 or later (your choice) as published by the Free Software
|
||||
* Foundation.
|
||||
*
|
||||
* THERE ARE NO WARRANTIES WHATSOEVER.
|
||||
*
|
||||
*/
|
||||
|
||||
// Modified sample code from https://developer.apple.com/library/mac/samplecode/GLEssentials/Introduction/Intro.html
|
||||
|
||||
#ifndef __SOURCE_UTIL_H__
|
||||
#define __SOURCE_UTIL_H__
|
||||
|
||||
#include "glUtil.h"
|
||||
|
||||
typedef struct demoSourceRec
|
||||
{
|
||||
GLchar* string;
|
||||
|
||||
typedef struct demoSourceRec {
|
||||
GLchar *string;
|
||||
GLsizei byteSize;
|
||||
|
||||
GLenum shaderType; // Vertex or Fragment
|
||||
|
||||
} demoSource;
|
||||
|
||||
demoSource* srcLoadSource(const char* filepathname);
|
||||
demoSource *srcLoadSource(const char *filepathname);
|
||||
|
||||
void srcDestroySource(demoSource* source);
|
||||
void srcDestroySource(demoSource *source);
|
||||
|
||||
#endif // __SOURCE_UTIL_H__
|
||||
|
104
src/video_util/vectorUtil.c
Executable file → Normal file
104
src/video_util/vectorUtil.c
Executable file → Normal file
@@ -1,157 +1,101 @@
|
||||
/*
|
||||
File: vectorUtil.c
|
||||
Abstract:
|
||||
Functions for performing vector math.
|
||||
|
||||
Version: 1.7
|
||||
|
||||
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
|
||||
Inc. ("Apple") in consideration of your agreement to the following
|
||||
terms, and your use, installation, modification or redistribution of
|
||||
this Apple software constitutes acceptance of these terms. If you do
|
||||
not agree with these terms, please do not use, install, modify or
|
||||
redistribute this Apple software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and
|
||||
subject to these terms, Apple grants you a personal, non-exclusive
|
||||
license, under Apple's copyrights in this original Apple software (the
|
||||
"Apple Software"), to use, reproduce, modify and redistribute the Apple
|
||||
Software, with or without modifications, in source and/or binary forms;
|
||||
provided that if you redistribute the Apple Software in its entirety and
|
||||
without modifications, you must retain this notice and the following
|
||||
text and disclaimers in all such redistributions of the Apple Software.
|
||||
Neither the name, trademarks, service marks or logos of Apple Inc. may
|
||||
be used to endorse or promote products derived from the Apple Software
|
||||
without specific prior written permission from Apple. Except as
|
||||
expressly stated in this notice, no other rights or licenses, express or
|
||||
implied, are granted by Apple herein, including but not limited to any
|
||||
patent rights that may be infringed by your derivative works or by other
|
||||
works in which the Apple Software may be incorporated.
|
||||
|
||||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
|
||||
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
|
||||
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
|
||||
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
|
||||
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
|
||||
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
|
||||
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Copyright (C) 2013 Apple Inc. All Rights Reserved.
|
||||
|
||||
* Apple // emulator for *nix
|
||||
*
|
||||
* This software package is subject to the GNU General Public License
|
||||
* version 2 or later (your choice) as published by the Free Software
|
||||
* Foundation.
|
||||
*
|
||||
* THERE ARE NO WARRANTIES WHATSOEVER.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "vectorUtil.h"
|
||||
// Modified sample code from https://developer.apple.com/library/mac/samplecode/GLEssentials/Introduction/Intro.html
|
||||
|
||||
#include "vectorUtil.h"
|
||||
#include <math.h>
|
||||
#include <memory.h>
|
||||
|
||||
void vec4Add(float* vec, const float* lhs, const float* rhs)
|
||||
{
|
||||
void vec4Add(float *vec, const float *lhs, const float *rhs) {
|
||||
vec[0] = lhs[0] + rhs[0];
|
||||
vec[1] = lhs[1] + rhs[1];
|
||||
vec[2] = lhs[2] + rhs[2];
|
||||
vec[3] = lhs[3] + rhs[3];
|
||||
}
|
||||
|
||||
void vec4Subtract(float* vec, const float* lhs, const float* rhs)
|
||||
{
|
||||
void vec4Subtract(float *vec, const float *lhs, const float *rhs) {
|
||||
vec[0] = lhs[0] - rhs[0];
|
||||
vec[1] = lhs[1] - rhs[1];
|
||||
vec[2] = lhs[2] - rhs[2];
|
||||
vec[3] = lhs[3] - rhs[3];
|
||||
}
|
||||
|
||||
|
||||
void vec4Multiply(float* vec, const float* lhs, const float* rhs)
|
||||
{
|
||||
void vec4Multiply(float *vec, const float *lhs, const float *rhs) {
|
||||
vec[0] = lhs[0] * rhs[0];
|
||||
vec[1] = lhs[1] * rhs[1];
|
||||
vec[2] = lhs[2] * rhs[2];
|
||||
vec[3] = lhs[3] * rhs[3];
|
||||
}
|
||||
|
||||
void vec4Divide(float* vec, const float* lhs, const float* rhs)
|
||||
{
|
||||
void vec4Divide(float *vec, const float *lhs, const float *rhs) {
|
||||
vec[0] = lhs[0] / rhs[0];
|
||||
vec[1] = lhs[1] / rhs[1];
|
||||
vec[2] = lhs[2] / rhs[2];
|
||||
vec[3] = lhs[3] / rhs[3];
|
||||
}
|
||||
|
||||
|
||||
void vec3Add(float* vec, const float* lhs, const float* rhs)
|
||||
{
|
||||
void vec3Add(float *vec, const float *lhs, const float *rhs) {
|
||||
vec[0] = lhs[0] + rhs[0];
|
||||
vec[1] = lhs[1] + rhs[1];
|
||||
vec[2] = lhs[2] + rhs[2];
|
||||
}
|
||||
|
||||
void vec3Subtract(float* vec, const float* lhs, const float* rhs)
|
||||
{
|
||||
void vec3Subtract(float *vec, const float *lhs, const float *rhs) {
|
||||
vec[0] = lhs[0] - rhs[0];
|
||||
vec[1] = lhs[1] - rhs[1];
|
||||
vec[2] = lhs[2] - rhs[2];
|
||||
}
|
||||
|
||||
|
||||
void vec3Multiply(float* vec, const float* lhs, const float* rhs)
|
||||
{
|
||||
void vec3Multiply(float *vec, const float *lhs, const float *rhs) {
|
||||
vec[0] = lhs[0] * rhs[0];
|
||||
vec[1] = lhs[1] * rhs[1];
|
||||
vec[2] = lhs[2] * rhs[2];
|
||||
}
|
||||
|
||||
void vec3Divide(float* vec, const float* lhs, const float* rhs)
|
||||
{
|
||||
void vec3Divide(float *vec, const float *lhs, const float *rhs) {
|
||||
vec[0] = lhs[0] / rhs[0];
|
||||
vec[1] = lhs[1] / rhs[1];
|
||||
vec[2] = lhs[2] / rhs[2];
|
||||
}
|
||||
|
||||
float vec3DotProduct(const float* lhs, const float* rhs)
|
||||
{
|
||||
float vec3DotProduct(const float *lhs, const float *rhs) {
|
||||
return lhs[0]*rhs[0] + lhs[1]*rhs[1] + lhs[2]*rhs[2];
|
||||
}
|
||||
|
||||
float vec4DotProduct(const float* lhs, const float* rhs)
|
||||
{
|
||||
float vec4DotProduct(const float *lhs, const float *rhs) {
|
||||
return lhs[0]*rhs[0] + lhs[1]*rhs[1] + lhs[2]*rhs[2] + lhs[3]*rhs[3];
|
||||
}
|
||||
|
||||
void vec3CrossProduct(float* vec, const float* lhs, const float* rhs)
|
||||
{
|
||||
void vec3CrossProduct(float *vec, const float *lhs, const float *rhs) {
|
||||
vec[0] = lhs[1] * rhs[2] - lhs[2] * rhs[1];
|
||||
vec[1] = lhs[2] * rhs[0] - lhs[0] * rhs[2];
|
||||
vec[2] = lhs[0] * rhs[1] - lhs[1] * rhs[0];
|
||||
}
|
||||
|
||||
float vec3Length(const float* vec)
|
||||
{
|
||||
float vec3Length(const float *vec) {
|
||||
return sqrtf(vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2]);
|
||||
}
|
||||
|
||||
float vec3Distance(const float* pointA, const float* pointB)
|
||||
{
|
||||
float vec3Distance(const float *pointA, const float *pointB) {
|
||||
float diffx = pointA[0]-pointB[0];
|
||||
float diffy = pointA[1]-pointB[1];
|
||||
float diffz = pointA[2]-pointB[2];
|
||||
return sqrtf(diffx*diffx + diffy*diffy + diffz*diffz);
|
||||
}
|
||||
|
||||
void vec3Normalize(float* vec, const float* src)
|
||||
{
|
||||
void vec3Normalize(float *vec, const float *src) {
|
||||
float length = vec3Length(src);
|
||||
|
||||
vec[0] = src[0]/length;
|
||||
vec[1] = src[1]/length;
|
||||
vec[2] = src[2]/length;
|
||||
}
|
||||
|
||||
|
||||
|
84
src/video_util/vectorUtil.h
Executable file → Normal file
84
src/video_util/vectorUtil.h
Executable file → Normal file
@@ -1,52 +1,16 @@
|
||||
/*
|
||||
File: vectorUtil.h
|
||||
Abstract:
|
||||
Functions for performing vector math.
|
||||
|
||||
Version: 1.7
|
||||
|
||||
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
|
||||
Inc. ("Apple") in consideration of your agreement to the following
|
||||
terms, and your use, installation, modification or redistribution of
|
||||
this Apple software constitutes acceptance of these terms. If you do
|
||||
not agree with these terms, please do not use, install, modify or
|
||||
redistribute this Apple software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and
|
||||
subject to these terms, Apple grants you a personal, non-exclusive
|
||||
license, under Apple's copyrights in this original Apple software (the
|
||||
"Apple Software"), to use, reproduce, modify and redistribute the Apple
|
||||
Software, with or without modifications, in source and/or binary forms;
|
||||
provided that if you redistribute the Apple Software in its entirety and
|
||||
without modifications, you must retain this notice and the following
|
||||
text and disclaimers in all such redistributions of the Apple Software.
|
||||
Neither the name, trademarks, service marks or logos of Apple Inc. may
|
||||
be used to endorse or promote products derived from the Apple Software
|
||||
without specific prior written permission from Apple. Except as
|
||||
expressly stated in this notice, no other rights or licenses, express or
|
||||
implied, are granted by Apple herein, including but not limited to any
|
||||
patent rights that may be infringed by your derivative works or by other
|
||||
works in which the Apple Software may be incorporated.
|
||||
|
||||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
|
||||
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
|
||||
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
|
||||
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
|
||||
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
|
||||
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
|
||||
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Copyright (C) 2013 Apple Inc. All Rights Reserved.
|
||||
|
||||
* Apple // emulator for *nix
|
||||
*
|
||||
* This software package is subject to the GNU General Public License
|
||||
* version 2 or later (your choice) as published by the Free Software
|
||||
* Foundation.
|
||||
*
|
||||
* THERE ARE NO WARRANTIES WHATSOEVER.
|
||||
*
|
||||
*/
|
||||
|
||||
// Modified sample code from https://developer.apple.com/library/mac/samplecode/GLEssentials/Introduction/Intro.html
|
||||
|
||||
#ifndef __VECTOR_UTIL_H__
|
||||
#define __VECTOR_UTIL_H__
|
||||
|
||||
@@ -55,46 +19,46 @@
|
||||
// functions with vec3 prefix require only 3 elements in the array
|
||||
|
||||
// Subtracts one 4D vector to another
|
||||
void vec4Add(float* vec, const float* lhs, const float* rhs);
|
||||
void vec4Add(float *vec, const float *lhs, const float *rhs);
|
||||
|
||||
// Subtracts one 4D vector from another
|
||||
void vec4Subtract(float* vec, const float* lhs, const float* rhs);
|
||||
void vec4Subtract(float *vec, const float *lhs, const float *rhs);
|
||||
|
||||
// Multiplys one 4D vector by another
|
||||
void vec4Multiply(float* vec, const float* lhs, const float* rhs);
|
||||
void vec4Multiply(float *vec, const float *lhs, const float *rhs);
|
||||
|
||||
// Divides one 4D vector by another
|
||||
void vec4Divide(float* vec, const float* lhs, const float* rhs);
|
||||
void vec4Divide(float *vec, const float *lhs, const float *rhs);
|
||||
|
||||
// Subtracts one 4D vector to another
|
||||
void vec3Add(float* vec, const float* lhs, const float* rhs);
|
||||
void vec3Add(float *vec, const float *lhs, const float *rhs);
|
||||
|
||||
// Subtracts one 4D vector from another
|
||||
void vec3Subtract(float* vec, const float* lhs, const float* rhs);
|
||||
void vec3Subtract(float *vec, const float *lhs, const float *rhs);
|
||||
|
||||
// Multiplys one 4D vector by another
|
||||
void vec3Multiply(float* vec, const float* lhs, const float* rhs);
|
||||
void vec3Multiply(float *vec, const float *lhs, const float *rhs);
|
||||
|
||||
// Divides one 4D vector by another
|
||||
void vec3Divide(float* vec, const float* lhs, const float* rhs);
|
||||
void vec3Divide(float *vec, const float *lhs, const float *rhs);
|
||||
|
||||
// Calculates the Cross Product of a 3D vector
|
||||
void vec3CrossProduct(float* vec, const float* lhs, const float* rhs);
|
||||
void vec3CrossProduct(float *vec, const float *lhs, const float *rhs);
|
||||
|
||||
// Normalizes a 3D vector
|
||||
void vec3Normalize(float* vec, const float* src);
|
||||
void vec3Normalize(float *vec, const float *src);
|
||||
|
||||
// Returns the Dot Product of 2 3D vectors
|
||||
float vec3DotProduct(const float* lhs, const float* rhs);
|
||||
float vec3DotProduct(const float *lhs, const float *rhs);
|
||||
|
||||
// Returns the Dot Product of 2 4D vectors
|
||||
float vec4DotProduct(const float* lhs, const float* rhs);
|
||||
float vec4DotProduct(const float *lhs, const float *rhs);
|
||||
|
||||
// Returns the length of a 3D vector
|
||||
// (i.e the distance of a point from the origin)
|
||||
float vec3Length(const float* vec);
|
||||
float vec3Length(const float *vec);
|
||||
|
||||
// Returns the distance between two 3D points
|
||||
float vec3Distance(const float* pointA, const float* pointB);
|
||||
float vec3Distance(const float *pointA, const float *pointB);
|
||||
|
||||
#endif //__VECTOR_UTIL_H__
|
||||
|
Reference in New Issue
Block a user