VALUE rbal_transform_coordinates(VALUE r_, VALUE rtrans, VALUE rx, VALUE ry) { ALLEGRO_TRANSFORM * trans = rbal_transform_unwrap(rtrans); float x = RBH_FLOAT(rx); float y = RBH_FLOAT(ry); al_transform_coordinates(trans, &x, &y); return rb_ary_new3(2, RBH_INT_NUM(x), RBH_INT_NUM(y)); }
void _al_draw_pixel_memory(ALLEGRO_BITMAP *bitmap, float x, float y, ALLEGRO_COLOR *color) { ALLEGRO_COLOR result; int ix, iy; /* * Probably not worth it to check for identity */ al_transform_coordinates(al_get_current_transform(), &x, &y); ix = (int)x; iy = (int)y; _al_blend_memory(color, bitmap, ix, iy, &result); _al_put_pixel(bitmap, ix, iy, result); }
void Renderer::drawHud() { if(!setShader(SHADER_ALLEGRO)) NBT_Debug("failed to set allegro shader"); //al_use_shader(nullptr); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //int dw = al_get_display_width(dpy_); //int dh = al_get_display_height(dpy_); /*ALLEGRO_TRANSFORM trans; al_identity_transform(&trans); al_orthographic_transform(&trans, 0, 0, -1, dw, dh, 1); al_set_projection_transform(dpy_, &trans); al_identity_transform(&trans); al_use_transform(&trans); */ if(!resManager_->getAtlas()->getSheet(0)->alBitmap()) NBT_Debug("no sheet bitmap????"); //al_use_shader(nullptr);section_y ALLEGRO_BITMAP *tex = resManager_->getAtlas()->getSheet(0)->alBitmap(); //glActiveTexture(GL_TEXTURE0); //glBindTexture(GL_TEXTURE_2D, al_get_opengl_texture(tex)); //al_set_shader_sampler("al_tex", tex, 0); al_draw_bitmap(tex, 0, 0, 0); float x = 0.0, y = 0.0; al_transform_coordinates(&camera_transform_, &x, &y); Vector3D world_pos; al_draw_textf(fnt_, al_map_rgb(0,0,0), 4, al_get_display_height(dpy_)-12, 0, "Pos: x:%.0f, y:%.0f, z:%.0f", camera_pos_.x, camera_pos_.y, camera_pos_.z); // al_draw_textf(fnt_, al_map_rgb(0,0,0), 4, al_get_display_height(dpy_)-24, 0, "WP: %.0f %.0f %.0f", world_pos.x, world_pos.y, world_pos.z); //al_draw_textf(fnt_, al_map_rgb(0,0,0), 4, al_get_display_height(dpy_)-24, 0, "Mat: x0:%.0f x1:%.0f x2:%.0f x3:%.0f z0:%.0f z1:%.0f z2:%.0f z3:%.0f", // world.m[0][0], world.m[1][0], world.m[2][0], world.m[3][0], // world.m[2][2], world.m[2][2], world.m[2][2], world.m[3][2]); //al_draw_textf(fnt_, al_map_rgb(0,0,0), 4, al_get_display_height(dpy_)-12, 0, "Pos: x:%.0f y:%.0f z:%.0f", camera_pos_.getX(), camera_pos_.getY(), camera_pos_.getZ()); }
void AllegroInput5::Update( int dt ) { if ( m_doubleClickTimer > 0 ) m_doubleClickTimer -= dt; if ( m_repeatTimer > 0 ) m_repeatTimer -= dt; // Get current transformation, to tranform reported scaled/shifted mouse coordinates into something the game can use const ALLEGRO_TRANSFORM *pTransform = al_get_current_inverse_transform(); const JoystickMapping & mapping = GetJoystickMapping(0); ALLEGRO_EVENT ev; while( al_get_next_event( m_queue, &ev ) ) { if ( m_hasKeyboard ) { if ( ev.any.type == ALLEGRO_EVENT_KEY_DOWN ) AddEvent( InputEvent::KeyboardEvent( KeyboardEvent::KBD_KEY_DOWN, ev.keyboard.keycode, ev.keyboard.unichar, ev.keyboard.modifiers ) ); else if ( ev.any.type == ALLEGRO_EVENT_KEY_UP ) AddEvent( InputEvent::KeyboardEvent( KeyboardEvent::KBD_KEY_UP, ev.keyboard.keycode, ev.keyboard.unichar, ev.keyboard.modifiers ) ); else if ( ev.any.type == ALLEGRO_EVENT_KEY_CHAR && m_repeatTimer <= 0 ) { // Please note that some event params (like modifiers) are ONLY accessible in KEY_CHAR event! AddEvent( InputEvent::KeyboardEvent( KeyboardEvent::KBD_KEY_REPEAT, ev.keyboard.keycode, ev.keyboard.unichar, ev.keyboard.modifiers ) ); m_repeatTimer = 100; } } if ( m_hasMouse ) { float exf = ev.mouse.x; float eyf = ev.mouse.y; float edxf = ev.mouse.dx; float edyf = ev.mouse.dy; al_transform_coordinates( pTransform, &exf, &eyf ); al_transform_coordinates( pTransform, &edxf, &edyf ); int ex = (int)floorf( exf ); int ey = (int)floorf( eyf ); int edx = (int)floorf( edxf ); int edy = (int)floorf( edyf ); if ( ev.any.type == ALLEGRO_EVENT_MOUSE_AXES ) { if ( edx != 0 || edy != 0 ) AddEvent( InputEvent::MouseEvent( MouseEvent::MOUSE_MOVE, ex, ey, ev.mouse.dw ) ); if ( ev.mouse.dw != 0 ) AddEvent( InputEvent::MouseEvent( MouseEvent::MOUSE_WHEEL, ex, ey, ev.mouse.dw ) ); } else if ( ev.any.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN ) { MouseEvent::EType type = MouseEvent::MOUSE_B1_DOWN; if ( ev.mouse.button == 1 ) { if ( m_doubleClickTimer > 0 ) { m_doubleClickTimer = 0; type = MouseEvent::MOUSE_B1_DOUBLECLICK; } else type = MouseEvent::MOUSE_B1_DOWN; } else if ( ev.mouse.button == 2 ) type = MouseEvent::MOUSE_B2_DOWN; else if ( ev.mouse.button == 3 ) type = MouseEvent::MOUSE_B3_DOWN; AddEvent( InputEvent::MouseEvent( type, ex, ey, 0 ) ); } else if ( ev.any.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP ) { MouseEvent::EType type = MouseEvent::MOUSE_B1_UP; if ( ev.mouse.button == 1 ) { m_doubleClickTimer = 250; type = MouseEvent::MOUSE_B1_UP; } else if ( ev.mouse.button == 2 ) type = MouseEvent::MOUSE_B2_UP; else if ( ev.mouse.button == 3 ) type = MouseEvent::MOUSE_B3_UP; AddEvent( InputEvent::MouseEvent( type, ex, ey, 0 ) ); } } if ( m_hasGamepad ) { if ( ev.any.type == ALLEGRO_EVENT_JOYSTICK_AXIS ) { const int stick = ev.joystick.stick; const int axis = ev.joystick.axis; if ( stick >= (int)m_gamepadSticks.size() ) m_gamepadSticks.resize( stick + 1 ); GamepadStick & s = m_gamepadSticks[ stick ]; if ( axis >= (int)s.m_axis.size() ) s.m_axis.resize( axis + 1 ); GamepadAxis & a = s.m_axis[ axis ]; // Some axes on some systems has their neutral position at -1 instead of 0, so we have to adjust for it const float adjPos = ev.joystick.pos - mapping.GetAxisBase( ev.joystick.stick, ev.joystick.axis ); const bool nearZero = fabs(adjPos) < 0.01f; // We only want to send GP_AXIS event once for each direction change, like it was a digital axis or a keyboard key if ( nearZero ) { // If the stick is back to its neutral position, and wasn't there before, send an event about it if ( !a.m_unlocked ) AddEvent( InputEvent::GamepadEvent( GamepadEvent::GP_AXIS, ev.joystick.stick, ev.joystick.axis, 0 ) ); a.m_unlocked = true; } else { // If the stick is outside its neutral position, and this wasn't reported before, send an event about it if ( a.m_unlocked ) AddEvent( InputEvent::GamepadEvent( GamepadEvent::GP_AXIS, ev.joystick.stick, ev.joystick.axis, adjPos ) ); a.m_unlocked = false; } } else if ( ev.any.type == ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN ) { AddEvent( InputEvent::GamepadEvent( GamepadEvent::GP_BUTTON_DOWN, ev.joystick.button ) ); } else if ( ev.any.type == ALLEGRO_EVENT_JOYSTICK_BUTTON_UP ) { AddEvent( InputEvent::GamepadEvent( GamepadEvent::GP_BUTTON_UP, ev.joystick.button ) ); } } if ( m_hasTouch ) { float exf = ev.touch.x; float eyf = ev.touch.y; float edxf = ev.touch.dx; float edyf = ev.touch.dy; al_transform_coordinates( pTransform, &exf, &eyf ); edxf *= pTransform->m[0][0]; edyf *= pTransform->m[0][0]; int ex = (int)floorf( exf ); int ey = (int)floorf( eyf ); int edx = (int)floorf( edxf ); int edy = (int)floorf( edyf ); if ( ev.any.type == ALLEGRO_EVENT_TOUCH_BEGIN ) AddEvent( InputEvent::TouchEvent( TouchEvent::TOUCH_BEGIN, ev.touch.id, ev.touch.primary, ev.touch.timestamp, ex, ey, edx, edy ) ); else if ( ev.any.type == ALLEGRO_EVENT_TOUCH_MOVE ) AddEvent( InputEvent::TouchEvent( TouchEvent::TOUCH_MOVE, ev.touch.id, ev.touch.primary, ev.touch.timestamp, ex, ey, edx, edy ) ); else if ( ev.any.type == ALLEGRO_EVENT_TOUCH_END ) AddEvent( InputEvent::TouchEvent( TouchEvent::TOUCH_END, ev.touch.id, ev.touch.primary, ev.touch.timestamp, ex, ey, edx, edy ) ); else if ( ev.any.type == ALLEGRO_EVENT_TOUCH_CANCEL ) AddEvent( InputEvent::TouchEvent( TouchEvent::TOUCH_CANCEL, ev.touch.id, ev.touch.primary, ev.touch.timestamp, ex, ey, edx, edy ) ); //GetLog().Log( CommonLog(), LL_CRITICAL, "AllegroInput: event=%i id=%i x=%f y=%f", ev.any.type, ev.touch.id, ev.touch.x, ev.touch.y ); } } if ( m_hasKeyboard ) { // Since Allegro events don't have KEY_PRESSED, we do it other way. ALLEGRO_KEYBOARD_STATE state; al_get_keyboard_state( &state ); for ( int i = 0; i < ALLEGRO_KEY_MAX; ++i ) { // We don't know key code for state :( if ( al_key_down( &state, i ) && m_keyStates[ i ] ) AddEvent( InputEvent::KeyboardEvent( KeyboardEvent::KBD_KEY_PRESSED, i, 0, 0 ) ); m_keyStates[ i ] = al_key_down( &state, i ) != 0; } } }
static INLINE void transform_vertex(float* x, float* y) { al_transform_coordinates(al_get_current_transform(), x, y); }
static void _al_draw_transformed_bitmap_memory(ALLEGRO_BITMAP *src, ALLEGRO_COLOR tint, int sx, int sy, int sw, int sh, int dw, int dh, ALLEGRO_TRANSFORM* local_trans, int flags) { float xsf[4], ysf[4]; int tl = 0, tr = 1, bl = 3, br = 2; int tmp; ALLEGRO_VERTEX v[4]; ASSERT(_al_pixel_format_is_real(src->format)); /* Decide what order to take corners in. */ if (flags & ALLEGRO_FLIP_VERTICAL) { tl = 3; tr = 2; bl = 0; br = 1; } else { tl = 0; tr = 1; bl = 3; br = 2; } if (flags & ALLEGRO_FLIP_HORIZONTAL) { tmp = tl; tl = tr; tr = tmp; tmp = bl; bl = br; br = tmp; } xsf[0] = 0; ysf[0] = 0; xsf[1] = dw; ysf[1] = 0; xsf[2] = 0; ysf[2] = dh; al_transform_coordinates(local_trans, &xsf[0], &ysf[0]); al_transform_coordinates(local_trans, &xsf[1], &ysf[1]); al_transform_coordinates(local_trans, &xsf[2], &ysf[2]); v[tl].x = xsf[0]; v[tl].y = ysf[0]; v[tl].z = 0; v[tl].u = sx; v[tl].v = sy; v[tl].color = tint; v[tr].x = xsf[1]; v[tr].y = ysf[1]; v[tr].z = 0; v[tr].u = sx + sw; v[tr].v = sy; v[tr].color = tint; v[br].x = xsf[2] + xsf[1] - xsf[0]; v[br].y = ysf[2] + ysf[1] - ysf[0]; v[br].z = 0; v[br].u = sx + sw; v[br].v = sy + sh; v[br].color = tint; v[bl].x = xsf[2]; v[bl].y = ysf[2]; v[bl].z = 0; v[bl].u = sx; v[bl].v = sy + sh; v[bl].color = tint; al_lock_bitmap(src, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY); _al_triangle_2d(src, &v[tl], &v[tr], &v[br]); _al_triangle_2d(src, &v[tl], &v[br], &v[bl]); al_unlock_bitmap(src); }