moving ship
This commit is contained in:
parent
c02273d29d
commit
da8946e9ef
@ -8,7 +8,7 @@ namespace ZL {
|
||||
int Environment::windowHeaderHeight = 0;
|
||||
int Environment::width = 0;
|
||||
int Environment::height = 0;
|
||||
float Environment::zoom = 6.f;
|
||||
float Environment::zoom = 20.f;
|
||||
|
||||
bool Environment::leftPressed = false;
|
||||
bool Environment::rightPressed = false;
|
||||
|
||||
61
Game.cpp
61
Game.cpp
@ -17,6 +17,8 @@ namespace ZL
|
||||
const char* CONST_ZIP_FILE = "";
|
||||
#endif
|
||||
|
||||
Matrix3f rotateShipMat = Matrix3f::Identity();
|
||||
|
||||
Vector4f generateRandomQuaternion(std::mt19937& gen)
|
||||
{
|
||||
// Ðàñïðåäåëåíèå äëÿ ãåíåðàöèè ñëó÷àéíûõ êîîðäèíàò êâàòåðíèîíà
|
||||
@ -310,6 +312,9 @@ void Game::drawShip()
|
||||
|
||||
renderer.LoadIdentity();
|
||||
renderer.TranslateMatrix({ 0,0, -1.0f * Environment::zoom });
|
||||
renderer.RotateMatrix(Environment::inverseShipMatrix);
|
||||
|
||||
renderer.RotateMatrix(rotateShipMat);
|
||||
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, spaceshipTexture->getTexID());
|
||||
@ -364,6 +369,7 @@ void Game::drawBoxes()
|
||||
renderer.shaderManager.PopShader();
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
void Game::UpdateVolumeKnob() {
|
||||
float musicVolumeBarButtonButtonCenterY = volumeBarMinY + musicVolume * (volumeBarMaxY - volumeBarMinY);
|
||||
|
||||
@ -454,7 +460,7 @@ void Game::drawScene() {
|
||||
drawShip();
|
||||
drawBoxes();
|
||||
|
||||
drawUI();
|
||||
//drawUI();
|
||||
|
||||
CheckGlError();
|
||||
}
|
||||
@ -482,6 +488,32 @@ void Game::processTickCount() {
|
||||
if (abs(diffy) > 5.0 || abs(diffx) > 5.0) //threshold
|
||||
{
|
||||
|
||||
float velocity = sqrtf(diffx * diffx + diffy * diffy);
|
||||
|
||||
Environment::shipVelocity = velocity * delta / 100;
|
||||
|
||||
Vector3f direction = { diffx, 0, -diffy };
|
||||
|
||||
Vector3f origin = { 0,0, -1 };
|
||||
|
||||
float dir_module = sqrtf(diffx * diffx + diffy * diffy);
|
||||
|
||||
float scalar = direction.v[0] * origin.v[0] + direction.v[1] * origin.v[1]+ direction.v[2] * origin.v[2];
|
||||
|
||||
float angle = acos(scalar / dir_module);
|
||||
|
||||
Vector4f quat = {
|
||||
0,
|
||||
1 * sin(angle / 2),
|
||||
0,
|
||||
cos(angle / 2)
|
||||
|
||||
};
|
||||
|
||||
rotateShipMat = QuatToMatrix(quat);
|
||||
|
||||
|
||||
/*
|
||||
float rotationPower = sqrtf(diffx * diffx + diffy * diffy);
|
||||
|
||||
//std::cout << rotationPower << std::endl;
|
||||
@ -502,14 +534,20 @@ void Game::processTickCount() {
|
||||
|
||||
Environment::shipMatrix = MultMatrixMatrix(Environment::shipMatrix, rotateMat);
|
||||
Environment::inverseShipMatrix = InverseMatrix(Environment::shipMatrix);
|
||||
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
Environment::shipVelocity = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (fabs(Environment::shipVelocity) > 0.01f)
|
||||
{
|
||||
Vector3f velocityDirection = { 0,0, -Environment::shipVelocity*delta / 1000.f };
|
||||
Vector3f velocityDirectionAdjusted = MultMatrixVector(Environment::shipMatrix, velocityDirection);
|
||||
|
||||
|
||||
Vector3f velocityDirectionAdjusted = MultMatrixVector(rotateShipMat, velocityDirection);
|
||||
|
||||
Environment::shipPosition = Environment::shipPosition + velocityDirectionAdjusted;
|
||||
}
|
||||
@ -546,12 +584,12 @@ void Game::update() {
|
||||
std::cout << mx << " " << my << '\n';
|
||||
int uiX = mx;
|
||||
int uiY = Environment::height - my;
|
||||
if (uiX >= volumeBarMinX && uiX <= volumeBarMaxX &&
|
||||
uiY >= volumeBarMinY && uiY <= volumeBarMaxY) {
|
||||
isDraggingVolume = true;
|
||||
UpdateVolumeFromMouse(mx, my);
|
||||
|
||||
if (false)
|
||||
{
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
Environment::tapDownHold = true;
|
||||
// Êîîðäèíàòû íà÷àëüíîãî íàæàòèÿ
|
||||
Environment::tapDownStartPos.v[0] = event.button.x;
|
||||
@ -561,21 +599,19 @@ void Game::update() {
|
||||
Environment::tapDownCurrentPos.v[1] = event.button.y;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if (event.type == SDL_MOUSEBUTTONUP) {
|
||||
// 2. Îáðàáîòêà îòïóñêàíèÿ êíîïêè ìûøè
|
||||
isDraggingVolume = false;
|
||||
Environment::tapDownHold = false;
|
||||
Environment::shipVelocity = 0;
|
||||
}
|
||||
else if (event.type == SDL_MOUSEMOTION) {
|
||||
// 3. Îáðàáîòêà ïåðåìåùåíèÿ ìûøè
|
||||
int mx = event.motion.x;
|
||||
int my = event.motion.y;
|
||||
|
||||
if (isDraggingVolume) {
|
||||
// Äâèãàåì ìûøü ïî ñëàéäåðó — ìåíÿåì ãðîìêîñòü è ïîçèöèþ êðóæêà
|
||||
UpdateVolumeFromMouse(mx, my);
|
||||
}
|
||||
if (Environment::tapDownHold) {
|
||||
// Îáíîâëåíèå òåêóùåé ïîçèöèè, åñëè êíîïêà óäåðæèâàåòñÿ
|
||||
Environment::tapDownCurrentPos.v[0] = event.motion.x;
|
||||
@ -596,6 +632,7 @@ void Game::update() {
|
||||
}
|
||||
else if (event.type == SDL_KEYUP)
|
||||
{
|
||||
|
||||
if (event.key.keysym.sym == SDLK_i)
|
||||
{
|
||||
Environment::shipVelocity += 1.f;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user