⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datacurvedani.h.svn-base

📁 坦克大战游戏完整全套源代码
💻 SVN-BASE
字号:
#ifndef GAME_DATA_CURVEDANI_H
#define GAME_DATA_CURVEDANI_H

#include "hgeCurvedAni.h"
#include "caPoint2d.h"
#include "common/utils.h"

using cAni::Point2f;

enum dataCurvedAniStateId
{
    dataSI_Position0, // vector2
    dataSI_Position1, // vector2
    dataSI_Position2, // vector2
    dataSI_Alpha,    // float
    dataSI_Color,    // vector3
};

/// 实现下列接口
/// 参数
class dataClipState : public iClipState
{
public:
    dataClipState() : alpha(1), color(1, 1, 1)
    {
        position[0] = hgeVector(0, 0);
        position[1] = hgeVector(0, 0);
        position[2] = hgeVector(0, 0);
    }
    virtual void reset(const iClipState *defaultClipState = 0)
    {
        if (defaultClipState)
        {
            defaultClipState->getState(dataSI_Position0, position);
            defaultClipState->getState(dataSI_Position1, position + 1);
            defaultClipState->getState(dataSI_Position2, position + 2);
            defaultClipState->getState(dataSI_Alpha,    &alpha);
            defaultClipState->getState(dataSI_Color,    &color);
        }
        else
        {
            position[0] = hgeVector(0, 0);
            position[1] = hgeVector(0, 0);
            position[2] = hgeVector(0, 0);
            alpha = 1;
            color = Point3f(1, 1, 1);
        }
    }
    virtual StateId StringToStateId(const char *name)
    {
        return name, 0;
    }
    virtual void *getStateAddr(StateId sid)
    {
        return const_cast<void *>(getState(sid));
    }
    virtual void setState(StateId sid, const void *value)
    {
        switch(sid)
        {
        case dataSI_Position0: // vector2
            position[0] = *(hgeVector*)value;
            break;
        case dataSI_Position1: // vector2
            position[1] = *(hgeVector*)value;
            break;
        case dataSI_Position2: // vector2
            position[2] = *(hgeVector*)value;
            break;
        case dataSI_Alpha:    // float
            alpha = *(float*)value;
            break;
        case dataSI_Color:    // vector3
            color = *(Point3f*)value;
            break;
        default:
            assert(0);
            break;
        }
    }
    virtual const void *getState(StateId sid) const
    {
        switch(sid)
        {
        case dataSI_Position0: // vector2
            return position;
        case dataSI_Position1: // vector2
            return position + 1;
        case dataSI_Position2: // vector2
            return position + 2;
        case dataSI_Alpha:    // float
            return &alpha;
        case dataSI_Color:    // vector3
            return &color;
        default:
            assert(0);
            break;
        }
        return 0;
    }
    virtual void getState(StateId sid, void *value) const
    {
        switch(sid)
        {
        case dataSI_Position0: // vector2
            *(hgeVector*)value = position[0];
            break;
        case dataSI_Position1: // vector2
            *(hgeVector*)value = position[1];
            break;
        case dataSI_Position2: // vector2
            *(hgeVector*)value = position[2];
            break;
        case dataSI_Alpha:    // float
            *(float*)value = alpha;
            break;
        case dataSI_Color:    // vector3
            *(Point3f*)value = color;
            break;
        default:
            assert(0);
            break;
        }
    }

    hgeVector position[3];
    float alpha;
    Point3f color;
};

class DataTriangleRenderer : public iRenderer
{
public:
    /// @fn getName
    /// @brief get renderer's unique name
    const char *getName() const
    {
        return "DataTriangle";
    };
    /// @fn getStateId
    /// @brief return id from name
    StateId getStateId(const char *stateName) const;
    /// @fn getStateName
    /// @brief return name from id
    const char *getStateName(StateId stateId) const;
    virtual void render(const iClipState &cs)
    {
        hgeTriple t;
        for (int i = 0; i < 3; i++)
        {
            const hgeVector *p = (const hgeVector *)cs.getState(dataSI_Position0 + i);
            t.v[i].x = p->x;
            t.v[i].y = p->y;
            t.v[i].z = 0;
            float alpha;
            cs.getState(dataSI_Alpha, &alpha);
            Point3f color;
            cs.getState(dataSI_Color, &color);

            int a = clamp(int(alpha * 255), 0, 255);
            int r = clamp(int(color.x * 255), 0, 255);
            int g = clamp(int(color.y * 255), 0, 255);
            int b = clamp(int(color.z * 255), 0, 255);

            t.v[i].col = ARGB(a, r, g, b);
            t.v[i].tx = t.v[i].ty = 0;
        }
        t.tex = 0;
        t.blend = BLEND_DEFAULT;
        tripleList.push_back(t);
    }
    virtual iClipState *getClipState()
    {
        return &cs;
    }
    void render(const Point2f &pos);
protected:
    vector<hgeTriple> tripleList;
    dataClipState cs;
};

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -