DriveHQ Start Menu
Cloud Drive Mapping
Folder Sync
Cloud Backup
True Drop Box
FTP/SFTP Hosting
Group Account
DriveHQ Start Menu
Online File Server
My Storage
|
Manage Shares
|
Publishes
|
Drop Boxes
|
Group Account
WebDAV Drive Mapping
Cloud Drive Home
|
WebDAV Guide
|
Drive Mapping Tool
|
Drive Mapping URL
Complete Data Backup
Backup Guide
|
Online Backup Tool
|
Cloud-to-Cloud Backup
FTP, Email & Web Service
FTP Home
|
FTP Hosting FAQ
|
Email Hosting
|
EmailManager
|
Web Hosting
Help & Resources
About
|
Enterprise Service
|
Partnership
|
Comparisons
|
Support
Quick Links
Security and Privacy
Download Software
Service Manual
Use Cases
Group Account
Online Help
Blog
Contact
Cloud Surveillance
Sign Up
Login
Features
Business Features
Online File Server
FTP Hosting
Cloud Drive Mapping
Cloud File Backup
Email Backup & Hosting
Cloud File Sharing
Folder Synchronization
Group Management
True Drop Box
Full-text Search
AD Integration/SSO
Mobile Access
IP Camera & DVR Solution
More...
Personal Features
Personal Cloud Drive
Backup All Devices
Mobile APPs
Personal Web Hosting
Sub-Account (for Kids)
Home/PC/Kids Monitoring
More...
Software
DriveHQ Drive Mapping Tool
DriveHQ FileManager
DriveHQ Online Backup
DriveHQ Mobile Apps
Pricing
Business Plans & Pricing
Personal Plans & Pricing
Price Comparison with Others
Feature Comparison with Others
Install Mobile App
Sign up
Creating account...
Invalid character in username! Only 0-9, a-z, A-Z, _, -, . allowed.
Username is required!
Invalid email address!
E-mail is required!
Password is required!
Password is invalid!
Password and confirmation do not match.
Confirm password is required!
I accept
Membership Agreement
Please read the Membership Agreement and check "I accept"!
Free Quick Sign-up
Sign-up Page
Log in
Signing in...
Username or e-mail address is required!
Password is required!
Keep me logged in
Quick Login
Forgot Password
Up
Upload
Download
Share
Publish
New Folder
New File
Copy
Cut
Delete
Paste
Rate
Upgrade
Rotate
Effect
Edit
Slide
History
#include "DarkPuzzle.h" #include "Map.h" #include "GameLevel.h" using namespace DarkBattle; float Map::WalkableHeight = 1.0f; //should represent the smallest slope float Map::GridSize = 5.0f; //should be equal to the size of movable object float Map::NegativeHeight = -10.0f;//height of the map 'pitfall' float Map::FootHeight = 1.0f; //to compute connection between map cells int Map::InfiniteDistance = 30000; //the maximum distance in distance map int Map::MaximumSearchDistance = 50; //this parameter will affect searching performance Map* Map::theMap = NULL; namespace DarkBattle{ extern FILE* fdebug; } Map::Map(float MapSizeX, float MapSizeY){ assert(theMap==NULL); theMap = this; this->mapSizeX = MapSizeX; this->mapSizeY = MapSizeY; this->sizeX = (int)ceil(MapSizeX/Map::GridSize); this->sizeY = (int)ceil(MapSizeY/Map::GridSize); this->totalSize = sizeX*sizeY; initHeight(); initCellConnection(); } void Map::initHeight(){ this->heightStatic = new Matrix
(sizeX,sizeY); for (int x=0;x
set(x,y,Map::NegativeHeight); } Vec3 from,to,hit,norm; for (int x=0;x
set(x,y,hit.z); } } } } void Map::initCellConnection(){ //NOTES: Don't use body to check for accessible cell because this will not work on //non-planar ground (the body will collide with the ground) Vec3 from,to; bool hit; connectX = new Matrix
(sizeX,sizeY);//for easy indexing, ONLY (sizeX-1)*sizeY is used for (int x=0;x
10.0f) connectX->set(x,y,false); else{ if (IsAccessible(to)){ from = from - Vec3(GridSize/2,0,0);//inlcude the hero body to = to + Vec3(GridSize/2,0,0); hit = GameLevel::RayCastTwoWay(from,to); //include the hero body, not allow him to pass narrow space if (!hit) hit = GameLevel::RayCastTwoWay(from+Vec3(0,GridSize/2,0),to+Vec3(0,GridSize/2,0)); if (!hit) hit = GameLevel::RayCastTwoWay(from-Vec3(0,GridSize/2,0),to-Vec3(0,GridSize/2,0)); connectX->set(x,y,!hit); }else connectX->set(x,y,false); } }else connectX->set(x,y,false); } } connectY = new Matrix
(sizeX,sizeY);//for easy indexing, ONLY sizeX*(sizeY-1) is used for (int x=0;x
10.0f) connectY->set(x,y,false); else{ if (IsAccessible(to)){ from = from - Vec3(0,GridSize/2,0); to = to + Vec3(0,GridSize/2,0); hit = GameLevel::RayCastTwoWay(from,to); if (!hit) hit = GameLevel::RayCastTwoWay(from+Vec3(GridSize/2,0,0),to+Vec3(GridSize/2,0,0)); if (!hit) hit = GameLevel::RayCastTwoWay(from-Vec3(GridSize/2,0,0),to-Vec3(GridSize/2,0,0)); connectY->set(x,y,!hit); }else connectY->set(x,y,false); } }else connectY->set(x,y,false); } } } float Map::heuristicDistance(int x,int y,Vec3 to){ return (GetPosition(x,y)-to).Length(); } bool Map::MakePath(Vec3 from, Vec3 to, Vec2Queue &wayPoints, DistanceMap &distanceMap, OpenListPriority &openList, CloseList &closeList){ assert(&wayPoints!=NULL); assert(&distanceMap!=NULL); //GetCell(from,&fromX,&fromY); //GetCell(to,&toX,&toY); distanceMap.Fill(InfiniteDistance); closeList.Clean(); openList.Clean(); int x,y; GetCell(from,x,y); openList.Push(heuristicDistance(x,y,to),Vec2(x,y)); distanceMap.set(x,y,0); return ComputeDistanceMapStep(to,distanceMap,openList,closeList); } #define COMPUTE_DISTANCE_MAP_STEPS 10 bool Map::ComputeDistanceMapStep(Vec3 to, DistanceMap &distanceMap, OpenListPriority &openList, CloseList &closeList){ assert(&distanceMap!=NULL); assert(&openList!=NULL); assert(&closeList!=NULL); Vec2 curPos,nei; Vec2Queue neighbors; int toX,toY; GetCell(to,toX,toY); int processedStep = 0; int curDistance; while (!openList.IsEmpty()) { curPos = openList.Pop(); if (closeList.IsClosed(curPos.x,curPos.y)) continue; curDistance = distanceMap.get(curPos.x,curPos.y); if (curPos.x==toX && curPos.y==toY){//found the solution return true; } if (curDistance>Map::MaximumSearchDistance){ return true; } GetNeighbors(curPos.x,curPos.y,neighbors); while (!neighbors.IsEmpty()){ nei = neighbors.Pop(); if (!closeList.IsClosed(nei.x,nei.y)){ distanceMap.set(nei.x,nei.y,curDistance+1); openList.Push(curDistance+1+ heuristicDistance(nei.x,nei.y,to),nei); } } closeList.Close(curPos.x,curPos.y); processedStep++; if (processedStep>COMPUTE_DISTANCE_MAP_STEPS) return false; } return true; } #define MAKE_PATH_STEPS 20 bool Map::MakePathStep(Vec3 from, Vec2 &curPos, DistanceMap &distanceMap, Vec2Queue &wayPoints){ //construct the waypoint here //wayPoints.Clean(); int fromX,fromY; GetCell(from,fromX,fromY); Vec2 nei; int curDistance; Vec2Queue neighbors; int processedStep = 0; while (curPos.x != fromX || curPos.y != fromY){ curDistance = distanceMap.get(curPos.x,curPos.y); wayPoints.PushBack(curPos); GetNeighbors(curPos.x,curPos.y,neighbors); while (!neighbors.IsEmpty()){ nei = neighbors.Pop(); if (distanceMap.get(nei.x,nei.y)==curDistance-1){ curPos = nei; break; } } processedStep++; if (processedStep>MAKE_PATH_STEPS) return false; } assert(curDistance<=1); return true; } bool Map::ComputeDistanceMapStep(Vec3 from, int range, DistanceMap &distanceMap, OpenListPriority &openList, CloseList &closeList, Vec2Queue &visitedPos, Matrix
&isCovered){ assert(&distanceMap!=NULL); assert(&openList!=NULL); assert(&closeList!=NULL); assert(&visitedPos!=NULL); assert(&isCovered!=NULL); //initialization //distanceMap.Fill(InfiniteDistance); //openList.Clean(); //int fromX,fromY; //GetCell(from,fromX,fromY); //openList.Push(0,Vec2(fromX,fromY)); //distanceMap.set(fromX,fromY,0); //closeList.Clean(); Vec2 curPos,nei; Vec2Queue neighbors; int curDistance; int processedStep = 0; while (!openList.IsEmpty()) { curPos = openList.Pop(); if (closeList.IsClosed(curPos.x,curPos.y)) continue; curDistance = distanceMap.get(curPos.x,curPos.y); if (curDistance>range){ return true; } GetNeighbors(curPos.x,curPos.y,neighbors); while (!neighbors.IsEmpty()){ nei = neighbors.Pop(); if (!closeList.IsClosed(nei.x,nei.y)){ distanceMap.set(nei.x,nei.y,curDistance+1); openList.Push(curDistance+1,nei); } } closeList.Close(curPos.x,curPos.y); visitedPos.Push(curPos); //isCovered.set(curPos.x,curPos.y,GameLevel::RayCast(Character::GetHero()->GetPos()+Vec3(0,0,Character::FireHeight), // GetPosition(curPos.x,curPos.y)+Vec3(0,0,Character::FireHeight),NULL,NULL)); isCovered.set(curPos.x,curPos.y,Character::IsCovered(Character::GetHero()->GetPos(), GetPosition(curPos.x,curPos.y))); processedStep++; if (processedStep>COMPUTE_DISTANCE_MAP_STEPS) return false; } return true; } void Map::InitPathFindingParameters(Vec2Queue* wayPoints, Vec3Queue* smoothWP, DistanceMap* distanceMap, Vec3* from, OpenListPriority* openList, CloseList* closeList, Vec2Queue* visitedPos,Matrix
* isCovered){ if (wayPoints!=NULL) wayPoints->Clean(); if (smoothWP!=NULL) smoothWP->Clean(); if (distanceMap!=NULL) distanceMap->Fill(InfiniteDistance); if (closeList!=NULL) closeList->Clean(); if (visitedPos!=NULL) visitedPos->Clean(); if (isCovered!=NULL) isCovered->Fill(false); if (openList!=NULL){ assert(from!=NULL); openList->Clean(); int x,y; GetCell(*from,x,y); openList->Push(0,Vec2(x,y)); distanceMap->set(x,y,0); } } void Map::GetNeighbors(int x,int y,Vec2Queue &ret){ assert(&ret!=NULL); ret.Clean(); if (x
0 && IsConnectX(x-1,y)) ret.Push(Vec2(x-1,y)); if (y
0 && IsConnectY(x,y-1)) ret.Push(Vec2(x,y-1)); } void Map::InitMakeSmoothPath(Vec3 from, Vec3 &refPos, Vec3 &prePos){ refPos = from + Vec3(0,0,Map::FootHeight); prePos = refPos; } #define MAKE_SMOOTH_PATH_STEPS 3 bool Map::MakeSmoothPathStep(Vec3 &refPos, Vec3 &prePos, Vec3 to, Vec2Queue &wayPoints, Vec3Queue &smoothWps){ Vec2 wp; //smoothWps.Clean(); bool hit; Vec3 norm,curPos; int processedStep = 0; while (!wayPoints.IsEmpty()){ wp = wayPoints.Pop(); curPos = GetPosition(wp.x,wp.y); curPos.z += Map::FootHeight; hit = GameLevel::RayCast(refPos,curPos,NULL,NULL); if (!hit){ norm = refPos - curPos; norm = Vec3(norm.y,-norm.x,norm.z); norm = norm / norm.Length() * GridSize/2; hit = GameLevel::RayCast(refPos+norm,curPos+norm,NULL,NULL); } if (!hit){ hit = GameLevel::RayCast(refPos-norm,curPos-norm,NULL,NULL); } if (hit){ if (smoothWps.Size()>Character::WayPointQueueLength) return false; smoothWps.Push(prePos); DEBUG_OUTPUT("Push wp\n"); refPos = prePos; }else{ prePos = curPos; } processedStep++; if (processedStep>MAKE_SMOOTH_PATH_STEPS) return false; } smoothWps.Push(to); DEBUG_OUTPUT("Push wp\n"); return true; } Vec3 Map::GetPosition(int x,int y){ return Vec3(x*GridSize+GridSize/2,y*GridSize+GridSize/2,heightStatic->get(x,y)); } Map::~Map(){ SAFE_DELETE(heightStatic); SAFE_DELETE(connectX); SAFE_DELETE(connectY); assert(theMap!=NULL); theMap = NULL; } bool Map::IsAccessible(int posX,int posY){ return (heightStatic->get(posX,posY)<=Map::WalkableHeight && heightStatic->get(posX,posY)>Map::NegativeHeight); } bool Map::IsAccessible(Vec3 pos){ int x,y; GetCell(pos,x,y); return IsAccessible(x,y); } void Map::GetCell(DarkBattle::Vec3 pos, int &x, int &y){ assert(&x!=NULL); assert(&y!=NULL); x = (int)floor((pos.x-GridSize/2)/GridSize); y =(int)floor((pos.y-GridSize/2)/GridSize); }
Map.cpp
Page URL
File URL
Prev
50/65
Next
Download
( 10 KB )
Note: The DriveHQ service banners will NOT be displayed if the file owner is a paid member.
Comments
Total ratings:
0
Average rating:
Not Rated
Would you like to comment?
Join DriveHQ
for a free account, or
Logon
if you are already a member.