void ViewYWorldCamera( Camera *thisCamera, float angle ) { SetRotAxisTrfm3D(&LOCAL_Trfm, 0.0, 1.0, 0.0, thisCamera->Ex, thisCamera->Ey, thisCamera->Ez, angle); TransformPointTrfm3D(&LOCAL_Trfm, &thisCamera->AtX, &thisCamera->AtY, &thisCamera->AtZ ); TransformVectorTrfm3D(&LOCAL_Trfm, &thisCamera->UpX, &thisCamera->UpY, &thisCamera->UpZ ); UpdateCameraFrame(thisCamera); }
void ArcLeftRightCamera( Camera *thisCamera, float angle ) { SetRotAxisTrfm3D(&LOCAL_Trfm, thisCamera->Ux, thisCamera->Uy, thisCamera->Uz, thisCamera->AtX, thisCamera->AtY, thisCamera->AtZ, angle); TransformPointTrfm3D(&LOCAL_Trfm, &thisCamera->Ex, &thisCamera->Ey, &thisCamera->Ez ); TransformVectorTrfm3D(&LOCAL_Trfm, &thisCamera->UpX, &thisCamera->UpY, &thisCamera->UpZ ); UpdateCameraFrame(thisCamera); }
void ArvOverUnderCamera( Camera *thisCamera, float angle ) { SetRotAxisTrfm3D(&LOCAL_Trfm, thisCamera->Rx, thisCamera->Ry, thisCamera->Rz, thisCamera->AtX, thisCamera->AtY, thisCamera->AtZ, angle); TransformPointTrfm3D(&LOCAL_Trfm, &thisCamera->Ex, &thisCamera->Ey, &thisCamera->Ez ); TransformVectorTrfm3D(&LOCAL_Trfm, &thisCamera->UpX, &thisCamera->UpY, &thisCamera->UpZ ); UpdateCameraFrame(thisCamera); }
void RollCamera( Camera *thisCamera, float angle ) { SetRotAxisTrfm3D(&LOCAL_Trfm, thisCamera->Dx, thisCamera->Dy, thisCamera->Dz, thisCamera->Ex, thisCamera->Ey, thisCamera->Ez, -angle); TransformPointTrfm3D(&LOCAL_Trfm, &thisCamera->AtX, &thisCamera->AtY, &thisCamera->AtZ ); TransformVectorTrfm3D(&LOCAL_Trfm, &thisCamera->UpX, &thisCamera->UpY, &thisCamera->UpZ ); UpdateCameraFrame(thisCamera); }
// Set Camera parameters void SetCamera( Camera *thisCamera, float viewX, float viewY, float viewZ, float atX, float atY, float atZ, float upX, float upY, float upZ ) { float vaX, vaY, vaZ; float prodEsc; VectorNormalize( &upX, &upY, &upZ ); thisCamera->Ex = viewX; thisCamera->Ey = viewY; thisCamera->Ez = viewZ; thisCamera->AtX = atX; thisCamera->AtY = atY; thisCamera->AtZ = atZ; thisCamera->UpX = upX; thisCamera->UpY = upY; thisCamera->UpZ = upZ; // View to At vector vaX = thisCamera->AtX - thisCamera->Ex; vaY = thisCamera->AtY - thisCamera->Ey; vaZ = thisCamera->AtZ - thisCamera->Ez; if (V_IS_ZERO(vaX, vaY, vaZ)) {//printf("%f,%f,%f\n",vaX,vaY,vaZ); fprintf(stderr, "[W] while setting camera (%s): V & A are too near\n", thisCamera->name ? thisCamera->name : "noname" ); thisCamera->AtX += 1.0f; thisCamera->AtY += 1.0f; thisCamera->AtZ += 1.0f; vaX = thisCamera->AtX - thisCamera->Ex; vaY = thisCamera->AtY - thisCamera->Ey; vaZ = thisCamera->AtZ - thisCamera->Ez; } VectorNormalize( &vaX, &vaY, &vaZ ); // Check if va & up are colinear prodEsc = vaX * upX + vaY * upY + vaZ * upZ; if( fabs( prodEsc ) > 0.99f ) { fprintf(stderr, "[W] while setting camera (%s): up is nearly parallel to VA\n", thisCamera->name ? thisCamera->name : "noname" ); upX += 1.0f; prodEsc = vaX * upX + vaY * upY + vaZ * upZ; if( fabs( prodEsc ) > 0.99f ) upY += 1.0; } UpdateCameraFrame( thisCamera ); }
void CopyDataCamera( Camera *thisCamera, Camera *source ) { thisCamera->Ex = source->Ex; thisCamera->Ey = source->Ey; thisCamera->Ez = source->Ez; thisCamera->AtX = source->AtX; thisCamera->AtY = source->AtY; thisCamera->AtZ = source->AtZ; thisCamera->UpX = source->UpX; thisCamera->UpY = source->UpY; thisCamera->UpZ = source->UpZ; thisCamera->fovy = source->fovy; thisCamera->near = source->near; thisCamera->far = source->far; UpdateCameraFrame( thisCamera ); UpdateCameraProjection( thisCamera ); }
void MapMode::Update() { if (!camera) return; UpdateCameraFrame(); tile_supervisor->Update(); object_supervisor->Update(); //camera_timer.Update(); read_script->CallFunction("Update"); if (read_script->HasError()) read_script->PrintErrors(); if (!InputManager->IsUpKeyPressed() && !InputManager->IsDownKeyPressed() && !InputManager->IsLeftKeyPressed() && !InputManager->IsRightKeyPressed()) camera->SetMoving(false); else camera->SetMoving(true); if (camera->IsMoving()) { if (InputManager->IsUpKeyPressed()) { if (InputManager->IsLeftKeyPressed()) camera->SetDirection(DIRECTION_NORTHWEST); else if (InputManager->IsRightKeyPressed()) camera->SetDirection(DIRECTION_NORTHEAST); else camera->SetDirection(DIRECTION_NORTH); } else if (InputManager->IsDownKeyPressed()) { if (InputManager->IsLeftKeyPressed()) camera->SetDirection(DIRECTION_SOUTHWEST); else if (InputManager->IsRightKeyPressed()) camera->SetDirection(DIRECTION_SOUTHEAST); else camera->SetDirection(DIRECTION_SOUTH); } else if (InputManager->IsLeftKeyPressed()) camera->SetDirection(DIRECTION_WEST); else if (InputManager->IsRightKeyPressed()) camera->SetDirection(DIRECTION_EAST); } event_supervisor->Update(); GameMode::Update(); // < TEMPORARY STUFF BEGIN // rpg_global::GlobalCharacter* hero = rpg_global::GlobalManager->GetHero(); // if (!hero) // return; // // sf::Vector2i char_pos = camera->GetPosition() - sf::Vector2i(16, 16);//camera->GetCenterPosition() - sf::Vector2f(16, 16); // sf::Vector2i position_delta = sf::Vector2i(0, 0); // // temp->Update(); // // sf::Vector2i curr_tile(char_pos.x / 32, char_pos.y / 32); // MapRectangle char_rect(char_pos.x, char_pos.y, // char_pos.x + 32, char_pos.y + 32); // // // Set Idle Animations // if (rpg_input::InputManager->NoMovementKeysPressed()) // { // string direction = temp->GetDirection(); // temp->SetCurrentAnimation("idle-" + direction); // } // // if (rpg_input::InputManager->IsUpKeyPressed()) // { // sf::Vector2i check_tile(curr_tile.x, curr_tile.y - 1); // MapRectangle tile_rect(check_tile.x * 32, check_tile.y * 32, // check_tile.x * 32 + 32, check_tile.y * 32 + 32); // if (!object_supervisor->IsMapCollision(check_tile.x, check_tile.y) || // !MapRectangle::CheckIntersection(char_rect, tile_rect)) // { // temp->SetCurrentAnimation("walk-north"); // temp->SetDirection("north"); // temp->SetMoving(true); // //position_delta.y -= 5; // } // } // if (rpg_input::InputManager->IsDownKeyPressed()) // { // sf::Vector2i check_tile(curr_tile.x, curr_tile.y + 1); // MapRectangle tile_rect(check_tile.x * 32, check_tile.y * 32, // check_tile.x * 32 + 32, check_tile.y * 32 + 32); // if (!object_supervisor->IsMapCollision(check_tile.x, check_tile.y) || // !MapRectangle::CheckIntersection(char_rect, tile_rect)) // { // temp->SetCurrentAnimation("walk-south"); // temp->SetDirection("south"); // temp->SetMoving(true); // //position_delta.y += 5; // } // } // if (rpg_input::InputManager->IsLeftKeyPressed()) // { // sf::Vector2i check_tile(curr_tile.x - 1, curr_tile.y); // MapRectangle tile_rect(check_tile.x * 32, check_tile.y * 32, // check_tile.x * 32 + 32, check_tile.y * 32 + 32); // if (!object_supervisor->IsMapCollision(check_tile.x, check_tile.y) || // !MapRectangle::CheckIntersection(char_rect, tile_rect)) // { // temp->SetCurrentAnimation("walk-west"); // temp->SetDirection("west"); // temp->SetMoving(true); // //position_delta.x -= 5; // } // } // if (rpg_input::InputManager->IsRightKeyPressed()) // { // sf::Vector2i check_tile(curr_tile.x + 1, curr_tile.y); // MapRectangle tile_rect(check_tile.x * 32, check_tile.y * 32, // check_tile.x * 32 + 32, check_tile.y * 32 + 32); // // if (!object_supervisor->IsMapCollision(check_tile.x, check_tile.y) || // !MapRectangle::CheckIntersection(char_rect, tile_rect)) // { // temp->SetCurrentAnimation("walk-east"); // temp->SetDirection("east"); // temp->SetMoving(true); // //position_delta.x += 5; // } // } // // //camera->SetCenterPosition(char_pos.x + position_delta.x + 16, char_pos.y + position_delta.y + 16); //temp->Update(); }