CharlySHOMAN Posted July 16, 2017 Share Posted July 16, 2017 После использования функции setCameraMatrix камера застывает в определенном направлении и вращать её при движении мышки становится невозможным. Как это исправить? Т.е. чтобы она вращалась именно из той точки, которую я задал с помощью SetCameraMatrix. setCameraMatrix Link to comment
CharlySHOMAN Posted July 16, 2017 Author Share Posted July 16, 2017 1 hour ago, Kenix said: setCameraTarget Эта функция задаёт в качестве цели игрока. А мне нужно, чтобы камера не была закреплена за игроком. // при использовании этого синтаксиса функции: setCameraTarget ( float targetX, float targetY, float targetZ ) никакого эффекта нет, если ранее направление камеры было задано через setCameraMatrix Link to comment
alexaxel705 Posted July 17, 2017 Share Posted July 17, 2017 local mouseSensitivity = 0.3 local invertMouseLook = false local speed = 0 local strafespeed = 0 local rotX, rotY = 0,0 local function freecamFrame () local cameraAngleX = rotX local cameraAngleY = rotY local freeModeAngleZ = math.sin(cameraAngleY) local freeModeAngleY = math.cos(cameraAngleY) * math.cos(cameraAngleX) local freeModeAngleX = math.cos(cameraAngleY) * math.sin(cameraAngleX) local camPosX, camPosY, camPosZ = getCameraMatrix() local camTargetX = camPosX + freeModeAngleX * 100 local camTargetY = camPosY + freeModeAngleY * 100 local camTargetZ = camPosZ + freeModeAngleZ * 100 local camAngleX = camPosX - camTargetX local camAngleY = camPosY - camTargetY local camAngleZ = 0 local angleLength = math.sqrt(camAngleX*camAngleX+camAngleY*camAngleY+camAngleZ*camAngleZ) local camNormalizedAngleX = camAngleX / angleLength local camNormalizedAngleY = camAngleY / angleLength local camNormalizedAngleZ = 0 local normalAngleX = 0 local normalAngleY = 0 local normalAngleZ = 1 local normalX = (camNormalizedAngleY * normalAngleZ - camNormalizedAngleZ * normalAngleY) local normalY = (camNormalizedAngleZ * normalAngleX - camNormalizedAngleX * normalAngleZ) local normalZ = (camNormalizedAngleX * normalAngleY - camNormalizedAngleY * normalAngleX) camPosX = camPosX + freeModeAngleX * speed camPosY = camPosY + freeModeAngleY * speed camPosZ = camPosZ + freeModeAngleZ * speed camPosX = camPosX + normalX * strafespeed camPosY = camPosY + normalY * strafespeed camPosZ = camPosZ + normalZ * strafespeed camTargetX = camPosX + freeModeAngleX * 100 camTargetY = camPosY + freeModeAngleY * 100 camTargetZ = camPosZ + freeModeAngleZ * 100 setCameraMatrix ( camPosX, camPosY, camPosZ, camTargetX, camTargetY, camTargetZ ) end local function freecamMouse (cX,cY,aX,aY) local width, height = guiGetScreenSize() aX = aX - width / 2 aY = aY - height / 2 if invertMouseLook then aY = -aY end rotX = rotX + aX * mouseSensitivity * 0.01745 rotY = rotY - aY * mouseSensitivity * 0.01745 local PI = math.pi if rotX > PI then rotX = rotX - 2 * PI elseif rotX < -PI then rotX = rotX + 2 * PI end if rotY > PI then rotY = rotY - 2 * PI elseif rotY < -PI then rotY = rotY + 2 * PI end if rotY < -PI / 2.05 then rotY = -PI / 2.05 elseif rotY > PI / 2.05 then rotY = PI / 2.05 end end function FreeCameraEnable(command, h) setCameraMatrix(x, y, z) addEventHandler("onClientRender", root, freecamFrame) addEventHandler("onClientCursorMove",root, freecamMouse) end addCommandHandler("startcam", FreeCameraEnable) function FreeCameraDisable(command, h) setCameraTarget(localPlayer) removeEventHandler("onClientRender", root, freecamFrame) removeEventHandler("onClientCursorMove",root, freecamMouse) end addCommandHandler("stopcam", FreeCameraDisable) Команда /startcam активирует, /stopcam деактивирует. Для перемещения камеры по клавишам надо дописывать скрипт. Всё уже реализовано в mods\deathmatch\resources\[editor]\freecam.zip 1 Link to comment
CharlySHOMAN Posted July 17, 2017 Author Share Posted July 17, 2017 4 hours ago, alexaxel705 said: local mouseSensitivity = 0.3 local invertMouseLook = false local speed = 0 local strafespeed = 0 local rotX, rotY = 0,0 local function freecamFrame () local cameraAngleX = rotX local cameraAngleY = rotY local freeModeAngleZ = math.sin(cameraAngleY) local freeModeAngleY = math.cos(cameraAngleY) * math.cos(cameraAngleX) local freeModeAngleX = math.cos(cameraAngleY) * math.sin(cameraAngleX) local camPosX, camPosY, camPosZ = getCameraMatrix() local camTargetX = camPosX + freeModeAngleX * 100 local camTargetY = camPosY + freeModeAngleY * 100 local camTargetZ = camPosZ + freeModeAngleZ * 100 local camAngleX = camPosX - camTargetX local camAngleY = camPosY - camTargetY local camAngleZ = 0 local angleLength = math.sqrt(camAngleX*camAngleX+camAngleY*camAngleY+camAngleZ*camAngleZ) local camNormalizedAngleX = camAngleX / angleLength local camNormalizedAngleY = camAngleY / angleLength local camNormalizedAngleZ = 0 local normalAngleX = 0 local normalAngleY = 0 local normalAngleZ = 1 local normalX = (camNormalizedAngleY * normalAngleZ - camNormalizedAngleZ * normalAngleY) local normalY = (camNormalizedAngleZ * normalAngleX - camNormalizedAngleX * normalAngleZ) local normalZ = (camNormalizedAngleX * normalAngleY - camNormalizedAngleY * normalAngleX) camPosX = camPosX + freeModeAngleX * speed camPosY = camPosY + freeModeAngleY * speed camPosZ = camPosZ + freeModeAngleZ * speed camPosX = camPosX + normalX * strafespeed camPosY = camPosY + normalY * strafespeed camPosZ = camPosZ + normalZ * strafespeed camTargetX = camPosX + freeModeAngleX * 100 camTargetY = camPosY + freeModeAngleY * 100 camTargetZ = camPosZ + freeModeAngleZ * 100 setCameraMatrix ( camPosX, camPosY, camPosZ, camTargetX, camTargetY, camTargetZ ) end local function freecamMouse (cX,cY,aX,aY) local width, height = guiGetScreenSize() aX = aX - width / 2 aY = aY - height / 2 if invertMouseLook then aY = -aY end rotX = rotX + aX * mouseSensitivity * 0.01745 rotY = rotY - aY * mouseSensitivity * 0.01745 local PI = math.pi if rotX > PI then rotX = rotX - 2 * PI elseif rotX < -PI then rotX = rotX + 2 * PI end if rotY > PI then rotY = rotY - 2 * PI elseif rotY < -PI then rotY = rotY + 2 * PI end if rotY < -PI / 2.05 then rotY = -PI / 2.05 elseif rotY > PI / 2.05 then rotY = PI / 2.05 end end function FreeCameraEnable(command, h) setCameraMatrix(x, y, z) addEventHandler("onClientRender", root, freecamFrame) addEventHandler("onClientCursorMove",root, freecamMouse) end addCommandHandler("startcam", FreeCameraEnable) function FreeCameraDisable(command, h) setCameraTarget(localPlayer) removeEventHandler("onClientRender", root, freecamFrame) removeEventHandler("onClientCursorMove",root, freecamMouse) end addCommandHandler("stopcam", FreeCameraDisable) Команда /startcam активирует, /stopcam деактивирует. Для перемещения камеры по клавишам надо дописывать скрипт. Всё уже реализовано в mods\deathmatch\resources\[editor]\freecam.zip Спасибо. Я искал это в стандартных ресурсах, но почему-то не находил. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now