About Store Forum Documentation Contact
Donations:
140$/mo



Post Reply 
viewport and gui question
Author Message
craksy Offline
Member

Post: #1
viewport and gui question
ok i have made a gui object containing a viewport, and i have some problems with the camera.
i just have the single viewport, and i set the render function like this:
Code:
void Render(GuiViewport &viewport){

    D.clear(BLACK);
    SetMatrix(MatrixIdentity);
    Box(1, Vec(0,0,0)).draw(WHITE);
    cam1.set();
    
}
now, the viewport works fine, but the scene also uses the "cam1" camera instead of just the standart "Cam".
so how do i set the scene to go back to "Cam" when the viewport is done rendering?
i tried putting Cam.set() different places but nothing worked :/


And another question: Are there any way to "clear" the Gui?
if i load a gui object in my game state, and return to my menu, it still has the gui object from my game state loaded (odd enough not the other way around whith the menu gui).
anyway, i want to know if i can clear the Gui in the Shut() function, so i have a fresh gui when entering a new state.

thanks in advance smile

-Craksy
10-30-2009 10:34 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: viewport and gui question
when you call Camera::set then it's being copied to 'Cam' (I think this is mentioned in the 'set' method), so you can't restore the Cam, but you need to use cam1.set and cam2.set (use multiple cameras)

'Cam' is always the active camera

you don't "clear" gui, but just hide it (or delete it), GuiObj::hide,del
10-30-2009 10:40 PM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #3
RE: viewport and gui question
ok so i basically want to change all my Cam setting from Cam to cam2, or something like that, and then switch between cam1, and cam2?

so i can just do GuiObj::del() in the Shut() function, and it will reload again in the Init() function next time i enter the state?

thanks for helping smile
10-30-2009 11:23 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: viewport and gui question
yes
10-30-2009 11:26 PM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #5
RE: viewport and gui question
now i got some other problems...
i did this in my render function:
Code:
void Render(GuiViewport &viewport){

    cam2.set();
    D.clear(BLACK);
    SetMatrix(MatrixIdentity);
    Box(1, Vec(0,0,0)).draw(GREEN);
    cam1.set();
}

setting cam2 (my viewport cam) at the start of the render, and setting it back to cam1 at the end of the render function.
it works fine, but the input is messed up now.
the cam handles (rotate and zoom) is "stuck", and matrix is acting weird, like Y and Z has switched places :S

what did i do wrong?
10-30-2009 11:54 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
RE: viewport and gui question
camhandle operates on Cam

cam1.set();
camhandle();
cam1=Cam;
10-31-2009 12:00 AM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #7
RE: viewport and gui question
works now grin

thanks a lot smile
10-31-2009 12:17 AM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #8
RE: viewport and gui question
another quick question:
i tried putting the inventory stuff into its own .cpp file to make it more clean.
it looks like this:
Code:
Inventory::Inventory()
{

    if(invGui_objs.load("gui/obj/inventory.gobj")){
        Gui+=invGui_objs;
        
        vp = invGui_objs.getViewport("item_vp");
    }

    vpCam.dist = 10;
    vpCam.at = Vec(0, 0, 0);
    vp->draw_func = &Inventory::Render;

}

void Render(GuiViewport &viewport){

    vpCam.set();
    D.clear(BLACK);
    SetMatrix(MatrixIdentity);
    Box(1, Vec(0,0,0)).draw(GREEN);
    cam1.set();
}

now i got the following errors:

error C2440: '=' : cannot convert from 'void (__thiscall Inventory::* )(EE::GuiViewport &)' to 'void (__cdecl *)(EE::GuiViewport &)'
error C2065: 'vpCam' : undeclared identifier
error C2228: left of '.set' must have class/struct/union type is ''unknown-type''
error C2065: 'cam1' : undeclared identifier
left of '.set' must have class/struct/union type is ''unknown-type''


ok i know that the cam1.set() line is probably giving me an error becaause it's declared in my gamestate, but how do i fix that? :/
and what about the others? vpCam is created in the class... why does it say "undeclared" ? :S
and to be honest, i don't really understand the error message for setting the draw function... what does __thiscall, and __cdecl mean? :S

anyway i hope you can help me smile
10-31-2009 11:35 AM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #9
RE: viewport and gui question
please... anyone?
11-01-2009 12:31 PM
Find all posts by this user Quote this message in a reply
lovee Offline
Member

Post: #10
RE: viewport and gui question
(!*Just my view, is not necessarily correct*!)
error C2440:
The first instance of an object(GuiViewport myGuiVP = new GuiViewPortwink
error C2065: 'vpCam'
Cam vpCam = new vpCam;
error C2228: left of '.set'
Not declaration vpCam data type (or say no in the variable within the scope), vpCam certainly did not "set" method
error C2228 AND error C2065 same error vpCam
11-01-2009 03:26 PM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #11
RE: viewport and gui question
i'm not sure i understand :/
sorry, but could you try to explain it further?

thanks smile
11-02-2009 06:09 PM
Find all posts by this user Quote this message in a reply
Mikesanimation Offline
Member

Post: #12
RE: viewport and gui question
Quote:vpCam is created in the class... why does it say "undeclared" ? :S

Is this all of your code that you listed in the one .cpp file?
Because what lovee is literally saying to fix the error C2065: 'vpCam' you need to give your vpCam a type, hence:
Cam vpCam = new vpCam;
11-04-2009 07:02 AM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #13
RE: viewport and gui question
of cause not... i have the rest in a header...
here is all of the code:

inventory.h
Code:
struct Inventory
{
    GuiObjs invGui_objs;
    GuiViewport *vp;
    Camera vpCam;

    void Render(GuiViewport &viewport);
    
    Inventory();
};

inventory.cpp
Code:
#include "stdafx.h"
#include "Main.h"

Inventory::Inventory()
{

    if(invGui_objs.load("gui/obj/inventory.gobj")){
        Gui+=invGui_objs;
        
        vp = invGui_objs.getViewport("item_vp");
    }
    
    vpCam = new Camera();

    vpCam.dist = 10;
    vpCam.at = Vec(0, 0, 0);
    vp->draw_func = &Inventory::Render;

}

void Render(GuiViewport &viewport){

    vpCam.set();
    D.clear(BLACK);
    SetMatrix(MatrixIdentity);
    Box(1, Vec(0,0,0)).draw(GREEN);
    cam1.set();
}
11-04-2009 02:27 PM
Find all posts by this user Quote this message in a reply
Xhizors Offline
Member

Post: #14
RE: viewport and gui question
void Render(GuiViewport &viewport) is not a member of the Inventory structure, that's why vpCam / vp->draw_func = &Inventory::Render is undeclared members.

Do like.

Code:
struct Inventory
{
    GuiObjs invGui_objs;
    GuiViewport *vp;
    Camera vpCam;

    Inventory();
};

#include "stdafx.h"
#include "Main.h"

Inventory *pInventory = new Inventory();

Code:
void Render(GuiViewport &viewport)
{
    pInventory->vpCam.set();             // Set the structure camera vpCam.
    D.clear(BLACK);
    SetMatrix(MatrixIdentity);
    Box(1, Vec(0,0,0)).draw(GREEN);
    cam1.set();
}

Inventory::Inventory()
{

    if(invGui_objs.load("gui/obj/inventory.gobj")){
        Gui+=invGui_objs;
        
        vp = invGui_objs.getViewport("item_vp");
    }
    
    vpCam = new Camera();

    vpCam.dist = 10;
    vpCam.at = Vec(0, 0, 0);
    vp->draw_func = Render;  // Set our render function.
}
(This post was last modified: 11-06-2009 08:23 AM by Xhizors.)
11-06-2009 08:22 AM
Find all posts by this user Quote this message in a reply
lovee Offline
Member

Post: #15
RE: viewport and gui question
"inventory.h" -> this is header file
"inventory.cpp" -> this is Implementation file
so "inventory.cpp" file need -> #include "inventory.h"
11-08-2009 04:17 AM
Find all posts by this user Quote this message in a reply
Post Reply