mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
factored out land and water body ray casting
This commit is contained in:
+3
-4
@@ -6,7 +6,6 @@
|
||||
#include <quad.h>
|
||||
#include <box.h>
|
||||
#include <text.h>
|
||||
#include <rayCaster.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
#include <solUtil.h>
|
||||
@@ -403,18 +402,18 @@ namespace battleship{
|
||||
Vector3 endPos = screenToSpace(getCursorPos());
|
||||
|
||||
Vector3 rayDir = (endPos - camPos).norm();
|
||||
vector<RayCaster::CollisionResult> results = RayCaster::cast(camPos, rayDir, Map::getSingleton()->getNodeParent(), 0, configData::DIST_FROM_RAY);
|
||||
Map *map = Map::getSingleton();
|
||||
vector<RayCaster::CollisionResult> results = map->raycastTerrain(camPos, rayDir, true);
|
||||
|
||||
if(!results.empty()){
|
||||
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
|
||||
Map *map = Map::getSingleton();
|
||||
|
||||
for(Unit *u : mainPlayer->getSelectedUnits()){
|
||||
Vector3 pos = u->getPos();
|
||||
Node *nodeParent = map->getNodeParent();
|
||||
|
||||
if(u->getType() == UnitType::UNDERWATER && nodeParent->getNumChildren() > 0){
|
||||
vector<RayCaster::CollisionResult> res = RayCaster::cast(Vector3(pos.x, 100, pos.z), Vector3(0, -1, 0), nodeParent->getChild(0), 0, configData::DIST_FROM_RAY);
|
||||
vector<RayCaster::CollisionResult> res = map->raycastTerrain(Vector3(pos.x, 100, pos.z), Vector3(0, -1, 0), false);
|
||||
|
||||
Vector3 waterBodyPos = Vector3::VEC_ZERO;
|
||||
Vector3 cellSize = map->getCellSize();
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <mesh.h>
|
||||
#include <model.h>
|
||||
#include <root.h>
|
||||
#include <rayCaster.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -119,13 +118,7 @@ namespace battleship{
|
||||
frame.update();
|
||||
|
||||
Vector3 startPos = Root::getSingleton()->getCamera()->getPosition();
|
||||
vector<RayCaster::CollisionResult> results = RayCaster::cast(
|
||||
startPos,
|
||||
(screenToSpace(getCursorPos()) - startPos).norm(),
|
||||
Map::getSingleton()->getNodeParent()->getChild(0),
|
||||
0,
|
||||
configData::DIST_FROM_RAY
|
||||
);
|
||||
vector<RayCaster::CollisionResult> results = Map::getSingleton()->raycastTerrain(startPos, (screenToSpace(getCursorPos()) - startPos).norm(), true);
|
||||
|
||||
if(results.empty()) return;
|
||||
|
||||
|
||||
@@ -352,6 +352,22 @@ namespace battleship{
|
||||
destroyScene();
|
||||
}
|
||||
|
||||
vector<RayCaster::CollisionResult> Map::raycastTerrain(Vector3 rayPos, Vector3 rayDir, bool bothTerrTypes){
|
||||
vector<RayCaster::CollisionResult> allResults = RayCaster::cast(rayPos, rayDir, terrainNode->getChild(0), 0, configData::DIST_FROM_RAY);
|
||||
|
||||
if(bothTerrTypes){
|
||||
vector<Node*> waterNodes = terrainNode->getChildren();
|
||||
waterNodes.erase(waterNodes.begin());
|
||||
|
||||
vector<RayCaster::CollisionResult> waterResults = RayCaster::cast(rayPos, rayDir, waterNodes);
|
||||
allResults.insert(allResults.end(), waterResults.begin(), waterResults.end());
|
||||
|
||||
RayCaster::sortResults(allResults);
|
||||
}
|
||||
|
||||
return allResults;
|
||||
}
|
||||
|
||||
template<typename T> int Map::bsearch(vector<T> haystack, T needle, float eps){
|
||||
T haystackMidVal;
|
||||
bool sizeHaystackEven = (haystack.size() % 2 == 0);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <rayCaster.h>
|
||||
#include <vector.h>
|
||||
#include <util.h>
|
||||
|
||||
@@ -46,6 +47,7 @@ namespace battleship{
|
||||
void update();
|
||||
void load(std::string, bool = false);
|
||||
void unload();
|
||||
std::vector<vb01::RayCaster::CollisionResult> raycastTerrain(vb01::Vector3, vb01::Vector3, bool);
|
||||
int getCellId(vb01::Vector3, bool = true);
|
||||
bool isPointWithinTerrainObject(vb01::Vector3, int);
|
||||
void loadPlayerGameObjects();
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "mesh.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <rayCaster.h>
|
||||
#include <box.h>
|
||||
#include <text.h>
|
||||
#include <node.h>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <node.h>
|
||||
#include <model.h>
|
||||
#include <material.h>
|
||||
#include <rayCaster.h>
|
||||
#include <quaternion.h>
|
||||
#include <particleEmitter.h>
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <solUtil.h>
|
||||
|
||||
#include <util.h>
|
||||
#include <rayCaster.h>
|
||||
#include <box.h>
|
||||
#include <model.h>
|
||||
#include <quaternion.h>
|
||||
|
||||
Reference in New Issue
Block a user