小编Snu*_*kus的帖子

旋转矩形上的点

我正试图计算一个矩形的左下角,因为它在周围旋转.我试图谷歌它,但显然我错过了一些东西.我正在尝试使用变换矩阵来计算点.

对于我的设置,我有一个名为"test"的矩形剪辑和一个名为"pnt"的剪辑,我试图保持在左下角.这是我演示的代码.我刚把它扔到时间轴的第一帧进行测试:

//declare initial position of points
pnt.x = (test.x - test.width/2);
pnt.y = (test.y + test.height/2);

//distance between corner and center
var dx:Number = pnt.x - test.x;
var dy:Number = pnt.y - test.y;

addEventListener(Event.ENTER_FRAME,rotate);


//x' = xc + dx cos(theta) - dy sin(theta)
//y' = yc + dx sin(theta) + dy cos(theta)
function rotate(e:Event):void{
    test.rotation++;

    // use the transformation matrix to calculate the new x and y of the corner
    pnt.x = test.x + dx*Math.cos(test.rotation*(Math.PI/180)) - dy*Math.sin(test.rotation*(Math.PI/180));
    pnt.y = …
Run Code Online (Sandbox Code Playgroud)

algorithm flash geometry actionscript-3

2
推荐指数
1
解决办法
1768
查看次数

在C++中继承问题

我在获取std list类以调用类上的正确函数时遇到了麻烦.它一直只调用基类的函数.这是发生了什么:

我有一个具有以下更新功能的状态类,在头中声明为虚拟:

State.h更新功能:

virtual void update(float elapsed);
Run Code Online (Sandbox Code Playgroud)

State.cpp更新功能:

void State::update(float elapsed){

};
Run Code Online (Sandbox Code Playgroud)

以及从它继承的一个名为TestState的类:

class TestState::public State{
        virtual void update(float elapsed){
             if (GLOBALENGINE->getInput() -> getKeyPress(DIK_Q)
                PostQuitMessage(0);
        };

};
Run Code Online (Sandbox Code Playgroud)

我调用addState函数将新状态添加到链表并使其成为当前状态,如下所示:

GLOBALENGINE->addState(new TestState,true);
Run Code Online (Sandbox Code Playgroud)

addState函数如下所示:

void GameEngine::addState(State *state, bool change){
    states->push_back(*state); //add the test state into the states list

    // some irrelevant code

    currentState = &(states->back());//currentState is a pointer to a State
    // So we make it point to the newly added state.


}
Run Code Online (Sandbox Code Playgroud)

然后每帧调用run()函数,其内部是以下代码:

currentState->update(elapsed)// This should call the update function in …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance

0
推荐指数
1
解决办法
75
查看次数

标签 统计

actionscript-3 ×1

algorithm ×1

c++ ×1

flash ×1

geometry ×1

inheritance ×1