Jump to content

Problems with camera fly-through


Michael Betke
 Share

Recommended Posts

I'm a bit in trouble. Need to finish a movie fly-through for a client this weekend but the script lacks of some important stuff.

 

It seems the camera is just following the view to the next camera_node.

So all I can do is a straight view but not left and right. If i rotate the node a bit to the left or right the camera does a wide curve.

 

But it should fly straight the the next node and just "look" to the side on a certain angle. I would like to have a option where I can set certain degree for "looking" left and right.

 

 

Any ideas?

 

This is the script:

Attention it drops a lot of large screenshots to the HDD which will be a movie later. Maybe using the fly-through.lua would be better.

require("Scripts/linkedlist")
require("Scripts/spline")
require("Scripts/constants/keycodes")
require("Scripts/constants/engine_const")

HideMouse()
FlushMouse()
FlushKeys()

local dummy = LoadModel( "abstract::info_camera_node.gmf" )
local node
local currentnode
if dummy~=nil then
for node in iterate(dummy.reference.instances) do
	if node:GetKey("starthere")=="1" then
		currentnode=node
		break
	end
end
dummy:Free()
end

if currentnode==nil then
Notify("No starting camera node found!")
return
end

local nextnode=currentnode:GetTarget()

if nextnode==nil then
Notify("At least two camera nodes are required.")
return
end

local tension=EntityDistance(currentnode,nextnode)*0.5
local spline=CreateSpline(currentnode.position,currentnode.mat:K():Scale(tension),nextnode.position,nextnode.mat:K():Scale(tension),0.75)
local splinelength = spline:Length()

fw.main.camera:SetMatrix(currentnode.mat)

local n=0.0
local frame=0
local odd=0

local buffer=CreateBuffer(1920,1080,BUFFER_COLOR)
SetBuffer(buffer)
local buffer2=CreateBuffer(1920,1080,BUFFER_COLOR)

while KeyHit(KEY_ESCAPE)==0 do

if n>=1.0 then
	currentnode=nextnode
	nextnode=currentnode:GetTarget()
	if nextnode==nil then
		Notify("Finished")
		break
	end
	tension=EntityDistance(currentnode,nextnode)*0.5
	spline=CreateSpline(currentnode.position,currentnode.mat:K():Scale(tension),nextnode.position,nextnode.mat:K():Scale(tension),0.75)
	n=0.0
	splinelength=spline:Length()
end

p=Vec3(0)
t=Vec3(0)
n = n + 0.01*1.0/splinelength*10.0
spline:Interpolate(n,p,t)

--MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)

fw.main.camera:SetPosition(p)
fw.main.camera:AlignToVector(t,3,0.05*1.0)



fw.main.world:Update(1.0)
fw.transparency.world:Update(1.0)

SetBuffer(buffer)

fw:Render()
--DrawText(AppSpeed(),100,0)

Flip(0)
local name

odd=odd+1
if odd==2 then
	odd=0
	if frame<1000 then
		if frame<100 then
			if frame<10 then
				name="frame000"..frame
			else
				name="frame00"..frame
			end
		else
			name="frame0"..frame
		end
	else
		name="frame"..frame
	end


	SetBuffer(buffer2)
	DrawImage(GetColorBuffer(buffer),0,0,1920,1080)
	SaveBuffer(buffer2,name..".tga")

	frame=frame+1
end

--SetBuffer(BackBuffer())
--fw:Render()
--Flip(0)

end

ShowMouse()

Pure3d Visualizations Germany - digital essences

AAA 3D Model Shop specialized on nature and environments

Link to comment
Share on other sites

Quick and dirty from fps lua script ...

 


require("Scripts/linkedlist")
require("Scripts/spline")
require("Scripts/constants/keycodes")

--Variables
camerapitch=0.0
camerayaw=0.0

camerapitch=fw.main.camera.rotation.x
camerayaw=fw.main.camera.rotation.y

HideMouse()
FlushMouse()
FlushKeys()

local dummy = LoadModel( "abstract::info_camera_node.gmf" )
local node
local currentnode
if dummy~=nil then
for node in iterate(dummy.reference.instances) do
	if node:GetKey("starthere")=="1" then
		currentnode=node
		break
	end
end
dummy:Free()
end

if currentnode==nil then
Notify("No starting camera node found!")
return
end

local nextnode=currentnode:GetTarget()

if nextnode==nil then
Notify("At least two camera nodes are required.")
return
end

local tension=EntityDistance(currentnode,nextnode)*0.5
local spline=CreateSpline(currentnode.position,currentnode.mat:K():Scale(tension),nextnode.position,nextnode.mat:K():Scale(tension),0.75)
local splinelength = spline:Length()

fw.main.camera:SetMatrix(currentnode.mat)

local n=0.0

while KeyHit(KEY_ESCAPE)==0 do

if n>=1.0 then
	currentnode=nextnode
	nextnode=currentnode:GetTarget()

	if nextnode==nil then
		break
	end

	tension=EntityDistance(currentnode,nextnode)*0.5
	spline=CreateSpline(currentnode.position,currentnode.mat:K():Scale(tension),nextnode.position,nextnode.mat:K():Scale(tension),0.75)
	n=0.0
	splinelength=spline:Length()
end

p=Vec3(0)
t=Vec3(0)

if nextnode~=nil then

	--less smooth
	n = n + ( 0.01*AppSpeed()/splinelength*10.0 )
	spline:Interpolate(n,p,t)



	--Camera look
	gx=Round(GraphicsWidth()/2)
	gy=Round(GraphicsHeight()/2)

	dx=Curve((MouseX()-gx)/4.0,dx, 0.01*AppSpeed() )
	dy=Curve((MouseY()-gy)/4.0,dy, 0.01*AppSpeed() )

	MoveMouse(gx,gy)

	camerapitch=camerapitch+dy
	camerayaw=camerayaw-dx
	camerapitch=math.min(camerapitch,89)
	camerapitch=math.max(camerapitch,-89)
	fw.main.camera:SetRotationf(camerapitch,camerayaw,0,1)
	--

	if KeyDown(KEY_SPACE)~=1 then
	fw.main.camera:SetPosition(p)
	fw.main.camera:AlignToVector(t,3,0.01*AppSpeed() )
	end

	--was
	--MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)
end

fw:Update()
fw:Render()

Flip(0)
end

ShowMouse()

AMD 64 X2 Dual 5k - 4GB - XFX GForce9800GT - nv196.21 - WinXP Sp3

zBrush4R2 - Silo2Pro - Unwrap3DPro - Gile - MaPZone2.5

 

adv_banner-april2012_720x150_tex01.png

 

Xxploration FPS in progress ...

Link to comment
Share on other sites

Thanks this is really dirty but a creative solution. :)

 

I can't use a manual rotation because the script writes 30 sreenshots per second and I won't be able to rotate smoothly.

 

Here is a screenhsot of what I need.

 

post-6-029827500 1289064457_thumb.jpg

 

Camera needs to view along the blue axis but should follow the spline along the street to the next node.

Pure3d Visualizations Germany - digital essences

AAA 3D Model Shop specialized on nature and environments

Link to comment
Share on other sites

Thanks this is really dirty but a creative solution. :)

 

I can't use a manual rotation because the script writes 30 sreenshots per second and I won't be able to rotate smoothly.

 

Here is a screenhsot of what I need.

 

post-6-029827500 1289064457_thumb.jpg

 

Camera needs to view along the blue axis but should follow the spline along the street to the next node.

 

ok just a quick and dirty version that lets you fix the camera angle to the current node's angle.

 

First change the info_camera_node.lua script to this:

require("scripts/class")
local class=CreateClass(...)

function class:InitDialog(grid)
self.super:InitDialog(grid)
local group=grid:AddGroup("Camera Node")
group:AddProperty("starthere",PROPERTY_BOOL,0,"Start here")
group:AddProperty("fixed",PROPERTY_BOOL,0,"Fixed Camera Angle")
group:Expand(1)
end

then the game script to this:

require("Scripts/linkedlist")
require("Scripts/spline")
require("Scripts/constants/keycodes")

HideMouse()
FlushMouse()
FlushKeys()

local dummy = LoadModel( "abstract::info_camera_node.gmf" )
local node
local currentnode
if dummy~=nil then
for node in iterate(dummy.reference.instances) do
	if node:GetKey("starthere")=="1" then
		currentnode=node
		break
	end
end
dummy:Free()
end

if currentnode==nil then
Notify("No starting camera node found!")
return
end

local nextnode=currentnode:GetTarget()

if nextnode==nil then
Notify("At least two camera nodes are required.")
return
end

local tension=EntityDistance(currentnode,nextnode)*0.5
local spline=CreateSpline(currentnode.position,currentnode.mat:K():Scale(tension),nextnode.position,nextnode.mat:K():Scale(tension),0.75)
local splinelength = spline:Length()

fw.main.camera:SetMatrix(currentnode.mat)

local n=0.0

while KeyHit(KEY_ESCAPE)==0 do

if n>=1.0 then
	currentnode=nextnode
	nextnode=currentnode:GetTarget()
	if nextnode==nil then
		break
	end
	tension=EntityDistance(currentnode,nextnode)*0.5
	spline=CreateSpline(currentnode.position,currentnode.mat:K():Scale(tension),nextnode.position,nextnode.mat:K():Scale(tension),0.75)
	n=0.0
	splinelength=spline:Length()
end

p=Vec3(0)
t=Vec3(0)
n = n + 0.01*AppSpeed()/splinelength*10.0
spline:Interpolate(n,p,t)

MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)

fw.main.camera:SetPosition(p)

--'Edited here to check whether camera should be at fixed angle or'
--'interpolated between the two nodes rotation values'
if currentnode:GetKey("fixed")=="1" then
	fw.main.camera:SetRotation(currentnode.rotation,1)
else
	fw.main.camera:AlignToVector(t,3,0.05*AppSpeed())
end		

fw:Update()
fw:Render()
Flip(0)
end
ShowMouse()

 

How to use: Set the rotation of the camera node in the editor. Then decide if you want the camera direction to be set by the node's rotation or have it change as it the game script interpolates between the current node's and the next node's rotation values by selecting the property dialog's checkbox for Fixed Camera Angle. Note that the camera angle is always in the same direction as the node's Z-axis (the blue arrow).

 

To prevent major camera rotation swings, set a non-fixed camera angle node at the same rotation as a fixed camera angle node after the fixed camera angle node.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Well, i meant to use "PointEntity" with an array of stuff you would like to look at while going on - not manually using the mouse.

I thought i road something about "movie-camera" - my tired eyes. thx macklebee to pick that up. :)

AMD 64 X2 Dual 5k - 4GB - XFX GForce9800GT - nv196.21 - WinXP Sp3

zBrush4R2 - Silo2Pro - Unwrap3DPro - Gile - MaPZone2.5

 

adv_banner-april2012_720x150_tex01.png

 

Xxploration FPS in progress ...

Link to comment
Share on other sites

the line here:

fw.main.camera:AlignToVector(t,3,0.05*1.0)

is replaced with this:

        --'Edited here to check whether camera should be at fixed angle or'
       --'interpolated between the two nodes rotation values'
       if currentnode:GetKey("fixed")=="1" then
               fw.main.camera:SetRotation(currentnode.rotation,1)
       else
               fw.main.camera:AlignToVector(t,3,0.05*AppSpeed())
       end

 

thats all that was changed... that and the one line added to the node script.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Maybe I have problems understanding the script stuff. Sorry for that. :)

 

But the script you posted looks very different then mine. My script looks like it creates a renderbuffer and such stuff. Camera flyby plus serial screenshot function in one script.

Your script seem to look like the flythrough.lua and also modification to the node. I understand the node modifications but not how to integrate your flythorugh.lua into my script which creates the renderbuffer and so on.

 

Thats the point I still don't get. :)

Pure3d Visualizations Germany - digital essences

AAA 3D Model Shop specialized on nature and environments

Link to comment
Share on other sites

what i posted was just the flythrough script with the small modification i made... your script is just the flythrough script with an extra couple of buffers and some code to take screenshots... but for what you are wanting with the fixed camera, it applies to both...

 

Find this line in your script:

fw.main.camera:AlignToVector(t,3,0.05*1.0)

 

and replace it with this:

        --'Edited here to check whether camera should be at fixed angle or'
       --'interpolated between the two nodes rotation values'
       if currentnode:GetKey("fixed")=="1" then
               fw.main.camera:SetRotation(currentnode.rotation,1)
       else
               fw.main.camera:AlignToVector(t,3,0.05*AppSpeed())
       end

 

And change the info_camera_node.lua script to what i showed above.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Okay I set it up and it helps but the path is just a zig-zag from node to node.

But the camera is aimed to the rotation I've set.

 

Is there a way to get rid of the zig-zag course? I played with

 

local tension=EntityDistance(currentnode,nextnode)*0.5

 

which reduces the zig-zag but its acting wired if a new node is reached.

Pure3d Visualizations Germany - digital essences

AAA 3D Model Shop specialized on nature and environments

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...