Community Forum

setViewport problem

Forum Overview >> Farming Simulator 2011

CategoryFarming Simulator 2011
Created05.04.2011 16:22


Przemysław Lipiński (Unknown) 05.04.2011 16:32
I have problem with function setViewport. In my script work only viewport index 0. What's wrong?

This is my script:
<---LUA-->
Viewport = {};

function Viewport.prerequisitesPresent(specializations)
return true;
end;

function Viewport:load(xmlFile)

self.setViewportMode = SpecializationUtil.callSpecializationsFunction("setViewportMode");

self.ViewportMode = false;

self.pipeCamera = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.pipeCamera#index"));
end;

function Viewport:delete()

end;

function Viewport:readStream(streamId, connection)
end;

function Viewport:writeStream(streamId, connection)
end;

function Viewport:mouseEvent(posX, posY, isDown, isUp, button)
end;

function Viewport:keyEvent(unicode, sym, modifier, isDown)
end;

function Viewport:update(dt)

if self:getIsActive() then

if self.isClient and self:getIsActiveForInput() then

if InputBinding.hasEvent(InputBinding.ACTIVATE_VIEWPORT) then
self:setViewportMode(not self.ViewportMode);
end;
end;
setCamera(self.cameras[self.camIndex].cameraNode, 0)
setCamera(self.pipeCamera, 1)
setViewport(0, 0.0, 0.0, 1.0, 1.0)
end;

end;

function Viewport:updateTick(dt)

end;

function Viewport:draw()

end;

function Viewport:setViewportMode(ViewportMode)
ViewportModeEvent.sendEvent(self, ViewportMode, noEventSend);
self.ViewportMode = ViewportMode;
if ViewportMode then
getCamera(0)
setViewport(0, 0.0, 0.0, 1.0, 1.0)
getCamera(1)
setViewport(1, 0.5, 0.5, 0.3, 0.3)
else
getCamera(0)
setViewport(0, 0.0, 0.0, 1.0, 1.0)
end;
end;
<---END--->

This is the event:
<---LUA-->
ViewportModeEvent = {};
ViewportModeEvent_mt = Class(ViewportModeEvent, Event);

InitEventClass(ViewportModeEvent, "ViewportModeEvent");

function ViewportModeEvent:emptyNew()
local self = Event:new(ViewportModeEvent_mt);
self.className="ViewportModeEvent";
return self;
end;

function ViewportModeEvent:new(object, ViewportMode)
local self = ViewportModeEvent:emptyNew()
self.object = object;
self.ViewportMode = ViewportMode;
return self;
end;

function ViewportModeEvent:readStream(streamId, connection)
local id = streamReadInt32(streamId);
self.ViewportMode = streamReadBool(streamId);
self.object = networkGetObject(id);
self:run(connection);
end;

function ViewportModeEvent:writeStream(streamId, connection)
streamWriteInt32(streamId, networkGetObjectId(self.object));
streamWriteBool(streamId, self.ViewportMode);
end;

function ViewportModeEvent:run(connection)
self.object:setViewportMode(self.ViewportMode);
if not connection:getIsServer() then
g_server:broadcastEvent(ViewportModeEvent:new(self.object, self.ViewportMode), nil, connection, self.object);
end;
end;

function ViewportModeEvent.sendEvent(vehicle, ViewportMode, noEventSend)
if ViewportMode ~= vehicle.ViewportMode then
if noEventSend == nil or noEventSend == false then
if g_server ~= nil then
g_server:broadcastEvent(ViewportModeEvent:new(vehicle, ViewportMode), nil, nil, vehicle);
else
g_client:getServerConnection():sendEvent(ViewportModeEvent:new(vehicle, ViewportMode));
end;
end;
end;
end;
<---END--->

Mfg
Lipa


Stefan Geiger - GIANTS Software 24.06.2011 09:17
You also need to set a root node which defines the nodes that are rendered.
If you want to render the same scene as with the first viewport but from a different view, you could use this code:

setRootNode(getRootNode(), 1);


Note: Log in to post. Create a new account here.