- // Animate the circle 1000 times
- // Written by Paul Kohut, June 8, 2009
- // paulkohut@hotmail.com
- // Implements a fairly smooth aniniation loop within AutoCAD.
- //-----------------------------------------------------------------------------
- //----- acrxEntryPoint.h
- //-----------------------------------------------------------------------------
- #include "StdAfx.h"
- #include "resource.h"
- #define _USE_MATH_DEFINES 1
- #include
- #define index(x, y, c) (y * c + x)
- //-----------------------------------------------------------------------------
- #define szRDS _RXST("nav")
- #pragma comment(linker, "/export:_acrxGetApiVersion,PRIVATE")
- //#pragma comment(linker, "/export:_acrxEntryPoint,PRIVATE")
- //-----------------------------------------------------------------------------
- //----- ObjectARX EntryPoint
- class CBadGraphicsApp : public AcRxArxApp {
- public:
- CBadGraphicsApp () : AcRxArxApp () {}
- virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
- AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;
- return (retCode) ;
- }
- virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
- AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;
- return (retCode) ;
- }
- virtual void RegisterServerComponents () {
- }
- static void EraseAllEntity(AcDbBlockTableRecordPointer & pBtr)
- {
- AcDbBlockTableRecordIterator * pIter;
- pBtr->newIterator(pIter);
- for(pIter->start(); !pIter->done(); pIter->step()) {
- AcDbObjectId entId;
- if(pIter->getEntityId(entId) == Acad::eOk) {
- AcDbObject *pEnt;
- if(actrTransactionManager->getObject(pEnt, entId, AcDb::kForWrite) == Acad::eOk)
- {
- pEnt->erase();
- }
- }
- }
- }
- // draws a checker board, grid lines, and animates a circle.
- static void DrawGraphics(void)
- {
- int nMapSizeX = 8;
- int nMapSizeY = 8;
- double dGridSizeX = 1.0, dGridSizeY = 1.0;
- AcCmColor colorBlack;
- AcCmColor colorGrid;
- AcCmColor colorWhite;
- AcCmColor colorRed;
- colorBlack.setRGB(0, 0, 0);
- colorGrid.setRGB(91, 91, 91);
- colorWhite.setRGB(255, 255, 255);
- colorRed.setRGB(255, 0, 0);
- double x = 0.0, y = 0.0;
- // Draw the checker board layout
- AcDbDatabase * pDb = acdbHostApplicationServices()->workingDatabase();
- AcDbBlockTableRecordPointer pRcd(ACDB_MODEL_SPACE, pDb, AcDb::kForWrite);
- if(pRcd.openStatus() == Acad::eOk) {
- EraseAllEntity(pRcd);
- for(int j = 0; j setColor((index(i, j, nMapSizeX) + j) % 2 ? colorBlack : colorWhite);
- AcDbObjectId objId;
- if(pRcd->appendAcDbEntity(objId, pSolid) == Acad::eOk)
- {
- actrTransactionManager->addNewlyCreatedDBRObject(pSolid);
- pSolid->draw();
- }
- else
- delete pSolid;
- x += dGridSizeX;
- }
- y -= dGridSizeY;
- }
- // Draw vertical grid lines
- x = 0.0;
- y = 0.0;
- double gridLineWidth = 0.05;
- for(int i = 0; i addVertexAt(pPline->numVerts(), AcGePoint2d(x, y), 0.0, gridLineWidth, gridLineWidth);
- pPline->addVertexAt(pPline->numVerts(), AcGePoint2d(x, y - (dGridSizeY * nMapSizeY)), 0.0, gridLineWidth, gridLineWidth);
- pPline->setColor(colorGrid);
- AcDbObjectId objId;
- if(pRcd->appendAcDbEntity(objId, pPline) == Acad::eOk)
- {
- actrTransactionManager->addNewlyCreatedDBRObject(pPline);
- pPline->draw();
- }
- else
- delete pPline;
- x += dGridSizeX;
- }
- // Draw horizontal grid lines
- x = 0.0;
- y = 0.0;
- for(int i = 0; i addVertexAt(pPline->numVerts(), AcGePoint2d(x, y), 0.0, gridLineWidth, gridLineWidth);
- pPline->addVertexAt(pPline->numVerts(), AcGePoint2d(x + (dGridSizeX * nMapSizeX), y), 0.0, gridLineWidth, gridLineWidth);
- pPline->setColor(colorGrid);
- if(pRcd->appendAcDbEntity(pPline) == Acad::eOk)
- {
- actrTransactionManager->addNewlyCreatedDBRObject(pPline);
- pPline->draw();
- }
- else
- delete pPline;
- y -= dGridSizeY;
- }
- // Animate a circle going in a circle
- static double stepp = M_PI_2 / 180.0;
- static double x1 = nMapSizeX * dGridSizeX * 0.5;
- static double y1 = -nMapSizeY * dGridSizeY * 0.5;
- static double ang = 0.0;
- AcDbCircle * pCircle = new AcDbCircle();