About Store Forum Documentation Contact



Post Reply 
Problem with if
Author Message
Kaggio Offline
Member

Post: #1
Problem with if
Hi,
I tried to modyfi code from tutorial "Simple 3D". I want to do I click 'K' then Ball appeared and again click 'K' Ball disappeared. I've done a few codes - anyone work....
code1:
Code:
void InitPre()
{
   EE_INIT();
   App.flag=APP_MS_EXCLUSIVE; // setup mouse exclusive mode to hide cursor
}
bool Init()
{
   Cam.dist=5; // set initial camera distance to 5 meters
   return true;
}
void Shut()
{
}
bool Update()
{
   if(Kb.bp(KB_ESC))return false;
  

   Cam.transformByMouse(0.1, 10, CAMH_ROT|CAMH_ZOOM); // simple camera handle allowing minimum 0.1 and maximum 10 meters zoom, and allowing rotation and zooming

   return true;
}
void Draw()
{
   D.clear(WHITE);

   SetMatrix(MatrixIdentity); // set matrix before drawing
   if(Kb.bp(KB_K))
   {
     Ball(1  , Vec(-3, 0, 0)).draw(BLACK);
   }

              Box (1                    ).draw(BLACK); // draw black box with 1 meter radius
      
   if(Ms.b(1))Tube(0.3, 2, Vec( 3, 0, 0)).draw(BLACK); // when 1st mouse button pushed draw black tube with 0.1 meter radius, 2 meters height and (3,0,0) position
}
//Ball appeard only for a moment and then disappeared
code 2:
Code:
int abc=0;
void InitPre()
{
   EE_INIT();
   App.flag=APP_MS_EXCLUSIVE; // setup mouse exclusive mode to hide cursor
}
bool Init()
{
   Cam.dist=5; // set initial camera distance to 5 meters
   return true;
}
void Shut()
{
}
bool Update()
{
   if(Kb.bp(KB_ESC))return false;
   if(Kb.bp(KB_K))abc=1;

   Cam.transformByMouse(0.1, 10, CAMH_ROT|CAMH_ZOOM); // simple camera handle allowing minimum 0.1 and maximum 10 meters zoom, and allowing rotation and zooming

   return true;
}
void Draw()
{
   D.clear(WHITE);

   SetMatrix(MatrixIdentity); // set matrix before drawing
   if(abc=1)
   {
     Ball(1  , Vec(-3, 0, 0)).draw(BLACK);
   }

              Box (1                    ).draw(BLACK); // draw black box with 1 meter radius
      
   if(Ms.b(1))Tube(0.3, 2, Vec( 3, 0, 0)).draw(BLACK); // when 1st mouse button pushed draw black tube with 0.1 meter radius, 2 meters height and (3,0,0) position
}
//automaticly appeard when start application ;/
What's wrong? :/
(This post was last modified: 07-04-2015 03:38 PM by Kaggio.)
07-04-2015 03:38 PM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #2
RE: Problem with if
First of all: Please try to keep layout and naming conventions in mind.

Second: if(Kb.bp(KB_K)) {..} will only be true when you start pressing K. It will only be true for 1 frame, then it will be false again until you release and press again. If you want to do a toggle you will need to use a bool variable to store if you pressed K or not.

Third: abc = 1 should be abc == 1. Else you are ASSIGNING a variable, not checking.
07-04-2015 03:50 PM
Find all posts by this user Quote this message in a reply
Kaggio Offline
Member

Post: #3
RE: Problem with if
Ok thanks i have done it smile I forgot about == and =. Thanks a lot smile
07-04-2015 04:19 PM
Find all posts by this user Quote this message in a reply
Post Reply