mirror of
https://github.com/mauiaaron/apple2.git
synced 2025-01-30 12:33:15 +00:00
Move common function to base class
This commit is contained in:
parent
142f0181bc
commit
725cf68011
@ -28,6 +28,7 @@ void glhud_setupDefault(GLModel *parent) {
|
||||
const unsigned int rows = hudElement->tplHeight;
|
||||
uint8_t *fb = hudElement->pixels;
|
||||
|
||||
#warning FIXME I AM HERE : verify this does not overwrite memory
|
||||
// render template into indexed fb
|
||||
interface_printMessageCentered(fb, cols, rows, RED_ON_BLACK, submenu, cols, rows);
|
||||
|
||||
@ -107,3 +108,46 @@ void glhud_destroyDefault(GLModel *parent) {
|
||||
FREE(parent->custom);
|
||||
}
|
||||
|
||||
void glhud_screenToModel(const float x, const float y, const int screenW, const int screenH, float *centerX, float *centerY) {
|
||||
*centerX = (x/(screenW>>1))-1.f;
|
||||
*centerY = ((screenH-y)/(screenH>>1))-1.f;
|
||||
}
|
||||
|
||||
void glhud_quadModelToScreen(const GLModel *model, const int screenW, const int screenH, float screenCoords[4]) {
|
||||
float x0 = 1.0;
|
||||
float y0 = 1.0;
|
||||
float x1 = -1.0;
|
||||
float y1 = -1.0;
|
||||
|
||||
#warning NOTE: we possibly should use matrix calculations (but assuming HUD elements are identity/orthographic for now)
|
||||
GLfloat *positions = (GLfloat *)(model->positions);
|
||||
unsigned int stride = model->positionSize;
|
||||
unsigned int len = model->positionArraySize/getGLTypeSize(model->positionType);
|
||||
for (unsigned int i=0; i < len; i += stride) {
|
||||
float x = (positions[i] + 1.f) / 2.f;
|
||||
if (x < x0) {
|
||||
x0 = x;
|
||||
}
|
||||
if (x > x1) {
|
||||
x1 = x;
|
||||
}
|
||||
float y = (positions[i+1] + 1.f) / 2.f;
|
||||
LOG("\tmodel x:%f, y:%f", x, y);
|
||||
if (y < y0) {
|
||||
y0 = y;
|
||||
}
|
||||
if (y > y1) {
|
||||
y1 = y;
|
||||
}
|
||||
}
|
||||
|
||||
// OpenGL screen origin is bottom-left (Android is top-left)
|
||||
float yFlip0 = screenH - (y1 * screenH);
|
||||
float yFlip1 = screenH - (y0 * screenH);
|
||||
|
||||
screenCoords[0] = x0 * screenW;
|
||||
screenCoords[1] = yFlip0;
|
||||
screenCoords[2] = x1 * screenW;
|
||||
screenCoords[3] = yFlip1;
|
||||
}
|
||||
|
||||
|
@ -40,4 +40,10 @@ void glhud_renderDefault(GLModel *parent);
|
||||
// default model destruction
|
||||
void glhud_destroyDefault(GLModel *parent);
|
||||
|
||||
// translate screen coordinates to model
|
||||
void glhud_screenToModel(const float x, const float y, const int screenW, const int screenH, float *centerX, float *centerY);
|
||||
|
||||
// orthographic translation of model coordinates to screen coordinates
|
||||
void glhud_quadModelToScreen(const GLModel *model, const int screenW, const int screenH, float screenCoords[4]);
|
||||
|
||||
#endif
|
||||
|
@ -55,7 +55,6 @@ enum {
|
||||
|
||||
static bool isAvailable = false; // Were there any OpenGL/memory errors on gltouchjoy initialization?
|
||||
static bool isEnabled = true; // Does player want touchjoy enabled?
|
||||
static bool isVisible = true; // Does player want touchjoy to have some form of visibility?
|
||||
static float minAlpha = 0.0; // Minimum alpha value of touchjoy components (at zero, will not draw)
|
||||
|
||||
// viewport touch
|
||||
@ -189,50 +188,6 @@ static void _setup_button_object(GLModel *parent) {
|
||||
glhud_setupDefault(parent);
|
||||
}
|
||||
|
||||
static inline void _screen_to_model(float x, float y, float *screenX, float *screenY) {
|
||||
*screenX = (x/(touchport.width>>1))-1.f;
|
||||
*screenY = ((touchport.height-y)/(touchport.height>>1))-1.f;
|
||||
}
|
||||
|
||||
static void _model_to_screen(float screenCoords[4], GLModel *model) {
|
||||
|
||||
float x0 = 1.0;
|
||||
float y0 = 1.0;
|
||||
float x1 = -1.0;
|
||||
float y1 = -1.0;
|
||||
|
||||
#warning NOTE: we possibly should use matrix calculations (but assuming HUD elements are identity/orthographic for now)
|
||||
GLfloat *positions = (GLfloat *)(model->positions);
|
||||
unsigned int stride = model->positionSize;
|
||||
unsigned int len = model->positionArraySize/getGLTypeSize(model->positionType);
|
||||
for (unsigned int i=0; i < len; i += stride) {
|
||||
float x = (positions[i] + 1.f) / 2.f;
|
||||
if (x < x0) {
|
||||
x0 = x;
|
||||
}
|
||||
if (x > x1) {
|
||||
x1 = x;
|
||||
}
|
||||
float y = (positions[i+1] + 1.f) / 2.f;
|
||||
LOG("\tmodel x:%f, y:%f", x, y);
|
||||
if (y < y0) {
|
||||
y0 = y;
|
||||
}
|
||||
if (y > y1) {
|
||||
y1 = y;
|
||||
}
|
||||
}
|
||||
|
||||
// OpenGL screen origin is bottom-left (Android is top-left)
|
||||
float yFlip0 = touchport.height - (y1 * touchport.height);
|
||||
float yFlip1 = touchport.height - (y0 * touchport.height);
|
||||
|
||||
screenCoords[0] = x0 * touchport.width;
|
||||
screenCoords[1] = yFlip0;
|
||||
screenCoords[2] = x1 * touchport.width;
|
||||
screenCoords[3] = yFlip1;
|
||||
}
|
||||
|
||||
static void gltouchjoy_setup(void) {
|
||||
LOG("gltouchjoy_setup ...");
|
||||
|
||||
@ -286,9 +241,6 @@ static void gltouchjoy_render(void) {
|
||||
if (!isEnabled) {
|
||||
return;
|
||||
}
|
||||
if (!isVisible) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct timespec now = { 0 };
|
||||
struct timespec deltat = { 0 };
|
||||
@ -310,7 +262,7 @@ static void gltouchjoy_render(void) {
|
||||
}
|
||||
|
||||
if (alpha > 0.0) {
|
||||
glViewport(0, 0, touchport.width, touchport.height); // NOTE : show these HUD elements beyond the framebuffer dimensions
|
||||
glViewport(0, 0, touchport.width, touchport.height); // NOTE : show these HUD elements beyond the A2 framebuffer dimensions
|
||||
glUniform1f(alphaValue, alpha);
|
||||
|
||||
glActiveTexture(TEXTURE_ACTIVE_TOUCHJOY_AXIS);
|
||||
@ -401,7 +353,7 @@ static inline void _reset_model_position(GLModel *model, float touchX, float tou
|
||||
|
||||
float centerX = 0.f;
|
||||
float centerY = 0.f;
|
||||
_screen_to_model(touchX, touchY, ¢erX, ¢erY);
|
||||
glhud_screenToModel(touchX, touchY, touchport.width, touchport.height, ¢erX, ¢erY);
|
||||
|
||||
/* 2...3
|
||||
* .
|
||||
|
Loading…
x
Reference in New Issue
Block a user