cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

regions.h (2200B)


      1/*
      2 * Gearboy - Nintendo Game Boy Emulator
      3 * Copyright (C) 2012  Ignacio Sanchez
      4 
      5 * This program is free software: you can redistribute it and/or modify
      6 * it under the terms of the GNU General Public License as published by
      7 * the Free Software Foundation, either version 3 of the License, or
      8 * any later version.
      9 
     10 * This program is distributed in the hope that it will be useful,
     11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     13 * GNU General Public License for more details.
     14 
     15 * You should have received a copy of the GNU General Public License
     16 * along with this program.  If not, see http://www.gnu.org/licenses/
     17 *
     18 */
     19
     20#ifndef _REGIONS_H
     21#define	_REGIONS_H
     22#pragma once
     23
     24#include "Vector.h"
     25
     26class Region
     27{
     28public:
     29    virtual ~Region() { };
     30    virtual bool PointInRegion(float px, float py) = 0;
     31    virtual Vec3 GetPosition(void) = 0;
     32};
     33
     34class RectRegion : public Region
     35{
     36private:
     37    float m_fRectPosX;
     38    float m_fRectPosY;
     39    float m_fRectWidth;
     40    float m_fRectHeight;
     41
     42public:
     43    RectRegion(float rx, float ry, float width, float height)
     44    {
     45        m_fRectPosX = rx;
     46        m_fRectPosY = ry;
     47        m_fRectWidth = width;
     48        m_fRectHeight = height;
     49    };
     50
     51    virtual ~RectRegion() { };
     52
     53    bool PointInRegion(float px, float py)
     54    {
     55        return(px >= m_fRectPosX) && (px <= (m_fRectPosX + m_fRectWidth)) && (py >= m_fRectPosY) && (py <= (m_fRectPosY + m_fRectHeight));
     56    };
     57
     58    Vec3 GetPosition(void)
     59    {
     60        return Vec3(m_fRectPosX, m_fRectPosY, 0.0f);
     61    }
     62};
     63
     64class CircleRegion : public Region
     65{
     66private:
     67    Vec2 m_CirclePos;
     68    float m_fCircleRadius;
     69
     70public:
     71    CircleRegion(float rx, float ry, float radius)
     72    {
     73        m_CirclePos.x = rx;
     74        m_CirclePos.y = ry;
     75        m_fCircleRadius = radius;
     76    };
     77
     78    virtual ~CircleRegion() { };
     79
     80    bool PointInRegion(float px, float py)
     81    {
     82        Vec2 point = Vec2(px, py);
     83        Vec2 res = point - m_CirclePos;
     84
     85        return(res.length() <= m_fCircleRadius);
     86    };
     87
     88    Vec3 GetPosition(void)
     89    {
     90        return Vec3(m_CirclePos.x, m_CirclePos.y, 0.0f);
     91    }
     92};
     93
     94#endif	/* _REGIONS_H */
     95