Game Development Community

Multiple Viewports

by Melv May · 02/24/2002 (10:28 pm) · 26 comments

Download Code File

Hi folks,

Dunno if anyone is interested but here is a copy of my guiViewport which is fairly basic at the moment. It allows you to render (after a selected rotation around the player camera) a view.

If you know of a better way of doing this then I would appreciate any advice you could give.

I've only done a single rotation around the 'Up' vector but it's simple to mod it. You could even setup a GOD view using it with minor changes. Watch out when adding multiple views as they can get VERY costly!!

Enjoy.

---------------------------------------

#include "sceneGraph/sceneGraph.h"
#include "game/gameConnection.h"
#include "console/consoleTypes.h"
#include "gui/guiTSControl.h"


class GuiViewport : public GuiTSCtrl
{
private:
typedef GuiTSCtrl Parent;

// View Rotation.
F32 mRotateView;

virtual void renderScene(const RectI &){};
void renderWorld(const RectI & updateRect);

public:
GuiViewport() : mRotateView(180.0f) {};

static void initPersistFields();
bool processCameraQuery(CameraQuery * query);
void setViewRotation(F32 Rotation);

DECLARE_CONOBJECT(GuiViewport);
};

//------------------------------------------------------------------------------

IMPLEMENT_CONOBJECT(GuiViewport);

//------------------------------------------------------------------------------

void GuiViewport::initPersistFields()
{
// Initialise parents' persistent fields.
Parent::initPersistFields();

// Add out own persistent fields.
addField( "ViewRotation", TypeF32, Offset( mRotateView, GuiViewport ) );
}

//------------------------------------------------------------------------------

void GuiViewport::setViewRotation(F32 Rotation)
{
// Set the Rotation internally.
mRotateView = Rotation;
}

//------------------------------------------------------------------------------

ConsoleMethod(GuiViewport,setViewRotation,void,3,3,"Sets View Rotation.")
{
F32 Rotation;

// Fetch the GuiViewport object.
GuiViewport *Viewport = static_cast(object);

// Convert RGB Ascii parms to float.
Rotation = dAtof(argv[2]);

// Set View Rotation.
Viewport->setViewRotation(Rotation);
}

//------------------------------------------------------------------------------

void GuiViewport::renderWorld(const RectI & updateRect)
{
// Set-up OpenGL for a scene render.
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glClear(GL_DEPTH_BUFFER_BIT);
glDisable(GL_CULL_FACE);
glMatrixMode(GL_MODELVIEW);
dglSetCanonicalState();

// Render Client Scene Graph.
gClientSceneGraph->renderScene();

// Disable Depth Test.
glDisable(GL_DEPTH_TEST);
}

//------------------------------------------------------------------------------

bool GuiViewport::processCameraQuery(CameraQuery * query)
{
Point3F CameraRotation(0, 0, mDegToRad(mRotateView)); // Rotated View.
float VisibleDistance = 1100.0f; // Visible Distance.


// Get Game Connection.
GameConnection* pConnection = dynamic_cast(NetConnection::getServerConnection());

// Did we get the connection?
if (pConnection)
{
// Yes, so get control camera transform.
if (pConnection->getControlCameraTransform(0.032, &query->cameraMatrix))
{
// Set Near/Far Planes.
query->nearPlane = 0.1;
query->farPlane = getMax(VisibleDistance, 50.f);

// Get existing Camera FOV.
pConnection->getControlCameraFov(&query->fov);

// Rotate Camera.
query->cameraMatrix.mul(MatrixF(CameraRotation));

// Return OK.
return(true);
}
}

// Return Error.
return(false);
}
Page «Previous 1 2
#1
02/24/2002 (10:43 pm)
Hey, that's brilliant!! Simple, but very effective - I like that one! Keep up the good work :-)
#2
02/25/2002 (3:45 pm)
Will this work for viewing from another object's perspective? A spy for instance. Could I use this to place cameras around, then view them in little windows while still controlling my player?
#3
02/26/2002 (12:46 am)
It could be modified to do so. You should be able to render the scenegraph from any camera transform.

I will look @ this for you and post the result here if you wish.
#4
02/26/2002 (1:35 pm)
Wow. Really? That would be sweet.

I would get it and check it out myself, but right now I'm trying to fix something.
#5
03/03/2002 (6:06 am)
well.. besides the framrate drop from 55 to 32 after adding 1 small viewport, this is a cool feature. I am on a PIII 450 so, I guess the framedrop isn't that bad on newer PC's
#6
03/03/2002 (9:21 am)
I've got a new version of this control that now let's you target an object by name and shows you a viewpoint from it's position.

You can also set a fixed offset as well as have the viewpoint sweep multiple arcs in XYZ (like a security camera) over a specified time period.

You can also overlay a bitmap (with colour masking) to give different effects.

I will post it if you want.
#7
03/03/2002 (9:23 am)
Of course we want ... :-))
#8
03/03/2002 (12:36 pm)
I've posted it into resource AND into the private forum under "SDK Private Forums\Engine".

Enjoy.
#9
04/24/2002 (8:00 am)
I wanted to impliment a 'multi view' and while doing a search came across this guiViewPort.cc example code.

So i:
copied it over to the ..\engine\gui folder
added it to the in the workspace
and hit compile.
Taking from the feedback posted in the forum, this should be sufficient and should all work.

Please bear with me; im rather new to this ...

I think i seem to be missing something as i find it to no avail to get it working.
Would it be possible for someone to direct me to a "HOWTO" or perhaps equip me with more detail on how to use this guiViewPort.cc file

The most ive done with the Torque stuff was messing about with the scripts and this is my first go at compiling the engine. Though id like to think that i have a strong C++ background, this somehow eludes me.

Quite frankly, im rather lost :(
Thanking in advance
#10
04/24/2002 (10:46 am)
Hi,

Have you added it to one of your GUI's yet then?

Melv.
#11
04/25/2002 (1:01 am)
Umm ok we got it working now thanks :) and we really appreciate your prompt reply :)
we just had to rebuild the entire thing :)
#12
04/25/2002 (1:21 am)
Umm ok we got it working now thanks :) and we really appreciate your prompt reply :)
we just had to rebuild the entire thing :)
#13
04/25/2002 (6:57 am)
when rotate right or left, the view seems to get stretch. Is there anyway to solve it?
#14
04/25/2002 (8:53 am)
Are you using a large field of view? Too large and you will get a distorted field.
#15
04/25/2002 (12:37 pm)
me again :) just wondering what I would need to change to offset the camera location a little, e.g. I want the camera to be looking AT the player not originating from the player.. but keeps moving with the player that is, so I thought if I could offset it back a little it could do the trick.. but I'm not sure how to transform the camera matrix and where to do it exactly..
could u please help me?

Thanks in advance..
#16
04/25/2002 (12:46 pm)
Try this ...

www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2304

It's a little more powerful. It was not designed to be a third person camera. You will need to look elsewhere if that's what you want.

- Melv.
#17
04/29/2002 (1:32 am)
hi,
just wondering what is the suitable fov to use
#18
04/29/2002 (8:48 am)
Err ... it would depend on what you want? I believe 90 degrees is the Torque camera default.

The player camera is restricted by default to the range of 5-120 degrees.

- Melv.
#19
06/16/2003 (8:08 am)
can anyone tell me where i need to embed this file "guiviewport.cc" in torue.
what changes do i need to make? im completely new to torque(also to game engines) , so please i may need more explanation.

thanks to u all
#20
02/21/2006 (5:47 am)
I've implemented this resource but just can't get it to select the object I'm trying to use. Actually, I can't get it to select any object and my alternate view when tabed is just a read box giving me the "Object Not Selected" error line. This would be a great resource for me if someone can help me get out of the nasty read box. Thanks !
Page «Previous 1 2