void Camera::Update(float deltaTime, GLFWwindow* window) { // detect wasd key presses and move camera vec3 cameraMove = vec3(); // move camera based on inputs and its forward/right/up vectors if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) cameraMove += GetForward() * moveForwardSpd; if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) cameraMove -= GetRight() * moveLeftSpd; if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) cameraMove -= GetForward() * moveBackSpd; if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) cameraMove += GetRight() * moveRightSpd; if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) cameraMove += GetUp() * moveUpSpd; if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) cameraMove -= GetUp() * moveDownSpd; if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) { glfwTerminate(); std::exit(0); } // move the camera from the movement and delta time vec3 cameraPos = GetPosition(); SetPosition(cameraPos + cameraMove*deltaTime); }
CRapiFileDialog::CRapiFileDialog( wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &position, const wxSize& size, long style ) : wxDialog( parent, id, title, position, size, style ) { // WDR: dialog function RapiFileDialogFunc for CRapiFileDialog RapiFileDialogFunc( this, TRUE ); GetBack()->SetWindowStyle(0); GetBack()->SetBitmapLabel(BackButtonFunc(0)); GetBack()->SetBitmapFocus(BackButtonFunc(1)); GetBack()->SetBitmapSelected(BackButtonFunc(0)); GetBack()->SetBitmapDisabled(BackButtonFunc(2)); GetUp()->SetWindowStyle(0); GetUp()->SetBitmapLabel(UpButtonFunc(0)); GetUp()->SetBitmapFocus(UpButtonFunc(1)); GetUp()->SetBitmapSelected(UpButtonFunc(0)); GetUp()->SetBitmapDisabled(UpButtonFunc(2)); m_pathname=wxT("\\"); m_mode=REPORTMODE; UpdateDialog(); m_bSortDirection=true; m_nSortColumn=0; SetSize(wxSize(400,400)); }
bool physGrapple(float lx,float ly,float lz){ bool ret = false; flip = 0; dir = glm::normalize(glm::vec3(-lx,ly,-lz)); //printf("grapple in dir %f %f %f\n",dir.x,dir.y,dir.z); //printf("looks at is %f %f %f\n",lookAt.x,lookAt.y,lookAt.z); /* btCollisionWorld::ClosestRayResultCallback RayCallback(btVector3(lookAt.x+.0*dir.x,lookAt.y-.0*dir.y,lookAt.z+.0*dir.z), btVector3(lookAt.x+50*dir.x,lookAt.y-50*dir.y,lookAt.z+50*dir.z)); dynamicsWorld->rayTest(btVector3(lookAt.x+.0*dir.x,lookAt.y-.0*dir.y,lookAt.z+.0*dir.z), btVector3(lookAt.x+50*dir.x,lookAt.y-50*dir.y,lookAt.z+50*dir.z), RayCallback); */ ////////////////////////////// glm:: vec3 ggaze = GetLookAt() - GetEye(); glm::vec3 gw = ggaze/magnitude(ggaze); gw = glm::vec3(-1.0 * gw.x, -1.0 * gw.y, -1.0 * gw.z); glm::vec3 gu = glm::cross(GetUp(), gw)/magnitude(glm::cross(GetUp(), gw)); gu *= 2; lookAt += glm::vec3(gu.x, 0, gu.z); /////////////////////////////// btCollisionWorld::ClosestRayResultCallback RayCallback(btVector3(lookAt.x+1.6*dir.x,lookAt.y-1.6*dir.y,lookAt.z+1.6*dir.z), btVector3(lookAt.x+75*dir.x,lookAt.y-75*dir.y,lookAt.z+75*dir.z)); dynamicsWorld->rayTest(btVector3(lookAt.x+1.6*dir.x,lookAt.y-1.6*dir.y,lookAt.z+1.6*dir.z), btVector3(lookAt.x+75*dir.x,lookAt.y-75*dir.y,lookAt.z+75*dir.z), RayCallback); //player->setLinearVelocity(btVector3(dir.x*50,dir.y*50,dir.z*50)); btTransform plPos; player->getMotionState()->getWorldTransform(plPos); if(RayCallback.hasHit()&& !playerGrappleActive && RayCallback.m_hitPointWorld.distance(plPos.getOrigin())>1.8) { playerJump=0; //End = RayCallback.m_hitPointWorld; //Normal = RayCallback.m_hitNormalWorld; //printf("hit!\n"); btVector3 go=RayCallback.m_hitNormalWorld*-5+player->getLinearVelocity(); if (go.length()>10)(go/go.length())*10; //player->setLinearVelocity(go); //printf("%f %f %f on hit norm",RayCallback.m_hitNormalWorld.getX(),RayCallback.m_hitNormalWorld.getY(),RayCallback.m_hitNormalWorld.getZ()); tmp = RayCallback.m_hitPointWorld; // Do some clever stuff here if(tmp.getY()>1){ playerGrappleActive =1; //SFX HERE //Sound s = Sound(); //s.playSFX("../Assets/Sounds/HookShot.mp3"); //printf("%f %f %f - player loc; %f %f %f grapple loc\n", physGetPlayerX(), physGetPlayerY(), physGetPlayerZ(), grapplingHookLocation().x, grapplingHookLocation().y, grapplingHookLocation().z); //printf("%f %f %f grapple sfx distance\n", abs(grapplingHookLocation().x - physGetPlayerX()), abs(grapplingHookLocation().y - physGetPlayerY()), abs(grapplingHookLocation().z - physGetPlayerZ())); musicPlayer.BGM.play3DSFX("../Assets/Sounds/HookShot.mp3", physGetPlayerX(), physGetPlayerY(), physGetPlayerZ(), grapplingHookLocation().x, grapplingHookLocation().y, grapplingHookLocation().z); ret = true; } } lookAt -= glm::vec3(gu.x, 0, gu.z); return ret; }
void glfwEditGetCursorPos(GLFWwindow *window, double xpos, double ypos) { //printf("%f %f\n", xpos, g_height - ypos); lastCurPos = glm::vec2(xpos, g_height - ypos - 1); //If in GUI Selection, disable pitch and yaw if(eKeysPressed['G'] == 0) { if(xpos > g_width || xpos < 0 || ypos < 0 || ypos > g_height) { return; } //Get rid of if unneeded egaze = GetLookAt() - GetEye(); ew = glm::vec3(-1.0 * ew.x, -1.0 * ew.y, -1.0 * ew.z); ew = glm::normalize(ew); eu = glm::cross(GetUp(), ew)/magnitude(glm::cross(GetUp(), ew)); eu = glm::normalize(eu); eendX = xpos; eendY = g_height-ypos-1; float diff; //Calculate change in X if(estartX < eendX) { diff = eendX - estartX; ebeta = incrementYaw((diff * M_PI)/g_width); } else if(estartX > eendX){ diff = estartX - eendX; ebeta = incrementYaw((-diff * M_PI)/g_width); } //Calculate change in Y if(eendY > estartY && ealpha <= 0.98) { diff = eendY - estartY; ealpha = incrementPitch((diff * M_PI)/g_width); } else if(eendY < estartY && ealpha >= -0.98) { diff = estartY - eendY; ealpha = incrementPitch(-(diff * M_PI)/g_width); } estartX = g_width/2.0;// = endX; estartY = g_height/2.0-1;// endY; } }
void Orientation::LookAt(glm::vec3 p_direction, glm::vec3 p_upVector) { m_orientation = quat(1.0f, 0.0f, 0.0f, 0.0f); vec3 direction = normalize(p_direction); vec3 up = normalize(p_upVector); vec3 arbitraryVector = vec3(0.0f, 0.0f, 1.0f); vec3 axis = glm::cross(direction, arbitraryVector); if(glm::dot(axis, axis) == 0.0f) { axis = vec3(0.0f, 1.0f, 0.0f); } float angle = glm::degrees(glm::acos(glm::dot(direction, vec3(0.0f, 0.0f, 1.0f)))); vec3 third = glm::cross(axis, vec3(0.0f, 0.0f, 1.0f)); if (glm::dot(third, direction) < 0) { angle = -angle; } Rotate(angle, axis); vec3 targetRight = normalize(glm::cross(direction, up)); vec3 myRight = normalize(glm::cross(direction, GetUp())); float ledot = glm::dot(targetRight, myRight); float tacos = glm::acos(glm::min(ledot, 1.0f)); float angle2 = glm::degrees(tacos); vec3 third2 = glm::cross(direction, myRight); if (glm::dot(third2, targetRight) < 0) { angle2 = -angle2; } Roll(angle2); }
void Camera::UpdateMatrix() { int width = Screen::GetWidth(); int height = Screen::GetHeight(); auto transform = GetTransform(); m_view_matrix = Matrix4x4::LookTo( transform->GetPosition(), transform->GetForward(), transform->GetUp()); if(!m_orthographic) { m_projection_matrix = Matrix4x4::Perspective(m_field_of_view, width / (float) height, m_near_clip_plane, m_far_clip_plane); } else { float top = m_orthographic_size; float bottom = -m_orthographic_size; float plane_h = m_orthographic_size * 2; float plane_w = plane_h * (width * m_rect.width) / (height * m_rect.height); m_projection_matrix = Matrix4x4::Ortho(-plane_w/2, plane_w/2, bottom, top, m_near_clip_plane, m_far_clip_plane); } m_view_projection_matrix = m_projection_matrix * m_view_matrix; }
//-------------------------------------------------------------------------------------------------------------------------------------- void EditCamera::Rotate( float xd, float yd ) { Quaternionf q; q.RotateAxis( m_VerticalAixs,yd * m_RotateSpeed ); Matrix44f mat = Math::Transformation<float>(NULL, NULL, NULL, &m_Target, &q, NULL); vector3f pos = Math::Transform_coord(this->GetPosition(), mat); q.RotateAxis( vector3f(0.0f, GetUp().Dot( vector3f(0, 1, 0)) < 0 ? -1.0f : 1.0f, 0.0f), xd * m_RotateSpeed ); mat = Math::Transformation<float>(NULL, NULL, NULL, &m_Target, &q, NULL); pos = Math::Transform_coord(pos, mat); m_VerticalAixs = Math::Transform_Quat(m_VerticalAixs, q); vector3f dir; if (m_isReverse) { dir = pos - m_Target; } else { dir = m_Target - pos; } dir.NormalizeSelf(); vector3f up = dir.Cross(m_VerticalAixs); this->_LookAt(pos, pos + dir, up); }
void CFPSCameraController::UpdateCameraValues(CCamera *Camera) const { Vect3f l_Direction = GetDirection(); Camera->SetPosition(m_Position); Camera->SetLookAt(m_Position + l_Direction); Camera->SetUp(GetUp()); Camera->SetMatrixs(); }
void CGameObject::MoveUp(float fDistance) { //게임 객체를 로컬 y-축 방향으로 이동한다. D3DXVECTOR3 d3dxvPosition = GetPosition(); D3DXVECTOR3 d3dxvUp = GetUp(); d3dxvPosition += fDistance * d3dxvUp; CGameObject::SetPosition(d3dxvPosition); }
void Camera::MoveDown(float speed) { speed *= TimeManager::Instance().DeltaTime; vec3 upVector = GetUp(); // Move our camera position up or down along the right vector Position.y -= upVector.x * speed; // Add our acceleration to our position's Y }
void CSphericalCameraController::SetCamera(CCamera *Camera) const { Vect3f l_Direction = GetDirection(); Camera->SetLookAt(m_Position); Camera->SetPosition(m_Position-l_Direction); Camera->SetUp(GetUp()); Camera->SetMatrixs(); }
//-------------------------------------------------------------------------------------------------------------------------------------- void FPSCamera::Rotate( float xd, float yd ) { Quaternionf q; q.RotateAxis( m_VerticalAixs ,yd * m_RotateSpeed ); vector3f dir = Math::Transform_Quat( this->GetForward() , q); q.RotateAxis( vector3f(0.0f, GetUp().Dot( vector3f(0, 1, 0)) < 0 ? -1.0f : 1.0f, 0.0f) , xd * m_RotateSpeed ); m_VerticalAixs = Math::Transform_Quat(m_VerticalAixs, q); dir = Math::Transform_Quat( dir , q); vector3f up = dir.Cross( m_VerticalAixs ); this->_LookAt(this->GetPosition(), this->GetPosition() + dir, up); }
void UpdateMainCamera(Camera* main_camera, World* world) { auto player = world->player_component.begin()->entity; auto transform_component = &world->transform_component; main_camera->set_position(transform_component->WorldPosition(player)); main_camera->set_facing( transform_component->WorldOrientation(player).Inverse() * mathfu::kAxisY3f); auto player_data = world->entity_manager.GetComponentData<PlayerData>(player); auto raft_orientation = transform_component->WorldOrientation( world->entity_manager.GetComponent<ServicesComponent>()->raft_entity()); main_camera->set_up(raft_orientation.Inverse() * player_data->GetUp()); }
int grappleInRange(float lx,float ly,float lz){ //glm::vec3 tempLookAt; dir = glm::normalize(glm::vec3(-lx,ly,-lz)); glm:: vec3 ggaze = GetLookAt() - GetEye(); glm::vec3 gw = ggaze/magnitude(ggaze); gw = glm::vec3(-1.0 * gw.x, -1.0 * gw.y, -1.0 * gw.z); glm::vec3 gu = glm::cross(GetUp(), gw)/magnitude(glm::cross(GetUp(), gw)); gu *= 2; lookAt += glm::vec3(gu.x, 0, gu.z); btCollisionWorld::ClosestRayResultCallback RayCallback(btVector3(lookAt.x+1.6*dir.x,lookAt.y-1.6*dir.y,lookAt.z+1.6*dir.z), btVector3(lookAt.x+75*dir.x,lookAt.y-75*dir.y,lookAt.z+75*dir.z)); dynamicsWorld->rayTest(btVector3(lookAt.x+1.6*dir.x,lookAt.y-1.6*dir.y,lookAt.z+1.6*dir.z), btVector3(lookAt.x+75*dir.x,lookAt.y-75*dir.y,lookAt.z+75*dir.z), RayCallback); lookAt -= glm::vec3(gu.x, 0, gu.z); // int ret = //inRange(50,75,glm::lookAt(playerPoss(),glm::vec3(tempLookAt.x+75*dir.x,tempLookAt.y+75*dir.y,tempLookAt.z+75*dir.z),glm::vec3(0,1,0))); //printf("grapple is %d range\n",RayCallback.hasHit()); //if(RayCallback.hasHit()) printf("%f %f %f",RayCallback.m_hitPointWorld.getX(),RayCallback.m_hitPointWorld.getY(),RayCallback.m_hitPointWorld.getZ()); return RayCallback.hasHit(); }
void CSphericalCameraController::SetCamera(CCamera *Camera) const { Vect3f l_Direction = GetDirection(); Camera->SetFOV(DEG2RAD(50.0f)); Camera->SetAspectRatio(16.0f/9.0f); Camera->SetLookAt(m_Position); Camera->SetPosition(m_Position-l_Direction); Camera->SetUp(GetUp()); Camera->SetMatrixs(); }
void CObject::MoveRelative(const float fx, const float fy, const float fz) { D3DXVECTOR3 d3dxvPosition = *GetPosition(); D3DXVECTOR3 d3dxvRight = *GetRight(); D3DXVECTOR3 d3dxvUp = *GetUp(); D3DXVECTOR3 d3dxvLookAt = *GetLookAt(); d3dxvPosition += fx * d3dxvRight; d3dxvPosition += fy * d3dxvUp; d3dxvPosition += fz * d3dxvLookAt; MoveAbsolute(&d3dxvPosition); }
void PhysicsComponent::VUpdate(int deltaMs) { // get the transform component shared_ptr<TransformComponent> pTransformComponent = MakeStrongPtr(m_pOwner->GetComponent<TransformComponent>(TransformComponent::g_Name)); if (!pTransformComponent) { LOG_ERROR("No transform component!"); return; } // get the direction the object is facing glm::mat4 transform = pTransformComponent->GetTransform(); if (m_acceleration != 0) { // calculate the acceleration this frame float accelerationToApplyThisFrame = m_acceleration / 1000.f * (float)deltaMs; // Get the current velocity vector and convert to a scalar. The velocity vector is a combination of // the direction this actor is going in and the speed of the actor. The scalar is just the speed // component. glm::vec3 velocity(m_pGamePhysics->VGetVelocity(m_pOwner->GetId())); float velocityScalar = glm::length(velocity); glm::vec3 direction(GetDirection(transform)); m_pGamePhysics->VApplyForce(direction, accelerationToApplyThisFrame, m_pOwner->GetId()); // logging // [rez] Comment this back in if you want to debug the physics thrust & rotation stuff. It spams quite // a bit of info the output window so I'm commenting it out for now. /* GCC_LOG("Actor", "Acceleration: " + ToStr(accelerationToApplyThisFrame) + "; velocityScalar: " + ToStr(velocityScalar) + \ "; direction: " + ToStr(direction) + "; direction.Length(): " + ToStr(direction.Length()) + \ "; velocity: " + ToStr(velocity) + "; velocity.Length(): " + ToStr(velocity.Length())); */ } if (m_angularAcceleration != 0) { // calculate the acceleration this frame float angularAccelerationToApplyThisFrame = m_angularAcceleration / 1000.f * (float)deltaMs; m_pGamePhysics->VApplyTorque(GetUp(transform), angularAccelerationToApplyThisFrame, m_pOwner->GetId()); // logging // [rez] Comment this back in if you want to debug the physics thrust & rotation stuff. It spams quite // a bit of info the output window so I'm commenting it out for now. //GCC_LOG("Actor", "Angular Acceleration: " + ToStr(angularAccelerationToApplyThisFrame) ); } }
void CObject::MoveRelative(const D3DXVECTOR3 *d3dxVec) { D3DXVECTOR3 d3dxvPosition = *GetPosition(); D3DXVECTOR3 d3dxvRight = *GetRight(); D3DXVECTOR3 d3dxvUp = *GetUp(); D3DXVECTOR3 d3dxvLookAt = *GetLookAt(); d3dxvPosition += d3dxVec->x * d3dxvRight; d3dxvPosition += d3dxVec->y * d3dxvUp; d3dxvPosition += d3dxVec->z * d3dxvLookAt; MoveAbsolute(&d3dxvPosition); }
void FreeCamera::Update(const tt::GameContext& context) { auto pInputService = MyServiceLocator::GetInstance()->GetService<IInputService>(); auto pTransform = GetComponent<TransformComponent>(); if(pInputService->IsActionTriggered(InputActionId::CameraMoveForward)) pTransform->Translate(pTransform->GetForward() * m_MovementSpeed, true); if(pInputService->IsActionTriggered(InputActionId::CameraMoveBack)) pTransform->Translate(pTransform->GetBackward() * m_MovementSpeed, true); if(pInputService->IsActionTriggered(InputActionId::CameraMoveLeft)) pTransform->Translate(pTransform->GetLeft() * m_MovementSpeed, true); if(pInputService->IsActionTriggered(InputActionId::CameraMoveRight)) pTransform->Translate(pTransform->GetRight() * m_MovementSpeed, true); if(pInputService->IsActionTriggered(InputActionId::CameraMoveUp)) pTransform->Translate(pTransform->GetUp() * m_MovementSpeed, true); if(pInputService->IsActionTriggered(InputActionId::CameraMoveDown)) pTransform->Translate(pTransform->GetDown() * m_MovementSpeed, true); if(!pInputService->IsActionTriggered(InputActionId::CameraUnlockRotation)) return; auto mouseMovement = pInputService->GetMouseMovement(); mouseMovement *= m_RotationSpeed * context.GameTimer.GetElapsedSeconds(); m_Yaw += mouseMovement.x; m_Pitch += mouseMovement.y; tt::Quaternion yawQuat(tt::Vector3::j, m_Yaw); tt::Vector3 rotatedRight = tt::Vector3::i.TransformPoint(yawQuat); tt::Quaternion pitchQuat(rotatedRight, m_Pitch); pTransform->Rotate(yawQuat * pitchQuat); }
// クイックアーツ bool Thief::QuickArts(void) { static int time = 0; if ( !initflag ) { sound->PlaySE( SE::KAITO_QUICK ); initflag = true; } Move(); // 行列から情報取得 Vector3 up = GetUp(); Vector3 right = GetRight(); Vector3 p_pos = GetPos(); SetMove(Vector3(0.0f, move.y, 0.0f)); SetMotion(THIEF::MOTION_DATA::QUICKARTS); //if (obj->GetFrame() >= 237) obj->SetMotion(237); // 情報設定 Vector3 vec[3] = { up * 5.0f + right * 3.0f, up * 5.0f, up * 5.0f + right * -3.0f }; p_pos.y += 3.0f; float bulletSpeed = 0.5f; int playerNum = GetPlayerNum(); { //撃った時に動きが一度止まるパターン // //モーションアトデナオス(ちょうどいい感じのフレームが来たら弾発射) //if (time == 0 /* obj->GetFrame() == ○○ */ ) //{ // for (int i = 0; i < 3; i++) // { // m_BulletManager->Set(BULLET_TYPE::THIEF_01 , new ThiefBullet01, p_pos, vec[i], bulletSpeed, playerNum); // } //} //time++; ////モーションアトデナオス(終わりのモーションが来たら終了) //if (obj->GetFrame() == 237) //{ // time = 0; // return true; //} } { //撃った時に動きが止まらないパターン for (int i = 0; i < 3; i++) { m_BulletManager->Set(BULLET_TYPE::THIEF_01 , new ThiefBullet01, p_pos, vec[i], bulletSpeed, playerNum); } attackInfo.Interval = 60; initflag = false; return true; } return false; }
void Camera::Yaw(float angle) { glm::quat q = glm::angleAxis(angle, GetUp()) * GetFrame()->GetRotation(); GetFrame()->SetRotation(q); }
void CFpsCamera::UpdateCamera() { float elapsed_time = _engine.elapsed_time; if (m_animate) { //Muevo El ojo de la camara hacia el punto destino m_deltaAnimTime += elapsed_time; float deltaMove = saturate(m_deltaAnimTime / m_animTime); m_lookFrom = m_startPos*(1 - deltaMove) + m_endPos*deltaMove; m_lookAt = m_startTarget*(1 - deltaMove) + m_endTarget*deltaMove; if (m_deltaAnimTime >= m_animTime) { m_animate = false; m_lookFrom = m_endPos; m_lookAt = m_endTarget; m_deltaAnimTime = 0; } } //Obtener variacion XY del mouse Vector3 dir = GetViewDir(); Vector3 ndir = dir*-1; float beta = atan2(ndir.Y, sqrt(ndir.X*ndir.X + ndir.Z*ndir.Z))*FastMath::RADIANS_TO_DEGREES; float rotX = 0; float rotY = 0; if (!m_cameraBlocked) { Vector3 dm = InputManager::m_delta_mouse; if (InputManager::IsLButtonDown() || m_captureMouse) { //roto solo si el boton del mouse esta apretado rotX = dm.X * m_rotationSpeed; rotY = dm.Y * m_rotationSpeed; if (rotY + beta > 90 - 1) { rotY = 90 - beta - 1; } if (rotY + beta < -90 + 1) { rotY = -90 - beta + 1; } } if (dm.Z != 0) { //avanzo y retrocedo con la rueda del mouse float distancia = (m_lookAt - m_lookFrom).Length(); float deltamove = dm.Z * m_wheelSpeed; if (distancia - deltamove < 1) deltamove = distancia - 1; m_lookFrom += dir*deltamove; } if (InputManager::IsPressed(DInputKey::Key_C)) { m_endPos = m_lookFrom; m_endTarget = m_lookAt; } if (InputManager::IsPressed(DInputKey::Key_P)) { AnimateTo(m_endPos, m_endTarget); } if (InputManager::IsPressed(DInputKey::Key_M)) { m_captureMouse = !m_captureMouse; } if (m_captureMouse) { //TODO: Falta convertir el la posicion en absoluta, ahora esta relativa a la camara y no queda centrada SetCursorPos(_engine.screenWidth / 2, _engine.screenHeight / 2); } if (InputManager::IsWheelButtonDown()) { //Hace el pan del mouse Vector3 delta_pan = GetLeft() * (dm.X * m_panSpeed); delta_pan += GetUp() * (dm.Y * m_panSpeed); m_lookAt += delta_pan; m_lookFrom += delta_pan; } if (InputManager::IsDown(DInputKey::Key_W)) { Vector3 move = dir*m_moveSpeed*elapsed_time; //anulo el movimiento en Y move.Y = 0; m_lookAt += move; m_lookFrom += move; } if (InputManager::IsDown(DInputKey::Key_S)) { Vector3 move = dir*-m_moveSpeed*elapsed_time; //anulo el movimiento en Y move.Y = 0; m_lookAt += move; m_lookFrom += move; } if (InputManager::IsDown(DInputKey::Key_A)) { Vector3 move = GetLeft()*m_moveSpeed*elapsed_time; //anulo el movimiento en Y move.Y = 0; m_lookAt += move; m_lookFrom += move; } if (InputManager::IsDown(DInputKey::Key_D)) { Vector3 move = GetLeft()*-m_moveSpeed*elapsed_time; //anulo el movimiento en Y move.Y = 0; m_lookAt += move; m_lookFrom += move; } if (InputManager::IsDown(DInputKey::Key_Space)) { Vector3 move = UP_VECTOR*m_jumpSpeed*elapsed_time; m_lookAt += move; m_lookFrom += move; } if (InputManager::IsDown(DInputKey::Key_LeftControl) || InputManager::IsDown(DInputKey::Key_RightControl)) { Vector3 move = UP_VECTOR*-m_jumpSpeed*elapsed_time; m_lookAt += move; m_lookFrom += move; } } //creo un vector perpendicular a la direccion de la camara y la direccion arriba para rotar sonbre ese eje. if (rotX != 0 || rotY != 0) { Matrix rotMat = Matrix::SRotationAxis(GetLeft(), rotY*FastMath::DEGREES_TO_RADIANS) * Matrix::SRotationAxis(UP_VECTOR, -rotX*FastMath::DEGREES_TO_RADIANS); Vector3 dif = m_lookFrom - m_lookAt; m_lookFrom = m_lookAt + Vector3::TransformCoordinate(dif, rotMat).XYZ(); } m_viewMatrix.LookAtLH(m_lookAt, m_lookFrom, UP_VECTOR); }
void Player::FireWeapon() { SPADES_MARK_FUNCTION(); Vector3 muzzle = GetEye(); muzzle += GetFront() * 0.01f;/* muzzle += GetRight() * 0.4f; muzzle -= GetUp() * 0.3f;*/ Vector3 right = GetRight(); Vector3 up = GetUp(); int pellets = weapon->GetPelletSize(); float spread = weapon->GetSpread(); GameMap *map = world->GetMap(); // pyspades takes destroying more than one block as a // speed hack (shotgun does this) bool blockDestroyed = false; Vector3 dir2 = GetFront(); for(int i =0 ; i < pellets; i++){ // AoS 0.75's way (dir2 shouldn't be normalized!) dir2.x += (GetRandom() * 2.f - 1.f) * spread; dir2.y += (GetRandom() * 2.f - 1.f) * spread; dir2.z += (GetRandom() * 2.f - 1.f) * spread; Vector3 dir = dir2.Normalize(); // first do map raycast GameMap::RayCastResult mapResult; mapResult = map->CastRay2(muzzle, dir, 500); Player *hitPlayer = NULL; float hitPlayerDistance = 0.f; int hitFlag = 0; for(int i = 0; i < world->GetNumPlayerSlots(); i++){ Player *other = world->GetPlayer(i); if(other == this || other == NULL) continue; if(other == this || !other->IsAlive() || other->GetTeamId() >= 2) continue; if(!other->RayCastApprox(muzzle, dir)) continue; HitBoxes hb = other->GetHitBoxes(); Vector3 hitPos; if(hb.head.RayCast(muzzle, dir, &hitPos)) { float dist = (hitPos - muzzle).GetLength(); if(hitPlayer == NULL || dist < hitPlayerDistance){ if(hitPlayer != other){ hitPlayer = other; hitFlag = 0; } hitPlayerDistance = dist; hitFlag = 1; // head } } if(hb.torso.RayCast(muzzle, dir, &hitPos)) { float dist = (hitPos - muzzle).GetLength(); if(hitPlayer == NULL || dist < hitPlayerDistance){ if(hitPlayer != other){ hitPlayer = other; hitFlag = 0; } hitPlayerDistance = dist; hitFlag = 2; // torso } } for(int j = 0; j < 3 ;j++){ if(hb.limbs[j].RayCast(muzzle, dir, &hitPos)) { float dist = (hitPos - muzzle).GetLength(); if(hitPlayer == NULL || dist < hitPlayerDistance){ if(hitPlayer != other){ hitPlayer = other; hitFlag = 0; } hitPlayerDistance = dist; if(j == 2) hitFlag = 8; // arms else hitFlag = 4; // leg } } } } Vector3 finalHitPos; finalHitPos = muzzle + dir * 128.f; if(mapResult.hit && (mapResult.hitPos - muzzle).GetLength() < 128.f && (hitPlayer == NULL || (mapResult.hitPos - muzzle).GetLength() < hitPlayerDistance)){ IntVector3 outBlockCoord = mapResult.hitBlock; // TODO: set correct ray distance // FIXME: why ray casting twice? finalHitPos = mapResult.hitPos; if(outBlockCoord.x >= 0 && outBlockCoord.y >= 0 && outBlockCoord.z >= 0 && outBlockCoord.x < map->Width() && outBlockCoord.y < map->Height() && outBlockCoord.z < map->Depth()){ if(outBlockCoord.z < 62){ int x = outBlockCoord.x; int y = outBlockCoord.y; int z = outBlockCoord.z; SPAssert(map->IsSolid(x, y, z)); Vector3 blockF = {x + .5f, y + .5f, z + .5f}; float distance = (blockF - muzzle).GetLength(); uint32_t color = map->GetColor(x, y, z); int health = color >> 24; health -= weapon->GetDamage(HitTypeBlock, distance); if(health <= 0 && !blockDestroyed){ health = 0; blockDestroyed = true; //send destroy cmd if(world->GetListener() && world->GetLocalPlayer() == this) world->GetListener()->LocalPlayerBlockAction (outBlockCoord, BlockActionTool); } color = (color & 0xffffff) | ((uint32_t)health << 24); if(map->IsSolid(x, y, z)) map->Set(x, y, z, true, color); if(world->GetListener()) world->GetListener()->BulletHitBlock(mapResult.hitPos, mapResult.hitBlock, mapResult.normal); } } }else if(hitPlayer != NULL){
void CRapiFileDialog::UpdateDialog(void) { m_pathname.MakeAbsolute(); m_currentpaths.clear(); m_currentsizes.clear(); m_currentdates.clear(); GetFileList()->ClearAll(); if(m_mode==REPORTMODE) { GetFileList()->SetWindowStyle(wxLC_REPORT|wxLC_SINGLE_SEL); GetFileList()->InsertColumn(0,wxT("Name"),wxLIST_FORMAT_LEFT,160); GetFileList()->InsertColumn(1,wxT("Size")); GetFileList()->InsertColumn(2,wxT("Date")); } else if(m_mode==ICONMODE) { GetFileList()->SetWindowStyle(wxLC_ICON|wxLC_SINGLE_SEL); } else if(m_mode==SMALLICONMODE) { GetFileList()->SetWindowStyle(wxLC_SMALL_ICON|wxLC_SINGLE_SEL); } else if(m_mode==LISTMODE) { GetFileList()->SetWindowStyle(wxLC_LIST|wxLC_SINGLE_SEL); } // Ensure we have a file type selection if(GetFilesOfType()->GetCount()==0) { AddFileType(wxT("All Files (*.*)"),wxT("*")); } if(GetFilesOfType()->GetSelection()==wxNOT_FOUND) { GetFilesOfType()->SetSelection(0); } // Get item names DWORD dwFound; LPCE_FIND_DATA pFoundDataArray=NULL; if(!g_RAPI.CeFindAllFiles(m_pathname.GetPath(true)+wxT("*"),FAF_ATTRIBUTES|FAF_SIZE_HIGH|FAF_SIZE_LOW|FAF_NAME|FAF_LASTWRITE_TIME,&dwFound,&pFoundDataArray)) { GetFileList()->Enable(false); } else { GetFileList()->Enable(true); } if(pFoundDataArray) { wxString strMatch=m_filetypes[GetFilesOfType()->GetSelection()]; // Fill in file list for(DWORD dw=0;dw<dwFound;dw++) { if(pFoundDataArray[dw].dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // It's a folder wxFileName dname(m_pathname.GetPath(true)+pFoundDataArray[dw].cFileName,wxT("")); m_currentpaths.push_back(dname.GetPath(true)); m_currentsizes.push_back(0); m_currentdates.push_back(pFoundDataArray[dw].ftLastWriteTime); } else { // It's a file wxFileName dname(m_pathname.GetPath(true)+pFoundDataArray[dw].cFileName); if(dname.GetFullName().Lower().Matches(strMatch.Lower())) { m_currentpaths.push_back(dname.GetFullPath()); m_currentsizes.push_back(((wxUint64)pFoundDataArray[dw].nFileSizeLow)|(((wxUint64)pFoundDataArray[dw].nFileSizeHigh)<<32)); m_currentdates.push_back(pFoundDataArray[dw].ftLastWriteTime); } } } g_RAPI.CeRapiFreeBuffer(pFoundDataArray); } wxImageList *pilSmall=new wxImageList(16,16,true,1); pilSmall->Add(RapiFileDialogBitmapsFunc(0),wxColour(255,0,255)); pilSmall->Add(RapiFileDialogBitmapsFunc(1),wxColour(255,0,255)); pilSmall->Add(RapiFileDialogBitmapsFunc(2),wxColour(255,0,255)); wxImageList *pilBig=new wxImageList(32,32,true,1); pilBig->Add(RapiFileDialogBitmapsLgFunc(0),wxColour(255,0,255)); pilBig->Add(RapiFileDialogBitmapsLgFunc(1),wxColour(255,0,255)); pilBig->Add(RapiFileDialogBitmapsLgFunc(2),wxColour(255,0,255)); size_t i=0,count=m_currentpaths.size(); for(i=0;i<count;i++) { if(m_currentpaths[i].Last()==wxT('\\')) { GetFileList()->InsertItem((long)i,wxFileName(m_currentpaths[i],wxT("")).GetDirs().Last(),0); GetFileList()->SetItemImage((long)i,0,1); if(m_mode==REPORTMODE) { // GetFileList()->SetItem((long)i,1,(const TCHAR *)GetSizeString(m_currentsizes[i])); GetFileList()->SetItem((long)i,2,(const TCHAR *)GetDateString(m_currentdates[i])); } } else { GetFileList()->InsertItem((long)i,wxFileName(m_currentpaths[i]).GetFullName(),2); if(m_mode==REPORTMODE) { GetFileList()->SetItem((long)i,1,(const TCHAR *)GetSizeString(m_currentsizes[i])); GetFileList()->SetItem((long)i,2,(const TCHAR *)GetDateString(m_currentdates[i])); } } if(m_currentpaths[i].Last()==m_pathname.GetFullPath()) { GetFileList()->SetItemState((long)i,wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED,wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED); } GetFileList()->SetItemData((long)i,(long)i); } GetFileList()->AssignImageList(pilSmall,wxIMAGE_LIST_SMALL); GetFileList()->AssignImageList(pilBig,wxIMAGE_LIST_NORMAL); // Fill in Look-In Choice Box GetLookIn()->Clear(); count=m_pathname.GetDirCount(); wxString dir=wxT("\\"); GetLookIn()->Append(dir); for(i=0;i<count;i++) { dir=wxT("\\"); for(size_t j=0;j<=i;j++) { dir+=m_pathname.GetDirs()[j]; if(j!=i) { dir+=wxT("\\"); } } GetLookIn()->Append(dir); } GetLookIn()->SetSelection((int)count); GetUp()->Enable(count>0); GetBack()->Enable(m_history.size()>1); GetOk()->Enable(m_pathname.GetFullPath().Last()!=wxT('\\')); GetFileList()->SortItems(ListCompareFunction,(long)this); }
AglVector3 AglMatrix::GetDown() const { return -GetUp(); }
void CBody::AdjustYaw(float radianAngle) { AdjustAxisAngle(GetUp(), radianAngle); }
void CBody::AdjustYawVelocity(float radianAngle) { AdjustAxisVelocity(GetUp(), radianAngle); }
void Pong(void) { int i; int closest_index = -1; int closest_value = 500; int wall_bounce = 0; unsigned int computerScore = 0; unsigned int playerScore = 0; unsigned int ball_speed = PONG_BALL_SPEED; struct Solid userPaddle; struct Solid computerPaddle; struct Solid balls[NUM_PONGBALLS]; //By default, all pong balls are disabled. for (i = 0; i < NUM_PONGBALLS; i++) { balls[i].health = 0; } ILI9340_setBgColor(COLOR_YELLOW); printf_setFont_properties(2, 0, COLOR_BLUE, COLOR_YELLOW); printf_setFont_location(10, 300); _printf("Player %u", playerScore); printf_setFont_location(10, 150); _printf("Computer %u", computerScore); build_solid(&userPaddle, 100, 290, 30, 4, COLOR_BLUE); build_solid(&computerPaddle, 100, 30, 30, 4, COLOR_RED); build_moving_solid(&balls[0], 100, 100, 7, 7, COLOR_GREEN, SOLID_AUTOUP | SOLID_AUTOLEFT, 0x0f, 27, 4); build_moving_solid(&balls[1], 100, 200, 7, 7, COLOR_BLUE, SOLID_AUTODOWN | SOLID_AUTORIGHT, 0x0f, 27, 4); build_moving_solid(&balls[2], 150, 200, 7, 7, COLOR_RED, SOLID_AUTOUP | SOLID_AUTORIGHT, 0x0f, 27, 4); build_moving_solid(&balls[3], 200, 200, 7, 7, COLOR_CYAN, SOLID_AUTODOWN | SOLID_AUTOLEFT, 0x0f, 27, 4); StartTimer(0, PONG_PADDLE_SPEED); StartTimer(1, ball_speed); StartTimer(2, CHECK_PONG_PAUSE); for (;;) { if (CheckTimer(0)) { if (GetUp()) { solid_fastMoveUp(&userPaddle, GetJoystickYMag() + 5, 0); } else if (GetDown()) { solid_fastMoveDown(&userPaddle, GetJoystickYMag() + 5, 0); } StartTimer(0, PONG_PADDLE_SPEED); } if (CheckTimer(1)) { //By default we support multiple pong balls for (i = 0; i < NUM_PONGBALLS; i++) { if (solid_checkIntersectionPongPaddle(&balls[i], &userPaddle) || solid_checkIntersectionPongPaddle(&balls[i], &computerPaddle)) { playSound(0); if (ball_speed > 20) { ball_speed--; } } wall_bounce = solid_autoMove(&balls[i]); //Hit the left of the screen if (wall_bounce == 3) { display_solid(&balls[i], 1); printf_setFont_location(10, 44); computerScore++; _printf("%u", computerScore); build_moving_solid(&balls[i], userPaddle.x + 4, 280, 7, 7, balls[i].color, SOLID_AUTOUP | SOLID_AUTORIGHT, 0x0f, 27, 4); } else if (wall_bounce == 4) { display_solid(&balls[i], 1); printf_setFont_location(10, 217); playerScore++; _printf("%u", playerScore); build_moving_solid(&balls[i], computerPaddle.x + 4, 40, 7, 7, balls[i].color, SOLID_AUTOUP | SOLID_AUTOLEFT, 0x0f, 27, 4); } if (wall_bounce != 0) { playSound(0); } if (balls[i].health > 0 && ((balls[i].autoMove & SOLID_AUTORIGHT) || (balls[i].autoMove & SOLID_FASTRIGHT))) { if (balls[i].y < closest_value && balls[i].y > 22) { closest_index = i; closest_value = balls[i].y; } } } if (closest_index != -1) { solid_aiMovePaddle(&computerPaddle, &balls[closest_index]); } closest_index = -1; closest_value = 500; StartTimer(1, ball_speed); } if (CheckTimer(2)) { if (GetJoystickBtn()) { if (Pause() == 1) { break; } } StartTimer(2, CHECK_PONG_PAUSE); } } }
PAVECTOR CBody::GetUpPAVector(void) const { return PAVector(GetUp()); }
void menu(void) { struct Solid cursor; char selection = 0; displayMenu(&cursor); StartTimer(0, 200); StartTimer(1, 200); for (;;) { if (CheckTimer(0)) { if (GetUp()) { if (selection > 0) { solid_moveLocation(&cursor, cursor.x - 22, cursor.y); selection--; StartTimer(0, 200); } } else if (GetDown()) { if (selection < 7) { solid_moveLocation(&cursor, cursor.x + 22, cursor.y); selection++; StartTimer(0, 200); } } } if (CheckTimer(1)) { if (GetTopLeft()) { if (selection == 0) { StarBattle(); displayMenu(&cursor); selection = 0; } else if (selection == 1) { BrickBreaker(); displayMenu(&cursor); selection = 0; } else if (selection == 2) { Debris(); displayMenu(&cursor); selection = 0; } else if (selection == 3) { Pong(); displayMenu(&cursor); selection = 0; } else if (selection == 4) { Draw(); displayMenu(&cursor); selection = 0; } StartTimer(1, 200); } } } }