mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
implemented terrain object movement
This commit is contained in:
@@ -43,10 +43,16 @@ mappings = {
|
||||
{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 = 34, trigger = 67, action = true, bindType = 0, inOptions = false},
|
||||
{bind = 35, trigger = 86, 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},
|
||||
{bind = 38, trigger = 71, action = true, bindType = 0, inOptions = false},
|
||||
{bind = 39, trigger = 256, action = true, bindType = 0, inOptions = false},
|
||||
{bind = 40, trigger = 90, action = true, bindType = 0, inOptions = false},
|
||||
{bind = 41, trigger = 89, action = true, bindType = 0, inOptions = false},
|
||||
{bind = 42, trigger = 88, action = true, bindType = 0, inOptions = false},
|
||||
{bind = 43, trigger = 87, action = true, bindType = 0, inOptions = false},
|
||||
}
|
||||
graphics = {
|
||||
resolution = {x = 1920, y = 1080}
|
||||
|
||||
@@ -40,7 +40,13 @@ namespace battleship{
|
||||
DECREASE_RADIUS,
|
||||
INCREASE_RADIUS,
|
||||
PUSH_VERTS_UP,
|
||||
PUSH_VERTS_DOWN
|
||||
PUSH_VERTS_DOWN,
|
||||
MOVE_TERR_OBJ,
|
||||
STOP_TERR_OBJ,
|
||||
MOVE_X_AXIS,
|
||||
MOVE_Y_AXIS,
|
||||
MOVE_Z_AXIS,
|
||||
CREATE_WATERBODY
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+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, 11};
|
||||
const static int numStaticBinds[numAppStates]{6, 0, 5, 17};
|
||||
const static int numConfBinds[numAppStates]{0, 1, 22, 0};
|
||||
const static int maxStaticBinds = 11;
|
||||
const static int maxStaticBinds = 17;
|
||||
const static int maxConfBinds = 22;
|
||||
const static int numScripts = 5;
|
||||
|
||||
|
||||
@@ -99,6 +99,44 @@ namespace battleship{
|
||||
}
|
||||
}
|
||||
|
||||
void MapEditorAppState::MapEditor::createWaterbody(){
|
||||
Material *mat = new Material(Root::getSingleton()->getLibPath() + "texture");
|
||||
mat->addBoolUniform("lightingEnabled", false);
|
||||
mat->addBoolUniform("texturingEnabled", true);
|
||||
mat->addTexUniform("textures[0]", waterTextures[0], false);
|
||||
|
||||
Vector3 size = Vector3(10, 10, 1);
|
||||
Quad *quad = new Quad(size, true);
|
||||
quad->setMaterial(mat);
|
||||
|
||||
Vector3 pos = 0.1 * Vector3::VEC_J;
|
||||
Node *node = new Node(pos, Quaternion(-1.57, Vector3::VEC_I));
|
||||
node->attachMesh(quad);
|
||||
|
||||
Map *map = Map::getSingleton();
|
||||
map->addTerrainObject(TerrainObject(pos, size, Vector3(14, 7, 14), TerrainObject::RECT_WATERBODY, node, 0, nullptr, nullptr));
|
||||
toggleSelection(&map->getTerrainObject(map->getNumTerrainObjects() - 1), true);
|
||||
}
|
||||
|
||||
void MapEditorAppState::MapEditor::moveTerrainObject(float strength){
|
||||
Vector3 pos = selectedTerrainObject->node->getPosition();
|
||||
|
||||
switch(movementAxis){
|
||||
case MovementAxis::X_AXIS:
|
||||
pos += strength * Vector3::VEC_I;
|
||||
break;
|
||||
case MovementAxis::Y_AXIS:
|
||||
pos += strength * Vector3::VEC_J;
|
||||
break;
|
||||
case MovementAxis::Z_AXIS:
|
||||
pos += strength * Vector3::VEC_K;
|
||||
break;
|
||||
}
|
||||
|
||||
selectedTerrainObject->node->setPosition(pos);
|
||||
selectedTerrainObject->pos = pos;
|
||||
}
|
||||
|
||||
void MapEditorAppState::MapEditor::pushLandmassVerts(float strength){
|
||||
Mesh *mesh = map->getTerrainObject(0).node->getMesh(0);
|
||||
MeshData meshData = mesh->getMeshBase();
|
||||
@@ -377,6 +415,24 @@ namespace battleship{
|
||||
else
|
||||
mapEditor->setPushing(false);
|
||||
|
||||
break;
|
||||
case Bind::CREATE_WATERBODY:
|
||||
if(isPressed) mapEditor->createWaterbody();
|
||||
break;
|
||||
case Bind::MOVE_TERR_OBJ:
|
||||
if(isPressed) mapEditor->setMovingTerrainObject(true);
|
||||
break;
|
||||
case Bind::STOP_TERR_OBJ:
|
||||
if(isPressed) mapEditor->setMovingTerrainObject(false);
|
||||
break;
|
||||
case Bind::MOVE_X_AXIS:
|
||||
case Bind::MOVE_Y_AXIS:
|
||||
case Bind::MOVE_Z_AXIS:
|
||||
if(isPressed && mapEditor->isMovingTerrainObject()){
|
||||
MapEditor::MovementAxis axis = MapEditor::MovementAxis((int)bind - (int)Bind::MOVE_X_AXIS);
|
||||
mapEditor->setMovementAxis(axis);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -403,6 +459,9 @@ namespace battleship{
|
||||
case Bind::PUSH_VERTS_UP:
|
||||
case Bind::PUSH_VERTS_DOWN:
|
||||
if(mapEditor->isPushing()) mapEditor->pushLandmassVerts(strength);
|
||||
else if(mapEditor->isMovingTerrainObject() && mapEditor->getSelectedTerrainObject() != &Map::getSingleton()->getTerrainObject(0))
|
||||
mapEditor->moveTerrainObject(strength);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+15
-2
@@ -29,27 +29,40 @@ namespace battleship{
|
||||
private:
|
||||
int startId;
|
||||
};
|
||||
enum MovementAxis{
|
||||
X_AXIS,
|
||||
Y_AXIS,
|
||||
Z_AXIS
|
||||
};
|
||||
|
||||
MapEditor(std::string, vb01::Vector2);
|
||||
void updateCircleRadius(bool);
|
||||
void pushLandmassVerts(float);
|
||||
void toggleSelection(TerrainObject* ,bool);
|
||||
void castSelectionRay();
|
||||
void createWaterbody();
|
||||
void moveTerrainObject(float);
|
||||
inline TerrainObject* getSelectedTerrainObject(){return selectedTerrainObject;}
|
||||
inline float getGuiThreshold(){return guiThreshold;}
|
||||
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;}
|
||||
inline bool isMovingTerrainObject(){return movingTerrainObject;}
|
||||
inline void setMovingTerrainObject(bool m){movingTerrainObject = m;}
|
||||
inline MovementAxis getMovementAxis(){return movementAxis;}
|
||||
inline void setMovementAxis(MovementAxis m){movementAxis = m;}
|
||||
private:
|
||||
void generatePlane(vb01::Vector2);
|
||||
void prepareGui();
|
||||
void prepareTextures(std::string, bool, std::vector<vb01::Texture*>&);
|
||||
void toggleSelection(TerrainObject*, bool);
|
||||
inline vb01::Texture* getSkyTexture(int i){return skyTextures[i];}
|
||||
inline vb01::Texture* getLandmassTexture(int i){return landmassTextures[i];}
|
||||
|
||||
Map *map;
|
||||
TerrainObject *selectedTerrainObject = nullptr;
|
||||
bool pushing = false;
|
||||
MovementAxis movementAxis = X_AXIS;
|
||||
bool pushing = false, movingTerrainObject = false;
|
||||
const float MIN_RADIUS = 1, MAX_RADIUS = 100, INCREASE_RATE = 1;
|
||||
float circleRadius = MIN_RADIUS, guiThreshold = 200;
|
||||
vb01::Vector3 pushPos = vb01::Vector3::VEC_ZERO;
|
||||
|
||||
Reference in New Issue
Block a user