Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve scaleform transformation #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1557,19 +1557,22 @@ Citizen.CreateThread(function()
if info.scaleform and info.scaleform.attached then
if entityExists and NetworkGetEntityIsNetworked(entity) then
local mediaRot = GetEntityRotation(entity, 0)
local forwardVector, rightVector, upVector = GetEntityMatrix(entity)

local r = math.rad(mediaRot.z)
local cosr = math.cos(r)
local sinr = math.sin(r)

local posX = (info.scaleform.position.x * cosr - info.scaleform.position.y * sinr) + mediaPos.x
local posY = (info.scaleform.position.y * cosr + info.scaleform.position.x * sinr) + mediaPos.y
local posZ = info.scaleform.position.z + mediaPos.z
local offsetX = info.scaleform.position.x - info.scaleform.scale.x * 10
local offsetY = info.scaleform.position.y
local offsetZ = info.scaleform.position.z + info.scaleform.scale.y * 10
local pos = mediaPos + (rightVector * offsetX) + (forwardVector * offsetY) + (upVector * offsetZ)

info.scaleform.finalPosition = vector3(posX, posY, posZ)
info.scaleform.finalPosition = pos

-- FIXME: This really only works for the Z rotation (yaw)
info.scaleform.finalRotation = -(mediaRot + info.scaleform.rotation)
info.scaleform.finalRotation = mediaRot + info.scaleform.rotation

elseif info.scaleform.finalPosition and info.scaleform.finalRotation then
info.scaleform.finalPosition = nil
info.scaleform.finalRotation = nil
Expand Down
4 changes: 2 additions & 2 deletions dui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ function DuiBrowser:renderFrame(drawSprite)
DrawScaleformMovie_3dSolid(self.sfHandle,
self.scaleform.finalPosition or self.scaleform.position,
self.scaleform.finalRotation or self.scaleform.rotation,
2.0, 2.0, 1.0,
self.scaleform.scale,
2.0, 2.0, 2.0,
self.scaleform.scale.x, self.scaleform.scale.y * (Config.dui.screenHeight / Config.dui.screenWidth), 1,
2)
end
end
Expand Down
3 changes: 1 addition & 2 deletions ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,7 @@
</div>
<i class="fas fa-arrows-alt"></i>
<input id="scaleform-scale-x" type="number" placeholder="x" class="scaleform-setting" min="0" max="1" step="0.01" value="0.1">
<input id="scaleform-scale-y" type="number" placeholder="y" class="scaleform-setting" min="0" max="1" step="0.01" value="0.05">
<input id="scaleform-scale-z" type="number" placeholder="z" class="scaleform-setting" min="0" max="1" step="0.01" value="0">
<input id="scaleform-scale-y" type="number" placeholder="y" class="scaleform-setting" min="0" max="1" step="0.01" value="0.1">
</div>
<div id="scaleform-auto">
<button id="scaleform-auto-my-position">
Expand Down
9 changes: 1 addition & 8 deletions ui/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,6 @@ function getScaleformSettings(standalone) {
var rotZInput = document.getElementById('scaleform-rotation-z');
var scaleXInput = document.getElementById('scaleform-scale-x');
var scaleYInput = document.getElementById('scaleform-scale-y');
var scaleZInput = document.getElementById('scaleform-scale-z');
var attachedInput = document.getElementById('scaleform-attached');

var name = nameInput.value;
Expand All @@ -1216,7 +1215,6 @@ function getScaleformSettings(standalone) {
var rotZ = parseFloat(rotZInput.value);
var scaleX = parseFloat(scaleXInput.value);
var scaleY = parseFloat(scaleYInput.value);
var scaleZ = parseFloat(scaleZInput.value);
var attached = attachedInput.checked;

if (name == '') {
Expand Down Expand Up @@ -1255,10 +1253,6 @@ function getScaleformSettings(standalone) {
scaleY = 0;
}

if (isNaN(scaleZ)) {
scaleZ = 0;
}

return {
name: name,
position: {
Expand All @@ -1274,7 +1268,7 @@ function getScaleformSettings(standalone) {
scale: {
x: scaleX,
y: scaleY,
z: scaleZ
z: 0
},
standalone: standalone,
attached: attached
Expand Down Expand Up @@ -1474,7 +1468,6 @@ function setMediaPlayerDefaults(handle) {
document.getElementById('scaleform-rotation-z').value = scaleform.rotation.z;
document.getElementById('scaleform-scale-x').value = scaleform.scale.x;
document.getElementById('scaleform-scale-y').value = scaleform.scale.y;
document.getElementById('scaleform-scale-z').value = scaleform.scale.z;
document.getElementById('scaleform-attached').checked = scaleform.attached;

document.getElementById('scaleform').checked = true;
Expand Down