mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
implemented landmass vert shifting
This commit is contained in:
@@ -35,11 +35,18 @@ mappings = {
|
||||
{bind = 31, trigger = 57, action = true, bindType = 0, inOptions = true},
|
||||
{bind = 32, trigger = 66, action = true, bindType = 0, inOptions = true},
|
||||
{bind = 33, trigger = 256, action = true, bindType = 0, inOptions = true},
|
||||
|
||||
{bind = 7, trigger = 312, action = false, bindType = 2, inOptions = false},
|
||||
{bind = 8, trigger = 313, action = false, bindType = 2, inOptions = false},
|
||||
{bind = 9, trigger = 310, action = false, bindType = 2, inOptions = false},
|
||||
{bind = 10, trigger = 311, action = false, bindType = 2, inOptions = false},
|
||||
{bind = 11, trigger = 1, action = true, bindType = 1, inOptions = false},
|
||||
{bind = 33, trigger = 256, action = true, bindType = 0, inOptions = false},
|
||||
{bind = 0, trigger = 0, action = true, bindType = 1, inOptions = false},
|
||||
{bind = 34, trigger = 90, action = true, bindType = 0, inOptions = false},
|
||||
{bind = 35, trigger = 88, action = true, bindType = 0, inOptions = false},
|
||||
{bind = 36, trigger = 312, action = false, bindType = 2, inOptions = false},
|
||||
{bind = 37, trigger = 313, action = false, bindType = 2, inOptions = false},
|
||||
}
|
||||
graphics = {
|
||||
resolution = {x = 1920, y = 1080}
|
||||
|
||||
@@ -2,42 +2,46 @@
|
||||
#define BINDS_H
|
||||
|
||||
namespace battleship{
|
||||
enum Bind{
|
||||
LEFT_CLICK,
|
||||
SCROLLING_UP,
|
||||
SCROLLING_DOWN,
|
||||
LEFT,
|
||||
RIGHT,
|
||||
DELETE_CHAR,
|
||||
TOGGLE_MAIN_MENU,
|
||||
LOOK_UP,
|
||||
LOOK_DOWN,
|
||||
LOOK_LEFT,
|
||||
LOOK_RIGHT,
|
||||
LOOK_AROUND,
|
||||
DRAG_BOX,
|
||||
DESELECT,
|
||||
HALT,
|
||||
ZOOM_IN,
|
||||
ZOOM_OUT,
|
||||
LEFT_CONTROL,
|
||||
LEFT_SHIFT,
|
||||
SELECT_PATROL_POINTS,
|
||||
LAUNCH,
|
||||
TOGGLE_SUB,
|
||||
GROUP_0,
|
||||
GROUP_1,
|
||||
GROUP_2,
|
||||
GROUP_3,
|
||||
GROUP_4,
|
||||
GROUP_5,
|
||||
GROUP_6,
|
||||
GROUP_7,
|
||||
GROUP_8,
|
||||
GROUP_9,
|
||||
SELECT_STRUCTURE,
|
||||
DESELECT_STRUCTURE
|
||||
};
|
||||
enum Bind{
|
||||
LEFT_CLICK,
|
||||
SCROLLING_UP,
|
||||
SCROLLING_DOWN,
|
||||
LEFT,
|
||||
RIGHT,
|
||||
DELETE_CHAR,
|
||||
TOGGLE_MAIN_MENU,
|
||||
LOOK_UP,
|
||||
LOOK_DOWN,
|
||||
LOOK_LEFT,
|
||||
LOOK_RIGHT,
|
||||
LOOK_AROUND,
|
||||
DRAG_BOX,
|
||||
DESELECT,
|
||||
HALT,
|
||||
ZOOM_IN,
|
||||
ZOOM_OUT,
|
||||
LEFT_CONTROL,
|
||||
LEFT_SHIFT,
|
||||
SELECT_PATROL_POINTS,
|
||||
LAUNCH,
|
||||
TOGGLE_SUB,
|
||||
GROUP_0,
|
||||
GROUP_1,
|
||||
GROUP_2,
|
||||
GROUP_3,
|
||||
GROUP_4,
|
||||
GROUP_5,
|
||||
GROUP_6,
|
||||
GROUP_7,
|
||||
GROUP_8,
|
||||
GROUP_9,
|
||||
SELECT_STRUCTURE,
|
||||
DESELECT_STRUCTURE,
|
||||
DECREASE_RADIUS,
|
||||
INCREASE_RADIUS,
|
||||
PUSH_VERTS_UP,
|
||||
PUSH_VERTS_DOWN
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+2
-2
@@ -20,9 +20,9 @@ namespace battleship{
|
||||
const int maxNumGroups = 10;
|
||||
|
||||
const static int numAppStates = 4;
|
||||
const static int numStaticBinds[numAppStates]{6, 0, 5, 7};
|
||||
const static int numStaticBinds[numAppStates]{6, 0, 5, 11};
|
||||
const static int numConfBinds[numAppStates]{0, 1, 22, 0};
|
||||
const static int maxStaticBinds = 7;
|
||||
const static int maxStaticBinds = 11;
|
||||
const static int maxConfBinds = 22;
|
||||
const static int numScripts = 5;
|
||||
|
||||
|
||||
+74
-2
@@ -10,6 +10,7 @@
|
||||
#include "mesh.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <ray.h>
|
||||
#include <box.h>
|
||||
#include <node.h>
|
||||
#include <quad.h>
|
||||
@@ -61,6 +62,33 @@ namespace battleship{
|
||||
assetManager->load(DEFAULT_TEXTURE);
|
||||
}
|
||||
|
||||
void MapEditorAppState::MapEditor::updateCircleRadius(bool increase){
|
||||
circleRadius += (increase ? INCREASE_RATE : -INCREASE_RATE);
|
||||
|
||||
if(circleRadius > MAX_RADIUS)
|
||||
circleRadius = MAX_RADIUS;
|
||||
else if(circleRadius < MIN_RADIUS)
|
||||
circleRadius = MIN_RADIUS;
|
||||
}
|
||||
|
||||
void MapEditorAppState::MapEditor::pushLandmassVerts(float strength){
|
||||
Mesh *mesh = map->getTerrainObject(0).node->getChild(0)->getMesh(0);
|
||||
MeshData meshData = mesh->getMeshBase();
|
||||
MeshData::Vertex *verts = meshData.vertices;
|
||||
int numVerts = meshData.numTris * 3;
|
||||
|
||||
for(int i = 0; i < numVerts; i++){
|
||||
Vector3 distVec = verts[i].pos - pushPos;
|
||||
distVec.y = 0;
|
||||
float dist = distVec.getLength();
|
||||
|
||||
if(dist < circleRadius)
|
||||
verts[i].pos.y += 10 * strength * dist / circleRadius;
|
||||
}
|
||||
|
||||
mesh->updateVerts(meshData);
|
||||
}
|
||||
|
||||
//TODO fix crash when using 100 side verts
|
||||
void MapEditorAppState::MapEditor::generatePlane(Vector2 size){
|
||||
int numSideVerts = 10, numIndices = 6 * (numSideVerts - 1) * (numSideVerts - 1);
|
||||
@@ -240,9 +268,11 @@ namespace battleship{
|
||||
}
|
||||
|
||||
void MapEditorAppState::update(){
|
||||
radiusText->setText(L"Radius: " + to_wstring(mapEditor->getCircleRadius()));
|
||||
|
||||
CameraController *camCtr = CameraController::getSingleton();
|
||||
|
||||
if(!camCtr->isLookingAround())
|
||||
if(!(camCtr->isLookingAround() || mapEditor->isPushing()))
|
||||
camCtr->updateCameraPosition();
|
||||
|
||||
UnitFrameController *ufCtr = UnitFrameController::getSingleton();
|
||||
@@ -254,6 +284,18 @@ namespace battleship{
|
||||
void MapEditorAppState::onAttached(){
|
||||
AbstractAppState::onAttached();
|
||||
mapEditor = new MapEditor(mapName, mapSize);
|
||||
|
||||
Root *root = Root::getSingleton();
|
||||
Material *mat = new Material(root->getLibPath() + "text");
|
||||
mat->addBoolUniform("texturingEnabled", false);
|
||||
mat->addVec4Uniform("diffuseColor", Vector4::VEC_IJKL);
|
||||
|
||||
radiusText = new Text(GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", L"");
|
||||
radiusText->setMaterial(mat);
|
||||
|
||||
Node *node = new Node(Vector3(0, 100, 0));
|
||||
node->addText(radiusText);
|
||||
root->getGuiNode()->attachChild(node);
|
||||
}
|
||||
|
||||
void MapEditorAppState::onDettached(){}
|
||||
@@ -276,6 +318,32 @@ namespace battleship{
|
||||
ufCtr->removeUnitFrames();
|
||||
ufCtr->setPlacingFrames(false);
|
||||
break;
|
||||
case Bind::INCREASE_RADIUS:
|
||||
if(isPressed) mapEditor->updateCircleRadius(true);
|
||||
break;
|
||||
case Bind::DECREASE_RADIUS:
|
||||
if(isPressed) mapEditor->updateCircleRadius(false);
|
||||
break;
|
||||
case Bind::LEFT_CLICK:
|
||||
if(isPressed){
|
||||
Camera *cam = Root::getSingleton()->getCamera();
|
||||
Vector3 startPos = cam->getPosition();
|
||||
Vector3 endPos = screenToSpace(getCursorPos());
|
||||
|
||||
vector<Ray::CollisionResult> results;
|
||||
Ray::retrieveCollisions(startPos, (endPos - startPos).norm(), Map::getSingleton()->getTerrainObject(0).node, results);
|
||||
Ray::sortResults(results);
|
||||
|
||||
bool push = !results.empty();
|
||||
mapEditor->setPushing(push);
|
||||
|
||||
if(push)
|
||||
mapEditor->setPushPos(results[0].pos);
|
||||
}
|
||||
else
|
||||
mapEditor->setPushing(false);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +356,7 @@ namespace battleship{
|
||||
if(camCtr->isLookingAround()){
|
||||
Vector3 dirProj = Root::getSingleton()->getCamera()->getDirection();
|
||||
dirProj = Vector3(dirProj.x, 0, dirProj.z).norm();
|
||||
CameraController::getSingleton()->orientCamera(Vector3(0, 1, 0).cross(dirProj), strength);
|
||||
camCtr->orientCamera(Vector3(0, 1, 0).cross(dirProj), strength);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -298,6 +366,10 @@ namespace battleship{
|
||||
camCtr->orientCamera(Vector3(0, 1, 0), strength);
|
||||
|
||||
break;
|
||||
case Bind::PUSH_VERTS_UP:
|
||||
case Bind::PUSH_VERTS_DOWN:
|
||||
if(mapEditor->isPushing()) mapEditor->pushLandmassVerts(strength);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,12 @@ namespace battleship{
|
||||
};
|
||||
|
||||
MapEditor(std::string, vb01::Vector2);
|
||||
void updateCircleRadius(bool);
|
||||
void pushLandmassVerts(float);
|
||||
inline float getCircleRadius(){return circleRadius;}
|
||||
inline bool isPushing(){return pushing;}
|
||||
inline void setPushing(bool p){pushing = p;}
|
||||
inline void setPushPos(vb01::Vector3 p){pushPos = p;}
|
||||
private:
|
||||
void generatePlane(vb01::Vector2);
|
||||
void prepareGui();
|
||||
@@ -38,6 +44,10 @@ namespace battleship{
|
||||
inline vb01::Texture* getLandmassTexture(int i){return landmassTextures[i];}
|
||||
|
||||
Map *map;
|
||||
bool pushing = false;
|
||||
const float MIN_RADIUS = 1, MAX_RADIUS = 100, INCREASE_RATE = 1;
|
||||
float circleRadius = MIN_RADIUS;
|
||||
vb01::Vector3 pushPos = vb01::Vector3::VEC_ZERO;
|
||||
std::vector<vb01::Texture*> skyTextures, landmassTextures;
|
||||
UnitListbox *vehicleListbox = nullptr, *structureListbox = nullptr;
|
||||
};
|
||||
@@ -53,6 +63,7 @@ namespace battleship{
|
||||
MapEditor *mapEditor = nullptr;
|
||||
std::string mapName;
|
||||
vb01::Vector2 mapSize;
|
||||
vb01::Text *radiusText = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user