Exemple #1
0
	void GLUTGame::Reshape(int width, int height)
	{
		glViewport(0, 0, width, height);
		if (m_is2D)
			gluOrtho2D(0, 1, 1, 0);
		else
			UpdatePerspective(camera.FOV);
	}
Exemple #2
0
//---------------------------------------------------------------------------
void CFabAtHomeView::OnSize(UINT nType, int cx, int cy) 
//---------------------------------------------------------------------------
{	
	CView::OnSize(nType, cx, cy);
	
    if(cy > 0) {    
		
		wglMakeCurrent(m_pDC->GetSafeHdc(), hrc);
		
        glViewport(0, 0, cx, cy);
		
        if((m_oldRect.right > cx) || (m_oldRect.bottom > cy))
            RedrawWindow();
		
        m_oldRect.right = cx;
        m_oldRect.bottom = cy;
		
		UpdatePerspective();
    }
}
Exemple #3
0
int main(int argc, char *argv[])
{
    // Engine init
    ENGINE_INIT(argc, argv);
    MapName="terrain_map.xml";
    look_in_mouse=false;
    k_MouseClick=false;
    if (!ENGINE)
    {
        fprintf(stderr,"Can't load main Engine module! Exiting...\n");
        return 1;
    };
    printf("Welcome to AmberSkyNet ( %s %d )\n",__FILE__,__LINE__);
    // Load world
    FILER->AddPath("samples/TerrainTest/", false);
    ENGINE->LoadDataFile(MapName.c_str());
    myWorld = ENGINE->GetWorld();
    if (!myWorld) {
        printf("Can't get world! Exiting... :(\n");
        return 1;
    };
    printf("World loaded.\n");
    // Camera
    myCam = myWorld->GetCamera( myWorld->AddCamera("CameraSimple") );
    myCam->SetScreen(0,0,1,1/*0.5*/);
    // ?
    FOV=initFOV;
    UpdatePerspective();
    // Camera Walker listener
    IEventListener *myList = EVENTER->AddEventListener( "EvListCamWalker" );
    if (!myList)
    {
        printf("Class EvListCamWalker can't found :(\n");
        return 1;
    }
    myList->SetPtrParam("Camera",myCam);
    myList->SetParam("step", camStep);
    printf("Camera walker created.\n");
    // Camera Looker listener
    myList = EVENTER->AddEventListener( "EvListCamLooker" );
    if (!myList)
    {
        printf("Class EvListCamWalker can't found :(\n");
        return 1;
    }
    myList->SetPtrParam("Camera",myCam);
    printf("Camera looker created.\n");
    // Camera position
    myCam->SetPos( CVector(5,128,0) );
    myCam->SetRotY( 0 );
    // Search terrains
    myWorld->FindChildrenByInterface("ASNITerrain", &Terrains);
    for (int i=0; i<Terrains.nums; i++)
        TerrainInterfaces.push_back((ASNITerrain*)(Terrains.getItem(i)->GetInterface("ASNITerrain")));
    // ?
    int evt;
    bool non_exit=true;

    ENGINE->SetPtrParam("UpdateCallback",(void*)UpdateCallback);
    ENGINE->SetPtrParam("DrawCallback",(void*)DrawCallback);
    // Main loop
    ENGINE->EngineStart();
    // End of work
    clearPtrList(&Terrains);
    printf("----End----\n");

    return 0;
};
Exemple #4
0
// Update-функция, если возвратит true- произойдет выход из цикла Engine
int UpdateCallback(void *Params)
{
    groundMoveLock();
    // Read first event
    int evt=EVENTER->GetInput();

    // цикл - пока не прочитали все события
/*LOGGER->LogMsg("UpdateCallback evt cycle begin");*/
    while (evt!=ASN_EVNT_EMPTY)
    {
        if (evt==ASN_MOUSE_WHEEL_UP) {
            FOV+=FOVStep;
            UpdatePerspective();
        }
        else if (evt==ASN_MOUSE_WHEEL_DOWN) {
            FOV-=FOVStep;
            UpdatePerspective();
        }

        if (evt==ASN_EVNT_KEYPRESSED)
        { //если событие - нажатие клавиши, то...
            // если мы нажали Esc - устанавливаем признак выхода в true
            if (EVENTER->GetLastKey()==27)
            {
                return true;
            }
            else if (EVENTER->GetLastKey()==ASNK_SPACE) {  gravity_on=!(gravity_on);/*LoadMap(); ProceedCustomMap(); UploadCustomMap();*/ }

            if (EVENTER->GetLastKey()==ASNK_F5) {
                printf("SaveWorld\n");
                std::string worldFilePath=std::string(ENGINE->GetEnvParam("[Paths]DataPath"))+"World.xml";
                ENGINE->SaveDataFile(worldFilePath.c_str());
                }

            if (EVENTER->GetLastKey()==ASNK_F6) {
                printf("LoadWorld\n");
                ENGINE->LoadDataFile("World.xml");
                myWorld = ENGINE->GetWorld();
                }


            // если мы нажали PrtSrc - делаем скриншот с именем screenshotXXX
            else
            if (EVENTER->GetLastKey()==316)
            {
                DEVICER->MakeScreenshot("screenshot");
                printf("Shoot!\n");
            }
            // Нажатие табуляции - захват/освобождение мыши
            else
            if (EVENTER->GetLastKey()==9)
            {
                look_in_mouse=!look_in_mouse;
                DEVICER->CenterMouse(!look_in_mouse);
            }
            // Ирригация и мелиорация
            else
            if ((EVENTER->GetLastKey()==ASNK_KP_PLUS)||
            (EVENTER->GetLastKey()==ASNK_KP_MINUS))
            {
                //beep();
                for (UINT i=0; i<Terrains.nums; i++){
                    INode *n = Terrains.getItem(i);
                    double currentHeight = n->GetDoubleParam("WaterHeight");
                    if (EVENTER->GetLastKey()==ASNK_KP_PLUS)
                        currentHeight+=waterStep;
                    else
                        currentHeight-=waterStep;
                    n->SetParam("WaterHeight", currentHeight);
                };
            }
            // Гравитация
            else
            if (EVENTER->GetLastKey()=='g')
            {
                gravity_on = !gravity_on;
            }
        }

        else if (evt==ASN_EVNT_MOUSEDOWN)
        {
            k_MouseClick=true;
            //FindMousePointer(DEVICER->mouse_x,DEVICER->mouse_y);
        }
        evt=EVENTER->GetInput();
    }

    LOGGER->LogMsg("UpdateCallback evt cycle end");

    return false;

};
Exemple #5
0
bool CRenderer::Init(int width, int height, int bpp, int fullscreen)
{
    m_width = width;
    m_height = height;

    UpdatePerspective();
    glLoadIdentity(); // identity for modelview matrix

    // Vertex Lighting
    float mat_specular[] = {1,1,1,1};
    float mat_shininess[] = { 50 };
    float mat_diff[] = { 0.5f, 0.5f, 0.5f, 1.0f };
    float light_pos[] = { 0, 1, 1, 1 };
    float white_light[] = {1,1,1,1};
    float lmodel_ambient[] = { 0.8f, 0.8f, 0.8f, 1.0f };

    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diff);
    glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
    glLightfv(GL_LIGHT0, GL_SPECULAR, white_light);
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);

    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);

    if(m_shaderactive)
    {
        bool shader = InitShader();
        if(!shader)
        {
            fprintf(stderr, "Init shader failed\n");
            return false;
        }
        fprintf(stderr, "GLSL shader loaded\n");

        if(!glewIsSupported("GL_EXT_framebuffer_object"))
        {
            fprintf(stderr, "No framebuffer support\n");
            m_useShadows = false;
        }

        if(m_useShadows && !CreateShadowFBO())
        {
            fprintf(stderr, "Init shadow mapping failed\n");
            m_useShadows = false;
        }
        else
        {
            fprintf(stderr, "Shadow mapping active\n");
        }
    }
    else
    {
        fprintf(stderr, "Shader disabled\n");
        m_useShadows = false;
    }

    // loading the crosshair
    std::string pathcross = CLynx::GetBaseDirTexture() + "crosshair.tga";
    m_crosshair = m_world->GetResourceManager()->GetTexture(pathcross);
    if(m_crosshair == 0)
        fprintf(stderr, "No crosshair found: %s\n", pathcross.c_str());
    m_world->GetResourceManager()->GetTextureDimension(pathcross,
             &m_crosshair_width, &m_crosshair_height);
    // loading the font
    if(!m_font.Init("font.png", 16, 24, m_world->GetResourceManager()))
        return false;

    return true;
}
Exemple #6
0
void CRenderer::PrepareShadowMap(const vec3_t& lightpos,
                                 const quaternion_t& lightrot,
                                 CWorld* world, int localctrlid)
{
    CFrustum frustum;
    vec3_t dir, up, side;
    matrix_t mviewlight;
    mviewlight.SetCamTransform(lightpos, lightrot);

    mviewlight.GetVec3Cam(&dir, &up, &side);
    dir = -dir;
    frustum.Setup(lightpos, dir, up, side,
                  RENDERER_FOV, (float)m_width/(float)m_height,
                  PLANE_NEAR,
                  PLANE_FAR);
    glViewport(0, 0, (int)(m_width * SHADOW_MAP_RATIO),
                     (int)(m_height * SHADOW_MAP_RATIO));
    float projection[16];
    glMatrixMode(GL_PROJECTION);
    // Shadow mapping with ortho projection can be useful
    //const float lightDistance = PLANE_FAR*0.1f;
    //glLoadIdentity();
    //glOrtho(-35.0f, 35.0f, -35.0f, 35.0f, 0.0f, PLANE_FAR*0.1f); // dimension: light area in m
    glGetFloatv(GL_PROJECTION_MATRIX, projection);
    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixf(mviewlight.pm); // set camera to light pos

    glMatrixMode(GL_TEXTURE);
    glActiveTexture(GL_TEXTURE7);
    glLoadMatrixf(g_shadowBias); // to map from -1..1 to 0..1
    glMultMatrixf(projection);
    glMultMatrixf(mviewlight.pm);
    glMatrixMode(GL_MODELVIEW);

    // Render to FBO
    glBindFramebuffer(GL_FRAMEBUFFER, m_fboId);
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    glDisable(GL_LIGHTING);
    glDisable(GL_BLEND);
#ifndef DRAW_SHADOWMAP
    glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
#endif
    //glCullFace(GL_FRONT);
    glPolygonOffset( 1.1f, 4.0f );
    glEnable(GL_POLYGON_OFFSET_FILL);

    DrawScene(frustum, world, localctrlid, true);

    glDisable(GL_POLYGON_OFFSET_FILL);

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    glViewport(0, 0, m_width, m_height);
#ifndef DRAW_SHADOWMAP
    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
#endif
    //glCullFace(GL_BACK);
    glEnable(GL_LIGHTING);
    glEnable(GL_BLEND);

    UpdatePerspective(); // restore standard projection
}
Exemple #7
0
void View::Update () {
    UpdatePerspective();
    damage->Repair();
}