Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Colonol Dekker on September 01, 2008, 10:18:45 pm

Title: Feature request - rear view (WC3/4 style)
Post by: Colonol Dekker on September 01, 2008, 10:18:45 pm
For anyone not lucky enough to play this yet, the hud mfd could be toggled to show a rear view. Any possibility in a future build? (For low spec pc's would it be possible to make it use lower lods?)
Title: Re: Feature request - rear view (WC3/4 style)
Post by: chief1983 on September 01, 2008, 11:01:25 pm
Like a reverse camera in new cars?
Title: Re: Feature request - rear view (WC3/4 style)
Post by: Colonol Dekker on September 02, 2008, 08:13:58 am
Yes :) but toggleable.
(Can't believe that pimp my ride ripped off the confederation :lol: )
Title: Re: Feature request - rear view (WC3/4 style)
Post by: Flaser on September 02, 2008, 07:36:47 pm
Nuke already implemented something similar and more.
Using scripts and rtt he made a turret display and even an input method to control said turret.
He could easily make your rear-camera...


....now if only people helped him test the darn things!
Title: Re: Feature request - rear view (WC3/4 style)
Post by: Colonol Dekker on September 02, 2008, 07:42:06 pm
I'd be happy to.
Just point towards a "how to" :)
Title: Re: Feature request - rear view (WC3/4 style)
Post by: Nuke on September 03, 2008, 12:04:36 am
i havent checked the state of rtt at all lately. it might not work anymore. then again it might work uber cool :D
Title: Re: Feature request - rear view (WC3/4 style)
Post by: WMCoolmon on September 04, 2008, 03:54:16 am
Tested, looks great. :)

The default key to turn it on and off is "Alt-v"

Code: [Select]
#Conditional Hooks
$Application: Freespace 2
$On Mission Start: [
if not g_RVTexture then
--Switch to turn rearview on and off
g_RVEnabled = false

--HUD gauge info
g_RVHUDLabel = "Rear view"
g_RVHUDXPos = 100
g_RVHUDYPos = 200

--Texture/camera preferences (must be power of 2
g_RVTextureWidth = 256
g_RVTextureHeight = 256

--Default texture and camera instances for rearview camera
g_RVTexture = gr.createTexture(g_RVTextureWidth, g_RVTextureHeight)
g_RVCamera = gr.createCamera("Rear view")
end
]

$Application: Freespace 2
$State: GS_STATE_GAME_PLAY
$Keypress: Alt-v
$On Key Released: [
g_RVEnabled = not g_RVEnabled
]

$Application: Freespace 2
$State: GS_STATE_GAME_PLAY
$On HUD Draw: [
local ship = hv.Self
if g_RVEnabled and ship and ship:isValid() then
--Lock to current ship
g_RVCamera.Self = ship

--Get current ship position/orientation
local pos = ba.newVector(0, 0, 0)
local ori = ba.newOrientation(0, 0, 0)

--Set camera to back of ship
pos.z = ship.Class.Model.BoundingBoxMin.z
g_RVCamera.Position = pos

--Set camera to reverse of ship orientation
ori.h = math.pi
g_RVCamera.Orientation = ori

--Set camera to be current camera, render, reset
gr.setCamera(g_RVCamera)
gr.CurrentRenderTarget = g_RVTexture
gr.clearScreen()
mn.renderFrame()
gr.CurrentRenderTarget = nil
gr.setCamera()

--TODO: Save previous camera and
--set previous camera when done

--Set HUD color
gr.setColor(0, 255, 0)

--Show a hud label
gr.drawString(g_RVHUDLabel, g_RVHUDXPos, g_RVHUDYPos)

--Offset the texture/box appropriately and draw them
local x = g_RVHUDXPos
local y = g_RVHUDYPos+gr.CurrentFont.Height
gr.drawImage(g_RVTexture, x, y)
gr.drawRectangle(x, y, x+g_RVTextureWidth, y+g_RVTextureHeight, false)
end
]
#End

EDIT: Requires C09032008 build to work. I will be changing that "camera.Self" thing to "camera.Host" to match it with the SEXP jargon, but that should be a quick search-and-replace when it happens. Also, I'll add a current camera variable so this won't screw up cutscenes using the camera code.
Title: Re: Feature request - rear view (WC3/4 style)
Post by: Colonol Dekker on September 04, 2008, 04:39:47 am
 :D Great :yrd:


I'll wait until you do those things that i don't understand before i DL and try it just so i don't have to DL two .exe's. Thanks WMCoolman.
Title: Re: Feature request - rear view (WC3/4 style)
Post by: karajorma on September 07, 2008, 01:18:23 am
I will be changing that "camera.Self" thing to "camera.Host" to match it with the SEXP jargon

:confused:

The only time I've noticed the word host used in the code is to denote the first player to join a multiplayer server (Which is the player hosting the server except for standalones).
Title: Re: Feature request - rear view (WC3/4 style)
Post by: WMCoolmon on September 08, 2008, 05:54:01 am
That's still not what I used for the SEXP. I'm open to suggestions.
Title: Re: Feature request - rear view (WC3/4 style)
Post by: karajorma on September 08, 2008, 07:31:07 am
I'm not saying host is a bad choice, just that I've never seen it used in that context. Is there another SEXP that uses host?
Title: Re: Feature request - rear view (WC3/4 style)
Post by: WMCoolmon on September 08, 2008, 04:43:33 pm
Not besides set-camera-host, according to my SEXPs.html from 9/4.
Title: Re: Feature request - rear view (WC3/4 style)
Post by: karajorma on September 08, 2008, 04:59:54 pm
Ah. I get you now. :)