putting a game engine together need some pointers

JaiJai
edited December 2015 in Library Questions

im putting a game that looks sorta like StarFox 64 pretty old Nintendo game i used to play growing up, so here i am trying to replicate this game with my own material and plot, what i have so far is the environment where the ship flies the ship it self "well a few for user choice" and i have the enemy ships which will be the other ships that the player did not chose. Now where im having trouble is importing the obj file to the flying environment where the game takes place, or the level if you will (levels map) "which by the way i have 5 maps" and i load the obj to the window and everything runs good or as normal but the ship is no where to be found?

star-fox-64_sep6-13_51_19

void setup() 
{
 /*
  AS YOU CAN SEE HERE IS THE OBJ OF THE SHIP OF THE PLAYERS GAME 
  size(1800, 900, P3D);
  frameRate(30);//added
  model = new OBJModel(this, "drone.obj", "absolute", TRIANGLES);
  model.enableDebug();

  model.scale(15);//20 is good but play with this 
  model.translateToCenter();

  stroke(255);
  noStroke();
  */
  cursor(CROSS);

  IN HERE I SETUP ALL THE TERRAIN AND WALLS TO THE GAME

  HERE I DECLARED THE NUMBER OF ENEMIES 
  {
  HERE I HAVE A CODE BLOCK FOR THE ENEMY RENDERING
  }
 HERE I HAVE A CODE BLOCK THATS FOR THE ENEMY SHIP
}

IN HERE I TRY PLACING THE DRONE CODE ONLY " found in void ship() " IN THE DRAW BUT NOTHING AND IT WAS SORTA LAGGING SO I ENDED UP MAKING A VOID SHIP() AND THIS RUNS BETTER BUT NO SHOW OF SHIP

void draw() 
{
  background(0);
  // Get elapsed time
  long t = millis() - time;
  time = millis();

  update(t/1000.0);  // Update shapes on terrain
  if (mousePressed)   // Update camera speed and direction
    processMousePressed();
  if (keyPressed) 
    processKeyPressed(t);
  if (clicked)  // Clicked on artefact?
    processMouseClick();
  cam.move(t/250.0);  //1000
  // Calculate amount of movement based on velocity and time
  // Adjust the cameras position so we are over the terrain
  // at the given height.
  cam.adjustToTerrain(terrain, Terrain.WRAP, camHoversAt);
  // Set the camera view before drawing
  cam.camera();
  obelisk.draw();
  tube.draw();
  terrain.draw();
  // Get rid of directional lights so skybox is evenly lit.
  skybox.moveTo(cam.eye().x, 0, cam.eye().z);
  skybox.draw();
}

AS YOU CAN SEE HERE IS WHERE I THOUGHT I SHOULD PLACE THIS FUNCTION BUT I DONT KNOW, YOU TELL ME ?! IT SHOULD GO IN DRAW OR IN HERE BUT IF IN HERE WHAT DO I DO IN DRAW TO MAKE IT DISPLAY?

void ship()
{
   background(0);
    lights();
    pushMatrix();
    translate(900, 700);
    rotateX(rotY);
    rotateY(rotX);
    model.draw();
    popMatrix();
}

IN HERE IM USING THE LEFT CLICK AND DRAG TO MOVE THE SHIP IN ITS CENTER AXIS USING MOUSEDRAGGED()

void mouseDragged()
{
    rotX += (mouseX - pmouseX) * 0.01;
    rotY -= (mouseY - pmouseY) * 0.01;
}

void processMousePressed() 
{
  float achange = (mouseX - pmouseX) * PI / width;
  cam.rotateViewBy(achange);  // Keep view and move directions the same
  cam.turnBy(achange);
}

HERE IM USING THE KEYBOARDS ARROW FOR NOW TO MOVE THE PLAYERS VIEW "CAMERA ANGLE VIEW"

void processKeyPressed(long t) 
{
  if (key == 'W' || key =='w' || key == 'P' || key == 'p') 
  {
    camSpeed += (t/25.0);
    cam.speed(camSpeed);
  } else if (key == 'S' || key =='s' || key == 'L' || key == 'l') 
  {
    camSpeed -= (t/5.0);
    cam.speed(camSpeed);
  } else if (key == 'o') 
  {
    camSpeed = 0;
    cam.speed(camSpeed);
  }
}

AS YOU CAN SEE THIS IS WHAT THE GAME LOOKS LIKE IN THIS PARTICULAR MAP BUT THE ISSUE IS THAT THAT DRONE IN THE BOTTOM CENTER IS NOT SHOWING UP THERE AS IT SHOULD, THATS THE OBJ FILE IN SETUP NAMED DRONE.OBJ

Screenshot (85)

Capture

Tagged:

Answers

  • you need to set the z for the model too, remember that minus means away from you

     translate(900, 700, -400);
    
  • JaiJai
    edited December 2015

    @Chrisir i try but i still dont see i even thought of adding the ship.draw(); to the draw section but nothing in fact i get a error saying "cannot find anything name ship"

    void draw() 
    {
      background(0);
      // Get elapsed time
      long t = millis() - time;
      time = millis();
    
      update(t/1000.0);  // Update shapes on terrain
      if (mousePressed)   // Update camera speed and direction
        processMousePressed();
      if (keyPressed) 
        processKeyPressed(t);
      if (clicked)  
        processMouseClick();
      cam.move(t/250.0);  //1000
      // Calculate amount of movement based on velocity and time
      // Adjust the cameras position so we are over the terrain
      // at the given height.
      cam.adjustToTerrain(terrain, Terrain.WRAP, camHoversAt);
      // Set the camera view before drawing
      cam.camera();
      obelisk.draw();
      tube.draw();
      terrain.draw();
      skybox.moveTo(cam.eye().x, 0, cam.eye().z);
      skybox.draw();
      ship.draw(); //JUST ADDED just to get a error
    }
    
    void ship()
    {
       background(0);
        lights();
        pushMatrix();
        translate(900, 700, -400);//-400 for the Z as suggested by Chrisir 
        rotateX(rotY);
        rotateY(rotX);
        model.draw();
        popMatrix();
    }
    
  • edited December 2015

    ??

    in draw() just say ship(); to call this function

    !!!

  • JaiJai
    edited December 2015

    well yes i tried that by using the ship.draw(); but i got that error and when i used it as you suggested when i run the sketch i get a black screen and nothing shows u then, so does it matter where i place the ship() in draw? i just placed it at the very bottom of draw

  • don't have background(0); in ship() of course

  • also place lights() in draw() please

    void draw() 
    {
      background(0);
      lights();
    
  • yup i did that too both of your suggestions and nothing still no ship/ hmmmm i thought draw plays things as per in order so if i draw a square and a circle i would endup with a square behind a circle so im not sure if i have a ship() being called in the end of draw why dont i get a ship to be displayed on top of all other calls such as

      cam.adjustToTerrain(terrain, Terrain.WRAP, camHoversAt);
      cam.camera();
      obelisk.draw();
      tube.draw();
      terrain.draw();
      skybox.moveTo(cam.eye().x, 0, cam.eye().z);
      skybox.draw();
      ship();
    
  • edited December 2015

    in 2D things are in the order you call them

    but in 3D / OPENGL the Z coordinates are the criteria for the order

    maybe your ship is behind the background image / sky

    do you see the ship when you comment out the sky / the background image?

  • well good point i dont really know much about 3D as it is in no video tutorial that i been following from Daniel Shiffman, but ok another good point about the debugging i forgot i can do that "comment out functions in draw" well i did the following and i found the model but its in wiremesh which i dont know why cuz in the other program where i imported from was just fine hmmm

    Screenshot (87)

    now i know for sure its in my window i just need to bring it out into the center of the window well bottom center as i like to call it,

    in this function i simply change "####THIS####" and i got to take out from where it was hiding at

    void ship()
    {
      //background(0);
      //lights();//place in draw()
      pushMatrix();
      translate(200, 200, -400);//"####THIS####"  from 900,700 to 200,200
      rotateX(rotY);
      rotateY(rotX);
      model.draw();
      popMatrix();
    }
    

    also i feel that this model might be to big tho im not sure how or why cuz in the other sketch where i imported from code below the main window was smaller and the size of the drone was relevantly small compare to this window here which is huge?!

    import saito.objloader.*;
    
    OBJModel model ;
    float rotX, rotY;
    
    void setup()
    {
        size(1800, 900, P3D);
        frameRate(30);
        model = new OBJModel(this, "drone.obj", "absolute", TRIANGLES);
        model.enableDebug();
    
        model.scale(15);//20 is good but play with this 
        model.translateToCenter();
    
        stroke(255);
        noStroke();
    }
    
    void draw()
    {
        background(0);
        lights();
        pushMatrix();
        translate(900, 700);
        rotateX(rotY);
        rotateY(rotX);
        model.draw();
        popMatrix();
    }
    void mouseDragged()
    {
        rotX += (mouseX - pmouseX) * 0.01;
        rotY -= (mouseY - pmouseY) * 0.01;
    } 
    
  • I dunno

    let's say the image of the background and cam has Z = 600 then place ship at Z = 300 or so

    see

    https://www.processing.org/reference/PShape_disableStyle_.html

  • ummm Chrisir where do you see the variable name Z? or are you asking me to make one? but yes i understand your point about

    Z = 600 then place ship at Z = 300 or so

  • I was just referring to the z-value in the translate expression

  • JaiJai
    edited December 2015

    ohhh ok lol is just that it does not have a Z so i was lost for a second "took it literately "but you mean this translate(900, 700, -300);

Sign In or Register to comment.