/* cursorStack.cpp * J Scott Cameron * * Implements class defined in cursorStack.h */ #include "cursorStack.h" /* default constructor * creates an empty stack with * the top cursor's matrix eqaul * to the identity matrix */ CursorStack::CursorStack() { vect = vector(0); Cursor identity; vect.push_back(identity); angle = 60.0f; device = NULL; } /* resets stack, not implemented */ void CursorStack::reset() { } /* push down on the stack */ void CursorStack::push() { vector::reverse_iterator itr = vect.rbegin(); vect.push_back(*itr); } /* pop off the stack */ void CursorStack::pop() { vect.pop_back(); } /* returns an iterator pointing to the top Cursor */ vector::reverse_iterator CursorStack::getTop() { vector::reverse_iterator itr = vect.rbegin(); return itr; } /* sets the associated D3D deveice */ void CursorStack::setDevice(LPDIRECT3DDEVICE8 d) { device = d; } /* upadates the D3D device with the top cursor */ void CursorStack::updateCursor() { device->SetTransform(D3DTS_WORLD,&(getTop()->matrix)); } /* move the top cursor forward a unit*/ void CursorStack::forwardNoDraw() { D3DXMATRIX temp; D3DXMatrixMultiply(&(getTop()->matrix), D3DXMatrixTranslation(&temp,0,0,1), &(getTop()->matrix)); updateCursor(); } /* move the top cursor forward a unit and * draw along that path */ void CursorStack::forwardDraw() { D3DXMATRIX temp; D3DXMATRIX* mat = &(getTop()->matrix); D3DXMatrixMultiply(mat, D3DXMatrixTranslation(&temp,0,0,.5),mat); updateCursor(); LPD3DXMESH tempMesh = *(getTop()->mesh); tempMesh->DrawSubset(0); D3DXMatrixMultiply(mat, D3DXMatrixTranslation(&temp,0,0,.5),mat); updateCursor(); } /* rotate negatively in the X-axis */ void CursorStack::rotXminus() { D3DXMATRIX temp; D3DXMatrixMultiply(&(getTop()->matrix), D3DXMatrixRotationX(&temp,D3DXToRadian( -angle ) ), &(getTop()->matrix)); updateCursor(); } /* rotate positively in the X-axis */ void CursorStack::rotXplus() { D3DXMATRIX temp; D3DXMatrixMultiply(&(getTop()->matrix), D3DXMatrixRotationX(&temp,D3DXToRadian( angle ) ), &(getTop()->matrix)); updateCursor(); } /* rotate negatively in the Y-axis */ void CursorStack::rotYminus() { D3DXMATRIX temp; D3DXMatrixMultiply(&(getTop()->matrix), D3DXMatrixRotationY(&temp,D3DXToRadian( -angle ) ), &(getTop()->matrix)); updateCursor(); } /* rotate positively in the Y-axis */ void CursorStack::rotYplus() { D3DXMATRIX temp; D3DXMatrixMultiply(&(getTop()->matrix), D3DXMatrixRotationY(&temp,D3DXToRadian( angle ) ), &(getTop()->matrix)); updateCursor(); } /* rotate negatively in the Z-axis */ void CursorStack::rotZminus() { D3DXMATRIX temp; D3DXMatrixMultiply(&(getTop()->matrix), D3DXMatrixRotationZ(&temp,D3DXToRadian( -angle ) ), &(getTop()->matrix)); updateCursor(); } /* rotate positively in the Z-axis */ void CursorStack::rotZplus() { D3DXMATRIX temp; D3DXMatrixMultiply(&(getTop()->matrix), D3DXMatrixRotationZ(&temp,D3DXToRadian( angle ) ), &(getTop()->matrix)); updateCursor(); } /*draws the given graphical L-System string*/ void CursorStack::interpretString(string s) { /* inspect each character in the string */ for(int i = 0; i