void TargetingControl::setupOrientation() { extern float curfov, aspect; // rendergl.cpp vecfromyawpitch(camera1->yaw, 0, 0, -1, camright); vecfromyawpitch(camera1->yaw, camera1->pitch + 90, 1, 0, camup); // Account for mouse position in the world position we are aiming at float cx, cy; gui::getcursorpos(cx, cy); float factor = tanf(RAD*curfov/2.0f); // Size of edge opposite the angle of fov/2, in the triangle for (half of) viewport, // having unknown radius but known angle of fov/2 and close edge of 1.0 camdir.x = 0.0f; camdir.y = 1.0f; camdir.z = 0.0f; // Looking straight forward camdir.x -= 2.0f * (cx - 0.5f) * factor; // adjust for mouse position camdir.z -= 2.0f * (cy - 0.5f) * factor / aspect; // adjust for mouse position camdir.normalize(); camdir.rotate_around_z(RAD*camera1->yaw); camdir.rotate(-RAD*camera1->pitch, camright); if(raycubepos(camera1->o, camdir, worldpos, 0, RAY_CLIPMAT|RAY_SKIPFIRST) == -1) worldpos = vec(camdir).mul(2*worldsize).add(camera1->o); //otherwise 3dgui won't work when outside of map }
void ControlNPC::connect(DynamicEntity* de) { if(!de) fatal("Controler::Character : no valid Dynamic Entity. Exit!"); dynent = de; ///TODO: set name ActionInstance defformatstring(s)("%p", this); copystring(dynent->name, s); ///TODO: set and send basic infos like name, model ... // filtertext(dynent->name, lib.librarydescr, false, MAXNAMELEN); game::addmsg(SV_SWITCHNAME, "rs", dynent->name); dynent->controltype = CONTROL_NPC; dynent->lastupdate = lastmillis; ///TODO: spawn behaviour in edit and normal mode //first spawn, no actions defined in Actionlib // if(editmode) // { dynent->o = vec(game::player1->o); droptofloor(dynent->o, 0, 0); vec sp = vec(0,0,0); vecfromyawpitch(game::player1->yaw, 0, 50, 0, sp); dynent->o.add(sp); dynent->o.z += dynent->eyeheight; game::addmsg(SV_TRYSPAWN, "rc", dynent); // } Instance::init(); isinit = true; }
vec menuinfrontofplayer() { vec dir; vecfromyawpitch(camera1->yaw, 0, 1, 0, dir); dir.mul(menudistance).add(camera1->o); dir.z -= player->eyeheight-1; return dir; }
void entradius(extentity &e, bool color) { switch(e.type) { case ETR_SPAWN: { vec dir; vecfromyawpitch(e.attr1, 0, 1, 0, dir); renderentarrow(e, dir, 4); break; } } }
void ControlCharacter::init(DynamicEntity* de) { if(!de) fatal("Controler::Character : no valid Dynamic Entity. Exit!"); dynent = de; copystring(dynent->name, lib.librarydescr); // TODO (offtools#1#): set and send basic infos like name, model ... // filtertext(dynent->name, lib.librarydescr, false, MAXNAMELEN); // addmsg(SV_SWITCHNAME, "rs", dynent->name); dynent->controltype = CONTROL_CHARACTER; dynent->lastupdate = lastmillis; plastaction = &(dynent->lastaction); //added by Protagoras //first spawn, no actions defined in Actionlib if(editmode && !lib.states[0]->steps.length()) { // TODO (offtools#1#): fix if author under floor dynent->o = vec(game::player1->o); droptofloor(dynent->o, 0, 0); vec sp = vec(0,0,0); vecfromyawpitch(game::player1->yaw, 0, 50, 0, sp); dynent->o.add(sp); dynent->o.z += dynent->eyeheight; game::addmsg(SV_TRYSPAWN, "rc", dynent); event(ACTIONINSTANCE_EVENT_INIT); } else { event(ACTIONINSTANCE_EVENT_INIT); } isinit = true; }
void CameraControl::positionCamera(physent* camera1) { Logging::log(Logging::INFO, "CameraControl::positionCamera\r\n"); INDENT_LOG(Logging::INFO); if (useForcedCamera || useForcedPosition || useForcedYaw || useForcedPitch || useForcedRoll) { if (useForcedPosition) { camera1->o = forcedCamera.o; useForcedPosition = false; }; if (useForcedYaw) { camera1->yaw = forcedCamera.yaw; useForcedYaw = false; }; if (useForcedPitch) { camera1->pitch = forcedCamera.pitch; useForcedPitch = false; }; if (useForcedRoll) { camera1->roll = forcedCamera.roll; useForcedRoll = false; }; if (useForcedCamera) { useForcedCamera = false; // Prepare for next frame return; } } // Sync camera height to scripts, if necessary static float lastCameraHeight = -1; if (ScriptEngineManager::hasEngine() && lastCameraHeight != cameraheight) { lastCameraHeight = cameraheight; ScriptEngineManager::getGlobal()->getProperty("Global")->setProperty("cameraHeight", cameraheight); } // If we just left forced camera mode, restore thirdperson state if (savedThirdperson != -1) { thirdperson = savedThirdperson; savedThirdperson = -1; } float saved_camera_speed = camera1->maxspeed; // Kripken: need to save this, because camera1 =?= player1 camera1->maxspeed = 50; // This speed determines the distance of the camera, so the Sauer way of tying it to the // player's speed is not completely general vec dir; vecfromyawpitch(camera1->yaw, camera1->pitch, -1, 0, dir); if (GuiControl::isCharacterViewing()) camera1->o = player->o; // Start from player if(game::collidecamera()) { vec cameraOrigin = camera1->o; if (thirdperson) { vec up(0, 0, 1); movecamera(camera1, up, cameraheight, 1); movecamera(camera1, up, clamp(cameraheight- camera1->o.dist(cameraOrigin), 0.0f, 1.0f), 0.1f); // Find distance to obstacle } vec cameraOrigin2 = camera1->o; movecamera(camera1, dir, cam_dist, 1); movecamera(camera1, dir, clamp(cam_dist - camera1->o.dist(cameraOrigin2), 0.0f, 1.0f), 0.1f); // Find distance to obstacle if (smoothcamera) { float intendedDist = camera1->o.dist(cameraOrigin2)*(1.0f-cameraavoid); static float lastDist = 5; float ACTUAL_DISTANCE_FACTOR = clamp(1.0f - (curtime/1000.0f)/smoothcamera, 0.0f, 1.0f); float actualDist = ACTUAL_DISTANCE_FACTOR*lastDist + (1-ACTUAL_DISTANCE_FACTOR)*intendedDist; // Start again, move to current distance camera1->o = cameraOrigin2; movecamera(camera1, dir, actualDist, 1); movecamera(camera1, dir, clamp(actualDist - camera1->o.dist(cameraOrigin2), 0.0f, 1.0f), 0.1f); lastDist = actualDist; } } else { camera1->o.z += cameraheight; camera1->o.add(vec(dir).mul(cam_dist)); } camera1->maxspeed = saved_camera_speed; // Kripken: Smooth camera movement: We interpolate our the new calculated position with the old one, smoothly static fpsent actualCamera; // Need fpsent for new normalization functions static vec lastPlayerPosition; vec temp(actualCamera.o); temp.sub(camera1->o); actualCamera.normalize_yaw(camera1->yaw); actualCamera.normalize_pitch(camera1->pitch); float yawDelta = camera1->yaw - actualCamera.yaw; float pitchDelta = camera1->pitch - actualCamera.pitch; // Only interpolate if we are fairly close, otherwise this might be a new map, or we teleported, etc. if (smoothcamera && !GuiControl::isMouselooking() && temp.magnitude() < 50*player->radius && fabs(yawDelta) < 30.0f && fabs(pitchDelta) < 30.0f) { float ACTUAL_CAMERA_FACTOR = clamp(1.0f - (curtime/1000.0f)/smoothcamera, 0.0f, 1.0f); vec temp = player->o; temp.sub(lastPlayerPosition); actualCamera.o.add(temp); // Prevent camera stutter actualCamera.o.mul(ACTUAL_CAMERA_FACTOR); temp = camera1->o; temp.mul(1-ACTUAL_CAMERA_FACTOR); actualCamera.o.add(temp); actualCamera.yaw = ACTUAL_CAMERA_FACTOR*actualCamera.yaw + (1-ACTUAL_CAMERA_FACTOR)*camera1->yaw; actualCamera.pitch = ACTUAL_CAMERA_FACTOR*actualCamera.pitch + (1-ACTUAL_CAMERA_FACTOR)*camera1->pitch; camera1->o = actualCamera.o; camera1->yaw = actualCamera.yaw; camera1->pitch = actualCamera.pitch; // camera1->o.z += player->aboveeye + player->eyeheight; } else { actualCamera.o = camera1->o; actualCamera.yaw = camera1->yaw; actualCamera.pitch = camera1->pitch; } lastPlayerPosition = player->o; }