Quad Pang
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Private Attributes
BongoOrthoMover Class Reference

Move bongo in 8 directions. More...

#include <Controllers.h>

Inheritance diagram for BongoOrthoMover:
Controller Controller

List of all members.

Public Member Functions

 BongoOrthoMover (Engine *parent, Bongo *pquad)
bool Init (XRes *resource, XCongo *xcongo)
 Call to perform initalization based on resource.
bool ProcessKey (int key, Engine::KeyEvent type, int x, int y)
 BongoOrthoMover (Engine *parent, Bongo *pquad)
bool Init (XRes *resource, XCongo *xcongo)
 Call to perform initalization based on resource.
bool ProcessKey (int key, Engine::KeyEvent type, int x, int y)
 Process key event.

Private Attributes

EnginempParent
BongompBongo
double mPower
int mnMoving
 How many directions are active.
Viewport coeficients

These coeficients are helping to determine quadrats of 3D space in which Viewer is placed relative to Bongo.

double m_k
double m_lz

We are two direction buffers since we have 2 options for each key LEFT-ON, LEFT-OFF, RIGTH-ON, RIGHT-OFF, etc

Direction buffers

We will use both to call SetDirection();

double mDirectionLU [3]
double mDirectionRD [3]

Detailed Description

Move bongo in 8 directions.

Definition at line 126 of file Controllers.h.


Constructor & Destructor Documentation

BongoOrthoMover::BongoOrthoMover ( Engine parent,
Bongo pquad 
)

Definition at line 114 of file Controllers.cpp.

References m_k, m_lz, Engine::mBoxDim, mDirectionLU, mDirectionRD, mnMoving, and mpParent.

: mpParent(parent), mpBongo(pquad), mPower(2.0)
{
    m_k = mpParent->mBoxDim[2] / mpParent->mBoxDim[0];
    m_lz = mpParent->mBoxDim[2];
    mnMoving = 0;
    memset(mDirectionLU, 0, sizeof(mDirectionLU) );
    memset(mDirectionRD, 0, sizeof(mDirectionRD) );
}
BongoOrthoMover::BongoOrthoMover ( Engine parent,
Bongo pquad 
)

Member Function Documentation

bool BongoOrthoMover::Init ( XRes resource,
XCongo xcongo 
) [virtual]

Call to perform initalization based on resource.

Reimplemented from Controller.

Definition at line 103 of file Controllers.cpp.

References XRes::DoubleValue(), and mPower.

{
    if (!resource->DoubleValue("mPower", &mPower) )
    {
        fprintf(stderr, "error: BongoOrthoMover power\n");
        return false;
    }
  
    return true;
}
bool BongoOrthoMover::Init ( XRes resource,
XCongo xcongo 
) [virtual]

Call to perform initalization based on resource.

Reimplemented from Controller.

bool BongoOrthoMover::ProcessKey ( int  key,
Engine::KeyEvent  type,
int  x,
int  y 
) [virtual]

Process key event.

Parameters:
keyKey which triggered action
typeKEY_UP or KEY_DOWN
xcursor position
ycursor position
Returns:
true if key is processed and should not be forwarded to other controlers

Implements Controller.

bool BongoOrthoMover::ProcessKey ( int  key,
Engine::KeyEvent  type,
int  px,
int  py 
) [virtual]

Moving is in some direction is started on Key Down. Mulitple keys can be pressed in the same time and all will be used in calculation. For example. UP + LEFT, UP, DOWN, RIGTH+DOWN, etc. When key is unpresseed only direction of that key will be set to 0 And other keys will remain in effect.

Implements Controller.

Definition at line 129 of file Controllers.cpp.

References Bongo::Fire(), Engine::GetViewer(), GLUT_SPEC_KEY_DOWN, GLUT_SPEC_KEY_LEFT, GLUT_SPEC_KEY_RIGHT, GLUT_SPEC_KEY_UP, Quad_impl::IsActive(), Engine::KEY_DOWN_EX, Engine::KEY_UP_EX, m_k, m_lz, Engine::mbAnimeEnabled, mDirectionLU, mDirectionRD, mnMoving, mpBongo, mPower, mpParent, Engine::mQuads, Quad_impl::SetDirection(), vec_add(), x, y, and z.

{
    double nula[] = { 0.0, 0.0, 0.0 };
    
    if (!mpParent->mbAnimeEnabled)
        return true;

    if (!mpBongo->IsActive() )
        return true;

  /*  if (mnMoving > 1)
    {
        memset(mDirectionRD, 0, sizeof(mDirectionRD) );
        memset(mDirectionLU, 0, sizeof(mDirectionLU) );
        mnMoving = 0;
    }
    */ 
    bool moved = false;

    double  x, y, z;
    mpParent->GetViewer(&x, &y, &z);
    
    double 
        t1 = m_k * x + z - m_lz,
        t2 = -m_k * x + z;
 
    double pow = 0.0;
    int    movd = -1;

    if (type == Engine::KEY_DOWN_EX)
    {
        movd = +1;
        pow = mPower;
    }

    switch (key)
    {
    case GLUT_SPEC_KEY_LEFT:       
        if (t1 >=0 && t2 >= 0)
            mDirectionLU[0] = -pow;
        else if (t1 >=0)
            mDirectionLU[2] = pow;
        else if (t2 >=0)
            mDirectionLU[2] = -pow;
        else
            mDirectionLU[0] = pow;
              
        mnMoving += movd;
        moved = true;       
        break;  
     case GLUT_SPEC_KEY_RIGHT:
        if (t1 >=0 && t2 >= 0)
            mDirectionRD[0] = pow;
        else if (t1 >=0)
            mDirectionRD[2] = -pow;
        else if (t2 >=0)
            mDirectionRD[2] = pow;
        else
            mDirectionRD[0] = -pow;
        mnMoving += movd;
        moved = true;       
        break; 
     
     case GLUT_SPEC_KEY_UP:
        if (t1 >=0 && t2 >= 0)
            mDirectionLU[2] = -pow;
        else if (t1 >=0)
            mDirectionLU[0] = -pow;
        else if (t2 >=0)
            mDirectionLU[0] = pow;
        else
            mDirectionLU[2] = pow;

        mnMoving += movd;
        moved = true;
        break; 
     case GLUT_SPEC_KEY_DOWN:
        if (t1 >=0 && t2 >= 0)
            mDirectionRD[2] = pow;
        else if (t1 >=0)
            mDirectionRD[0] = pow;
        else if (t2 >=0)
            mDirectionRD[0] = -pow;
        else
            mDirectionRD[2] = -pow;
        moved = true;
        
        mnMoving += movd;
        break; 
    
     case ' ': 
        {
            if (Engine::KEY_UP_EX == type)
                break;
            Quad *q = mpBongo->Fire();
            if (q)
            {
                mpParent->mQuads.push_front(q);
            }
        }
        break;
    }

    if (moved)
    {
        double dir[3];
        memset(dir, 0, sizeof(dir) );
        vec_add(dir, mDirectionLU);
        vec_add(dir, mDirectionRD);
        mpBongo->SetDirection(dir);
    }

    return true;
}

Member Data Documentation

double BongoOrthoMover::m_k [private]

Definition at line 147 of file Controllers.h.

Referenced by BongoOrthoMover(), and ProcessKey().

double BongoOrthoMover::m_lz [private]

Definition at line 148 of file Controllers.h.

Referenced by BongoOrthoMover(), and ProcessKey().

Definition at line 164 of file Controllers.h.

Referenced by BongoOrthoMover(), and ProcessKey().

Definition at line 165 of file Controllers.h.

Referenced by BongoOrthoMover(), and ProcessKey().

How many directions are active.

Definition at line 152 of file Controllers.h.

Referenced by BongoOrthoMover(), and ProcessKey().

Definition at line 135 of file Controllers.h.

Referenced by ProcessKey().

double BongoOrthoMover::mPower [private]

Definition at line 136 of file Controllers.h.

Referenced by Init(), and ProcessKey().

Definition at line 134 of file Controllers.h.

Referenced by BongoOrthoMover(), and ProcessKey().


The documentation for this class was generated from the following files: