NLS Engine  v0.1
The Next Logical Step in game engine design.
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines
PointLine.cpp
Go to the documentation of this file.
00001 
00012 #include "PointLine.h"
00013 
00014 // System Library Includes
00015 
00016 // Application Library Includes
00017 #include <boost/any.hpp>
00018 
00019 // Local Includes
00020 #include "../../../sharedbase/PointList.h"
00021 #include "../../../sharedbase/Entity.h"
00022 #include "TiledMap.h"
00023 
00024 // Forward Declarations
00025 
00026 // Typedefs and data structures
00027 
00028 // Constants
00029 
00030 // Class methods
00031 namespace GraphicsCore {
00032   PointLine::PointLine(EntitySPTR owner, ModuleInterface* renderModule, LPDIRECT3DDEVICE9 d3dDevice) : RenderableComponent(owner, renderModule) {
00033     D3DXCreateLine(d3dDevice, &this->line);
00034   }
00035 
00036   PointLine::~PointLine( void ) {
00037 
00038   }
00039 
00040   void PointLine::Render( LPDIRECT3DDEVICE9 ) {
00041     if (this->owner->properties.PropertyExists("pointlist")) {
00042       PointList plist = *(this->owner->properties.GetPropertyReference<PointList*>("pointlist"));
00043       unsigned int viewportWidth = 800, viewportHeight = 600;
00044       if (this->owner->GetParent() != nullptr) {
00045         viewportWidth = this->owner->GetParent()->properties.GetPropertyValue<unsigned int>("viewportWidth");
00046         viewportHeight = this->owner->GetParent()->properties.GetPropertyValue<unsigned int>("viewportHeight");
00047       }
00048       auto beginplist = plist.BeginPoint();
00049       auto endplist = plist.EndPoint();
00050       D3DXVECTOR2* points = new D3DXVECTOR2[plist.Size()];
00051       int i = 0;
00052       int x, y;
00053       for (auto itr = beginplist; itr != endplist; ++itr, ++i) {
00054         x = itr->x * GraphicsCore::TILE_WIDTH - this->owner->GetWorldPosition().x + GraphicsCore::TILE_WIDTH/2;
00055         y = itr->y * GraphicsCore::TILE_HEIGHT - this->owner->GetWorldPosition().y + GraphicsCore::TILE_HEIGHT/2;
00056         if (((x + GraphicsCore::TILE_WIDTH/2) < 0) && (x > (viewportWidth + (GraphicsCore::TILE_WIDTH/2)))) { // Clamping for inside viewport
00057           continue;
00058         }
00059         if (((y + GraphicsCore::TILE_HEIGHT/2) < 0) && (y > (viewportHeight + (GraphicsCore::TILE_HEIGHT/2)))) { // Clamping for inside viewport
00060           continue;
00061         }
00062         points[i].x = x;
00063         points[i].y = y;
00064       }
00065 
00066       this->line->SetWidth(3.0f);
00067       this->line->Begin();
00068       this->line->Draw(points, plist.Size(), D3DCOLOR_RGBA(255,0,0,255));
00069       this->line->End();
00070 
00071       delete[] points;
00072     }
00073   }
00074 }