About Store Forum Documentation Contact



Post Reply 
Code. View coordenates screen and custom configuration
Author Message
kaito Offline
Member

Post: #1
Code. View coordenates screen and custom configuration
So we can begin to develop a game knowing the position and other parameters, or how they are distributed in different parts of the screen game.

Code in spanish: <!-- m --><a class="postlink" href="http://mundovilla.foroactivo.es/foro/viewtopic.php?p=363#363">http://mundovilla.foroactivo.es/foro/vi ... ?p=363#363</a><!-- m -->

Keys used:

Arrow keys: To modify parameters
+, - NumPad: To increase and decrease increment
TAB, SPACEBAR: To change selection
-
[Image: captura2.png]
-
Code:
/******************************************************************************/
#include "stdafx.h"  

/******************************************************************************/

I8 imenu1(0),imenu2(0);  // Save menu selected

Bool bMostrar[7]={false};  // Save Show/Hide option

Flt fEjeX(0),fEjeY(0),fEjeZ(0),      // Generic variables
    fIncremento(0.5);

Mesh meshMalla;     // Mesh variables
Matrix matrixMalla=Vec(0,0,0);
Flt fMallaRotX(0),fMallaRotY(0),fMallaRotZ(0),
    fMallaEscX(1),fMallaEscY(1),fMallaEscZ(1);

Window wVentana;   // Window variables
Vec2 posVentana;

Gfx gfxImagen;    // Image variables
Vec2 posImagen=(0,0);
Flt fanchoImagen(0.5),faltoImagen(0.5);

Char8 cTexto[256]="0123456789";   // Text variables
Vec2 posTexto=(0,0), aliTexto=(0,0);
Flt fEscTexto(0.2);

Sun *sun;

void CrearTexto (Char8 *vpuntero, U16 cadena) {  // MakeText function
    for (int i=0; i<cadena; i++) {
        switch (i%10) {
            case 0 : *vpuntero='0'; break;
            case 1 : *vpuntero='1'; break;
            case 2 : *vpuntero='2'; break;
            case 3 : *vpuntero='3'; break;
            case 4 : *vpuntero='4'; break;
            case 5 : *vpuntero='5'; break;
            case 6 : *vpuntero='6'; break;
            case 7 : *vpuntero='7'; break;
            case 8 : *vpuntero='8'; break;
            case 9 : *vpuntero='9';
        }
        ++vpuntero;
    }
    *vpuntero='\0';
}


/******************************************************************************/
void InitPre()
{
   App.name("Taller");
   IOPath("../data/");
   PakAdd("../data/engine.pak");

   D.full(true).ambPower(0.3).hpRt(true).hwDepthBuffer(true);
}
/******************************************************************************/
Bool Init()
{
    meshMalla.load("Obj/item/misc/barrel/0.mesh");

    Gui+=wVentana.create(Rect(-0.2,0, 0.2,0.2));
    posVentana=wVentana.pos();

    gfxImagen.Import("logo.png",-1,GFX_2D);
    
    Water.set(*Gfxs("gfx/water/0.gfx"),*Gfxs("gfx/water/0.n.gfx"),Gfxs("gfx/fx/reflection.gfx"));
    Water.plane(Water.plane()+ Vec(0,-3,0));    // down water
    Water.color.set(0,0,0);   // Hide water, set color black
    Water.reflect_fake=0;     // and hide reflect

    Sun &sol=Suns.New();
             sun=&sol;
             sun->set(*Gfxs("gfx/sky/sun.gfx"));
    sun->light_color.set(0);   // Hide sun
             sun->gfx_color=0;
             sun->rays.color.set(0);

    Sky.set(Vec(0,0,0),Vec(0,0,0));   // Hide Sky, set color black

    bMostrar[0]=true;

    Cam.matrix.pos+=Cam.matrix.z*-6; Cam.matrix.pos+=Cam.matrix.y*1; Cam.pitch=-0.1f;  // Custom camera
    Cam.setAngle(Cam.matrix.pos,Cam.yaw,Cam.pitch,Cam.roll).updateVelocities().​set();


    return true;
}
/******************************************************************************/
void Shut()
{

}
/******************************************************************************/
Bool Main()
{
    if (Kb.bp(KB_ESC)) {return false;}

    if (Kb.br(KB_TAB)) {++imenu1; return true;}
    if (Kb.br(KB_SPACE)) {++imenu2; return true;}
    if ((Kb.br(KB_ENTER)) && (imenu1<7))    {
                            switch (imenu1){
                                            case 4: if (bMostrar[4]) {Water.color.set(0,0,0); Water.reflect_fake=0;}
                                                    else {Water.color.set(0.4,0.5,0.6); Water.reflect_fake=0.3;}
                                                    break;
                                            case 5: if (bMostrar[5]) {sun->light_color.set(0); sun->gfx_color=0; sun->rays.color.set(0);}
                                                    else {sun->light_color.set(1); sun->gfx_color=WHITE; sun->rays.color.set(0.18,0.18,0.18);}
                                                    break;
                                            case 6: if (bMostrar[6]) {Sky.set(Vec(0,0,0),Vec(0,0,0));}
                                                    else Sky.set();
                                            }
                            bMostrar[imenu1]=(!(bMostrar[imenu1]));
                            }

    if ((imenu1==1) && (bMostrar[1])) {Gui.update();}
    if (bMostrar[4]) {Water.update(Vec2(0.2,0.2));}

    if (Kb.br(KB_NPSUB)) if (fIncremento>0.0125) {fIncremento-=0.0125; return true;}
    if (Kb.br(KB_NPADD)) if (fIncremento<1.5) {fIncremento+=0.0125; return true;}
    if ((Kb.br(KB_UP)) && (Kb.b(KB_LCTRL))) {fEjeZ+=fIncremento;} else if (Kb.br(KB_UP)) {fEjeY+=fIncremento;}
    if ((Kb.br(KB_DOWN)) && (Kb.b(KB_LCTRL))) {fEjeZ-=fIncremento;} else if (Kb.br(KB_DOWN)) {fEjeY-=fIncremento;}
    if (Kb.br(KB_LEFT)) {fEjeX-=fIncremento;}
    if (Kb.br(KB_RIGHT)) {fEjeX+=fIncremento;}    
    if ((fEjeX+fEjeY+fEjeZ)==0) {return true;}


    switch (imenu1)
    {

        case 0 :    {
                    switch (imenu2) {
                                    case 0 :    {
                                                matrixMalla.pos=Vec(matrixMalla.pos.x+fEjeX,matrixMalla.pos.y+fEjeY,matrixM​alla.pos.z+fEjeZ);
                                                break;
                                                }
                                    case 1 :    {
                                                matrixMalla.rotateXY(fEjeX,fEjeY); matrixMalla.rotateZ(fEjeZ);
                                                fMallaRotX+=fEjeX; fMallaRotY+=fEjeY; fMallaRotZ+=fEjeZ;
                                                break;
                                                }
                                    case 2 :    {
                                                matrixMalla.scale(Vec(1+fEjeX,1+fEjeY,1+fEjeZ));
                                                fMallaEscX+=fEjeX; fMallaEscY+=fEjeY; fMallaEscZ+=fEjeZ;
                                                }
                                    }
                    break;
                    }

        case 1 :    {
                    switch (imenu2)    {
                                    case 0 : posVentana+=Vec2(fEjeX,fEjeY); wVentana.pos(posVentana); break;
                                    case 1 : wVentana.resize(Vec2(fEjeX,fEjeY));
                                    }
                    break;
                    }

        case 2 :    {
                    switch (imenu2)    {
                                    case 0 : posTexto+=Vec2(fEjeX,fEjeY); break;
                                    case 1 : fEscTexto+=(fEjeX+fEjeY); break;
                                    case 2 :    {
                                                aliTexto=Vec2(Sign(fEjeX)+aliTexto.x,Sign(fEjeY)+aliTexto.y);
                                                if (aliTexto.x<-1) {aliTexto.x=-1;}
                                                if (aliTexto.x>1) {aliTexto.x=1;}
                                                if (aliTexto.y<-1) {aliTexto.y=-1;}
                                                if (aliTexto.y>1) {aliTexto.y=1;}
                                                break;
                                                }
                                    case 3 :    {
                                                U16 local=Length(cTexto);
                                                if ((Sign(fEjeX+fEjeY)>0) && (local<255)) {++local;}
                                                if ((Sign(fEjeX+fEjeY)<0) && (local>0)) {--local;}
                                                CrearTexto(cTexto,local);
                                                }
                                    }
                    break;
                    }
        case 3 :    {
                    switch (imenu2)    {
                                    case 0 : posImagen+=Vec2(fEjeX,fEjeY); break;
                                    case 1 : fanchoImagen+=fEjeX; faltoImagen+=fEjeY;
                                    }
                    break;
                    }

        case 4 :    {
                    switch (imenu2) {
                                    case 0 : Water.plane(Water.plane()+ Vec(0,fEjeY,0)); break;
                                    case 1 : if (((Water.density+fEjeX+fEjeY)>0) && ((Water.density+fEjeX+fEjeY)<=1)) Water.density+=(fEjeX+fEjeY); break;
                                    case 2 : if (((Water.reflect+fEjeX+fEjeY)>0) && ((Water.reflect+fEjeX+fEjeY)<=1)) Water.reflect+=(fEjeX+fEjeY); break;
                                    case 3 : if (((Water.specular+fEjeX+fEjeY)>0) && ((Water.specular+fEjeX+fEjeY)<=1)) Water.specular+=(fEjeX+fEjeY); break;
                                    case 4 : if (((Water.wave_scale+fEjeX+fEjeY)>0) && ((Water.wave_scale+fEjeX+fEjeY)<=1)) Water.wave_scale+=(fEjeX+fEjeY);
                                    }
                    break;
                    }
        case 7 :    {
                    switch (imenu2)    {
                                    case 0 : Cam.matrix.pos+=(Cam.matrix.x*fEjeX)+(Cam.matrix.y*fEjeY)+(Cam.matrix.z*fEjeZ); break;
                                    case 1 : Cam.pitch+=fEjeY; break;
                                    case 2 : Cam.yaw+=fEjeX; break;
                                    case 3 : Cam.roll+=fEjeX;
                                    }
                    Cam.setAngle(Cam.matrix.pos,Cam.yaw,Cam.pitch,Cam.roll).updateVelocities().​set();
                    }                    
    }

    fEjeX=fEjeY=fEjeZ=0;



    return true;
}
/******************************************************************************/
void Render()
{
   switch(Renderer())
   {

   case RM_SOLID : case RM_SOLID_M :  {
                        if (bMostrar[0]) {meshMalla.draw(matrixMalla);}
                        break;
                     }
    }
}

/******************************************************************************/
void Draw()
{
    if (imenu1>7) {imenu1=0;}

    switch (imenu1)
    {
        case 0 : if (imenu2>2) {imenu2=0;} break;
        case 2 : case 7 : if (imenu2>3) {imenu2=0;} break;
        case 4 : if (imenu2>4) {imenu2=0;} break;
        default : if (imenu2>1) {imenu2=0;}
    }
    
    Renderer(Render);

             if (bMostrar[3]) {gfxImagen.draw(posImagen,fanchoImagen,faltoImagen);}

    if (bMostrar[1]) {Gui.draw();}

    if (bMostrar[2])    {
                        TextDS taller;
                        taller.align.set(aliTexto.x,aliTexto.y);
                        taller.scale.set(fEscTexto);
                        taller.color=GREEN;
                        D.text(taller,posTexto,cTexto);
                        }


    TextDS estilo;
    estilo.align.set(1,0);
    estilo.scale/=1.7;

    switch ((int)(Tm.time())%2)
    {

        case 0 :    {
                    estilo.color=RED;
                    D.text(estilo,-1.3,0.9-imenu1*0.05,">>>");
                    D.text(estilo,0.9,0.9-imenu2*0.05,">>>");
                    estilo.color=WHITE;
                    break;
                    }
        default :    {
                    estilo.color=GREY;
                    }
    }

    D.text(estilo,-1.4,0.97,"Press TAB to change selection");
    D.text(estilo,0.8,0.97,"Press SPACE to change selection");
    if (imenu1<7) if ((bMostrar[imenu1])) {D.text(estilo,-1.4,-0.7,"Press ENTER to hide");}
                    else {D.text(estilo,-1.4,-0.7,"Press ENTER to show");}


    estilo.color=WHITE;
    D.text(estilo,-1.2,0.9,"Mesh");
    D.text(estilo,-1.2,0.85,"Gui");
    D.text(estilo,-1.2,0.8,"Text");
    D.text(estilo,-1.2,0.75,"Image");
    D.text(estilo,-1.2,0.7,"Water");
    D.text(estilo,-1.2,0.65,"Sun");
    D.text(estilo,-1.2,0.6,"Sky");
    D.text(estilo,-1.2,0.55,"Camera");
    D.text(estilo,-1.4,-0.75,S+"Increment: "+fIncremento);
    
    switch (imenu1)
    {
        case 0 :    {
                    D.text(estilo,-1.4,-0.8,S+"Mesh position: "+matrixMalla.pos);
                    D.text(estilo,-1.4,-0.85,S+"RotX: "+fMallaRotX+"   RotY: "+fMallaRotY+"   RotZ: "+fMallaRotZ);
                    D.text(estilo,-1.4,-0.9,S+"ScaleX: "+fMallaEscX+"   ScaleY: "+fMallaEscY+"   ScaleZ: "+fMallaEscZ);
                    D.text(estilo,1,0.9,"Move");
                    D.text(estilo,1,0.85,"Rotate");
                    D.text(estilo,1,0.8,"Scale");
                    break;
                    }
        case 1 :    {
                    D.text(estilo,-1.4,-0.8,S+"Windows position: "+wVentana.pos());
                    D.text(estilo,-1.4,-0.85,S+"Min x: "+wVentana.rect.min.x+"    Min y: "+wVentana.rect.min.y+"    Max x: "+wVentana.rect.max.x+"    Max y: "+wVentana.rect.max.y);
                    D.text(estilo,1,0.9,"Move");
                    D.text(estilo,1,0.85,"Dimension");
                    break;
                    }
        case 2 :    {
                    D.text(estilo,-1.4,-0.8,S+"Text position: "+posTexto);
                    D.text(estilo,-1.4,-0.85,S+"Scale: "+fEscTexto+"   Align: "+aliTexto+"   Dimension: "+Length(cTexto));
                    D.text(estilo,1,0.9,"Move");
                    D.text(estilo,1,0.85,"Scale");
                    D.text(estilo,1,0.8,"Align");
                    D.text(estilo,1,0.75,"Dimension");
                    break;
                    }
        case 3 :    {
                    D.text(estilo,-1.4,-0.8,S+"Image position: "+posImagen);
                    D.text(estilo,-1.4,-0.85,S+"Width: "+fanchoImagen+"   Height: "+faltoImagen);
                    D.text(estilo,1,0.9,"Move");
                    D.text(estilo,1,0.85,"Scale");
                    break;
                    }
        case 4 :    {
                    D.text(estilo,-1.4,-0.8,S+"Water position: "+Water.plane());
                    D.text(estilo,-1.4,-0.85,S+"Density: "+Water.density+"   Reflect: "+Water.reflect+"   Specular: "+Water.specular+"   Wave Scale: "+Water.wave_scale);
                    D.text(estilo,1,0.9,"Move");
                    D.text(estilo,1,0.85,"Density");
                    D.text(estilo,1,0.8,"Reflect");
                    D.text(estilo,1,0.75,"Specular");
                    D.text(estilo,1,0.7,"Wave Scale");
                    break;
                    }
        case 7 :    {
                    D.text(estilo,-1.4,-0.8,S+"Camera position"+Cam.matrix.pos);
                    D.text(estilo,-1.4,-0.85,S+"Pitch: "+Cam.pitch+"   Yaw: "+Cam.yaw+"   Roll: "+Cam.roll);
                    D.text(estilo,1,0.9,"Move");
                    D.text(estilo,1,0.85,"Pitch");
                    D.text(estilo,1,0.8,"Yaw");
                    D.text(estilo,1,0.75,"Roll");
                    }
    }

}
/******************************************************************************/
03-09-2009 11:05 PM
Find all posts by this user Quote this message in a reply
Post Reply