Esempio n. 1
0
cxBool cxEngineFireTouch(cxTouchType type,cxVec2f pos)
{
    cxEngine this = cxEngineInstance();
    if(!this->isTouch){
        return false;
    }
    cxDouble time = cxTimestamp();
    cxVec2f cpos = cxEngineTouchToWindow(pos);
    if(type == cxTouchTypeDown){
        this->touch.movement = cxVec2fv(0, 0);
        this->touch.delta = cxVec2fv(0, 0);
        this->touch.previous = cpos;
        this->touch.dtime = time;
        this->touch.start = cpos;
    }else if(type == cxTouchTypeMove){
        this->touch.delta = cxVec2fv(cpos.x - this->touch.previous.x, cpos.y - this->touch.previous.y);
        this->touch.previous = cpos;
        this->touch.movement.x += this->touch.delta.x;
        this->touch.movement.y += this->touch.delta.y;
    }else{
        this->touch.utime = time;
    }
    this->touch.current = cpos;
    this->touch.type = type;
    cxBool ret = false;
    CX_SIGNAL_FIRE(this->onTouch, CX_FUNC_TYPE(cxAny, cxTouch *, cxBool *),CX_SLOT_OBJECT, &this->touch, &ret);
    return (ret || cxViewTouch(this->window, &this->touch));
}
Esempio n. 2
0
cxRect4f cxViewGLRect(cxAny pview)
{
    cxView this = pview;
    cxFloat wh = this->size.w/2.0f;
    cxFloat hh = this->size.h/2.0f;
    cxVec2f p1 = cxVec2fv(-wh, -hh);
    cxVec2f p2 = cxVec2fv(wh, hh);
    p1 = cxViewPointToGLPoint(pview, p1);
    p2 = cxViewPointToGLPoint(pview, p2);
    return cxRect4fv(p1.x, p1.y, p2.x - p1.x, p2.y - p1.y);
}
Esempio n. 3
0
static cxInt cxFixScaleH(lua_State *L)
{
    cxEngine engine = cxEngineInstance();
    cxNumber num = cxNumberVec2f(cxVec2fv(engine->scale.y, engine->scale.y));
    CX_LUA_PUSH_OBJECT(num);
    return 1;
}
Esempio n. 4
0
cxVec2f cxWindowPointToGLPoint(cxVec2f wPoint)
{
    cxEngine engine = cxEngineInstance();
    cxFloat x = wPoint.x + engine->winsize.w/2.0f;
    cxFloat y = wPoint.y + engine->winsize.h/2.0f;
    return cxVec2fv(x, y);
}
Esempio n. 5
0
cxVec2f cxGLPointToWindowPoint(cxVec2f glPoint)
{
    cxEngine engine = cxEngineInstance();
    cxFloat x = glPoint.x - engine->winsize.w/2.0f;
    cxFloat y = glPoint.y - engine->winsize.h/2.0f;
    return cxVec2fv(x, y);
}
Esempio n. 6
0
static cxInt cxNumberLuaNewVec2f(lua_State *L)
{
    cxFloat x = luaL_checknumber(L, 1);
    cxFloat y = luaL_checknumber(L, 2);
    cxNumber this = cxNumberVec2f(cxVec2fv(x, y));
    lua_pushlightuserdata(L, this);
    CX_LUA_RET_THIS(cxNumber);
}
Esempio n. 7
0
CX_SETTER_DEF(cxSpline, points)
{
    cxJson points = cxJsonToArray(value);
    CX_JSON_ARRAY_EACH_BEG(points, item)
    {
        cxVec2f point = cxJsonToVec2f(item, cxVec2fv(0, 0));
        cxSplineAppend(this, point);
    }
Esempio n. 8
0
cxVec2f cxTileIdxToPos(cxVec2f idx,cxSize2f size)
{
    cxFloat w2 = size.w / 2;
    cxFloat h2 = size.h / 2;
    cxFloat aa = atan2f(h2, w2);
    cxFloat sa = sinf(aa);
    cxFloat ca = cosf(aa);
    cxFloat m = sqrtf(w2*w2 + h2*h2);
    
    cxFloat dx = m * idx.x;
    cxFloat dy = m * idx.y;
    cxVec2f p1 = cxVec2fv(0, 0);
    p1.x = ca * dx;
    p1.y = sa * dx;
    cxVec2f p2 = cxVec2fv(0, 0);
    p2.x = ca * dy;
    p2.y = sa * dy;
    return cxVec2fv(p1.x - p2.x,p1.y + p2.y);
}
Esempio n. 9
0
CX_OBJECT_INIT(cxView, cxObject)
{
    this->super.cxBase = cxBaseTypeView;
    this->hideTop = true;
    this->isBorder = false;
    this->isVisible = true;
    this->isDirty = true;
    this->color = cxColor4fv(1.0f, 1.0f, 1.0f, 1.0f);
    this->size = cxSize2fv(0.0f, 0.0f);
    this->anchor = cxVec2fv(0.5f, 0.5f);
    this->raxis = cxVec3fv(0.0f, 0.0f, 1.0f);
    this->scale = cxVec2fv(1.0f, 1.0f);
    this->fixscale = cxVec2fv(1.0f, 1.0f);
    this->subViews = CX_ALLOC(cxList);
    CX_METHOD_OVERRIDE(this->IsTouch, cxViewIsTouch);
    CX_METHOD_OVERRIDE(this->IsOnKey, cxViewIsOnKey);
    cxObjectSetReadAttrFunc(this, cxViewReadAttr);
    
    this->actions = CX_ALLOC(cxHash);
    this->caches = CX_ALLOC(cxHash);
    this->removes = CX_ALLOC(cxArray);
}
Esempio n. 10
0
static void cxChipmunkGetAttr(cxReaderAttrInfo *info,cxChipmunkAttr *attr)
{
    cxChipmunkAttrInit(attr);
    attr->shape = cxXMLReadIntAttr(info, "cxChipmunk.shape", cxChipmunkShapeBox);
    attr->cp = cxXMLReadVec2fAttr(info, "cxChipmunk.center", cxVec2fv(0, 0));
    attr->isStatic = cxXMLReadBoolAttr(info, "cxChipmunk.static", attr->isStatic);
    attr->m = cxXMLReadFloatAttr(info, "cxChipmunk.m", attr->m);
    attr->e = cxXMLReadFloatAttr(info, "cxChipmunk.e", attr->e);
    attr->u = cxXMLReadFloatAttr(info, "cxChipmunk.u", attr->u);
    attr->group = cxXMLReadUIntAttr(info, "cxChipmunk.group", CP_NO_GROUP);
    attr->layer = cxXMLReadUIntAttr(info, "cxChipmunk.layer", CP_ALL_LAYERS);
    attr->ctype = cxXMLReadUIntAttr(info, "cxChipmunk.ctype", 0);
}
Esempio n. 11
0
cxVec2f cxTilePosToIdx(cxVec2f pos,cxSize2f size)
{
    cxFloat w2 = size.w / 2;
    cxFloat h2 = size.h / 2;
    cxFloat aa = atan2f(h2, w2);
    cxFloat sa = sinf(aa);
    cxFloat ca = cosf(aa);
    cxFloat m = sqrtf(w2*w2 + h2*h2);
    //
    cxFloat dx = (pos.y / sa + pos.x / ca) / 2.0f;
    cxFloat dy = dx - pos.x / ca;
    return cxVec2fv(dx/m, dy/m);
}
Esempio n. 12
0
static void cxChipmunkAttrInit(cxChipmunkAttr *attr)
{
    memset(attr, 0, sizeof(cxChipmunkAttr));
    attr->cp = cxVec2fv(0, 0);
    attr->ctype = 0;
    attr->e = 0.0f;;
    attr->group = CP_NO_GROUP;
    attr->isStatic = false;
    attr->layer = CP_ALL_LAYERS;
    attr->m = 1.0f;;
    attr->shape = cxChipmunkShapeBox;
    attr->u = 0.0f;
}
Esempio n. 13
0
cxVec2f cxViewPointToWindowPoint(cxAny pview,cxVec2f vPoint)
{
    cxView this = pview;
    cxView pv = this;
    cxVec3f out;
    kmVec3Fill(&out, vPoint.x, vPoint.y, 0);
    while (pv != NULL && pv->parentView != NULL) {
        kmVec3Transform(&out, &out, &pv->anchorMatrix);
        kmVec3Transform(&out, &out, &pv->normalMatrix);
        pv = pv->parentView;
    }
    return cxVec2fv(out.x, out.y);
}
Esempio n. 14
0
void cxEngineLayout(cxInt width,cxInt height)
{
    CX_LOGGER("openGL layout width=%d height=%d",width,height);
    cxEngine engine = cxEngineInstance();
    engine->winsize = cxSize2fv(width, height);
    cxViewSetSize(engine->window, engine->winsize);
    if(!cxSize2Zero(engine->dessize)){
        engine->scale = cxVec2fv(engine->winsize.w/engine->dessize.w, engine->winsize.h/engine->dessize.h);
    }
    //
    if(!engine->isInit){
        cxOpenGLCheckFeature();
        cxEngineMain(engine);
    }
    //
    cxFloat zeye = engine->winsize.h / 1.1566f;
    kmMat4 perspective={0};
    kmGLMatrixMode(KM_GL_PROJECTION);
    kmGLLoadIdentity();
    //
    kmMat4PerspectiveProjection(&perspective, 60.0f, engine->winsize.w / engine->winsize.h, 0.0f, zeye * 2);
    kmGLMultMatrix(&perspective);
    kmGLMatrixMode(KM_GL_MODELVIEW);
    kmGLLoadIdentity();
    //
    cxOpenGLViewport(cxBox4fv(0, engine->winsize.w, 0, engine->winsize.h));
    //
    cxMatrix4f matrix;
    cxEngineLookAt(&matrix,cxVec2fv(0, 0));
    kmGLMultMatrix(&matrix);
    //
    engine->lastTime = cxTimestamp();
    if(!engine->isInit){
        cxViewEnter(engine->window);
    }
    cxViewLayout(engine->window);
    engine->isInit = true;
}
Esempio n. 15
0
cxVec2f cxCardinalSplineAt(cxVec2f p0, cxVec2f p1, cxVec2f p2, cxVec2f p3, cxFloat tension, cxFloat t)
{
    cxFloat t2 = t * t;
    cxFloat t3 = t2 * t;
    cxFloat s = (1 - tension) / 2;
    cxFloat b1 = s * ((-t3 + (2 * t2)) - t);
    cxFloat b2 = s * (-t3 + t2) + (2 * t3 - 3 * t2 + 1);
    cxFloat b3 = s * (t3 - 2 * t2 + t) + (-2 * t3 + 3 * t2);
    cxFloat b4 = s * (t3 - t2);
    cxVec2f rv = cxVec2fv(0, 0);
    rv.x = (p0.x*b1 + p1.x*b2 + p2.x*b3 + p3.x*b4);
    rv.y = (p0.y*b1 + p1.y*b2 + p2.y*b3 + p3.y*b4);
	return rv;
}
Esempio n. 16
0
static void cxJumpStep(cxAny pav,cxFloat dt,cxFloat time)
{
    cxJump this = pav;
    cxFloat frac = fmodf( time * this->jumps, 1.0f );
    cxFloat y = this->height * 4 * frac * (1 - frac) + this->position.y * time;
    cxFloat x = this->position.x * time;
    cxVec2f diff;
    cxVec2f currPos = this->super.view->position;
    kmVec2Subtract(&diff, &currPos, &this->prevPos);
    kmVec2Add(&this->startPos, &diff, &this->startPos);
    cxVec2f nPos;
    kmVec2Add(&nPos, &this->startPos, &cxVec2fv(x, y));
    this->prevPos = nPos;
    cxViewSetPos(this->super.view, nPos);
}
Esempio n. 17
0
CX_METHOD_DEF(cxSpline,Init,void)
{
    CX_ASSERT_VALUE(cxActionGetView(this), cxView, view);
    cxInt num = cxAnyArrayLength(this->points);
    if(num < 2){
        cxActionStop(this);
        return;
    }
    this->delta = 1.0f/((cxFloat)num - 1.0f);
    this->diff = cxVec2fv(0, 0);
    this->prev =cxViewGetPosition(view);
    
    cxVec2f p0 = cxSplinePointAt(this, 0);
    cxVec2f p1 = cxSplinePointAt(this, num - 1);
    cxFloat angle = cxVec2fRadiansBetween(p1, p0);
    if(!cxFloatEqu(angle, this->angle)){
        this->angle = angle;
        CX_EVENT_FIRE(this, onAngle);
    }
    CX_SUPER(cxAction, this, Init, CX_M(void));
}
Esempio n. 18
0
CX_OBJECT_INIT(cxEngine, cxObject)
{
    cxAllocatorInit();
    cxAutoPoolInit();
    kmGLInitialize();
    xmlInitGlobals();
    this->frameInterval = 1.0f/60.0f;
    this->isShowBorder = true;
    this->isTouch = true;
    this->scale     = cxVec2fv(1.0f, 1.0f);
    this->window    = CX_ALLOC(cxWindow);
    this->scripts   = CX_ALLOC(cxHash);
    this->datasets  = CX_ALLOC(cxHash);
    this->actions   = CX_ALLOC(cxHash);
    this->dbenvs    = CX_ALLOC(cxHash);
    this->bmpfonts  = CX_ALLOC(cxHash);
    gL = lua_newstate(cxEngineLuaAllocFunc, this);
    CX_ASSERT(gL != NULL, "new lua state error");
    lua_atpanic(gL, cxEngineLuaPanic);
    luaL_openlibs(gL);
    cxEngineAddLuaLoader(gL);
}
Esempio n. 19
0
CX_SETTER_DEF(cxAtlas, layers)
{
    cxJson layers = cxJsonToArray(value);
    CX_JSON_ARRAY_EACH_BEG(layers, layer)
    {
        cxVec2f pos = cxVec2fv(0, 0);
        cxSize2f size = cxSize2fv(0, 0);
        cxBoxTex2f tex = cxBoxTex2fDefault();
        cxColor4f color = cxColor4fv(1, 1, 1, 1);
        pos = cxJsonVec2f(layer, "pos", pos);
        size = cxJsonSize2f(layer, "size", size);
        cxConstChars key = cxJsonConstChars(layer, "key");
        if(key != NULL){
            tex = cxTextureBox(this->cxSprite.texture, key);
        }else{
            tex = cxJsonBoxTex2f(layer, "coord", tex);
        }
        if(cxSize2Zero(size) && key != NULL){
            size = cxTextureSize(this->cxSprite.texture, key);
        }
        color = cxJsonColor4f(layer, "color", color);
        cxAtlasAppendBoxPoint(this, pos, size, tex, color);
    }
Esempio n. 20
0
cxVec2f cxRoundVec2f(cxVec2f v)
{
    return cxVec2fv(cxRound(v.x), cxRound(v.y));
}
Esempio n. 21
0
cxVec2f cxVec2fMidPoint(cxVec2f v1, cxVec2f v2)
{
    cxVec2f sum = cxVec2fAdd(v1, v2);
    return cxVec2fv(sum.x / 2.0f, sum.y / 2.0f);
}
Esempio n. 22
0
cxVec2f cxVec2fScale(cxVec2f pIn, cxFloat s)
{
    return cxVec2fv(pIn.x * s, pIn.y * s);
}
Esempio n. 23
0
 cxVec2f cxVec2fAdd(cxVec2f pV1, cxVec2f pV2)
{
    return cxVec2fv(pV1.x + pV2.x, pV1.y + pV2.y);
}
Esempio n. 24
0
 cxVec2f cxVec2fSub(cxVec2f pV1, cxVec2f pV2)
{
    return cxVec2fv(pV1.x - pV2.x, pV1.y - pV2.y);
}