Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: problem with glm::vec3

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2014
    Posts
    5

    problem with glm::vec3

    Hello,
    I have this piece of code:

    Code :
    	if (glfwGetKey( window, GLFW_KEY_O ) == GLFW_PRESS){  
    		if (glfwGetKey( window, GLFW_KEY_1 ) == GLFW_PRESS){//1 pawn
     
    			if(strcmp(selected->name,"dummy")!=0 && selected != &mpawn[8]){
     
    				EXselected = selected;
    				if(selected->Kd.x == 0,549){
    					printf("%f",selected->Kd.x);
    					selected->Kd.x = 0.0;
    					selected->Kd.y = 0.0;
    					selected->Kd.z = 0.0;
    				}
    				else if(selected->Kd.x == 0,898){
    					selected->Kd.x = 0.800;
    					selected->Kd.y = 0.800;
    					selected->Kd.z = 0.800;
    				}
    			}
     
    			selected = &mpawn[8];
    			selected->Kd.x = 0.898;
    			selected->Kd.y = 0.227;
    			selected->Kd.z = 0.227;
    			selected->Vchange = true;
     
    		}
           }
    selected->Kd is a glm::vec3, with 3 float stored inside x, y and z.
    The problem is with the 2 if statements:
    if I write if(selected->Kd.x == 0,549) with the comma on 0,549 the statement result is always true.
    if I write if(selected->Kd.x == 0.549) with the dot on 0.549 the statement result is always false.

    What I am wrong?
    if I forgot some informations, please tell me.
    Thanks

  2. #2
    Junior Member Newbie
    Join Date
    Mar 2014
    Posts
    5
    Hi again!
    I resolved my problem simply using the ">" and "<" instead of "=="
    so my previus code become:

    Code :
    	if (glfwGetKey( window, GLFW_KEY_O ) == GLFW_PRESS){  
    		if (glfwGetKey( window, GLFW_KEY_1 ) == GLFW_PRESS){//1 pawn
     
    			if(strcmp(selected->name,"dummy")!=0 && selected != &mpawn[8]){
     
    				EXselected = selected;
    				if(selected->Kd.x < 0.6){
    					printf("%f",selected->Kd.x);
    					selected->Kd.x = 0.0;
    					selected->Kd.y = 0.0;
    					selected->Kd.z = 0.0;
    				}
    				else if(selected->Kd.x >0.6){
    					selected->Kd.x = 0.800;
    					selected->Kd.y = 0.800;
    					selected->Kd.z = 0.800;
    				}
    			}
     
    			selected = &mpawn[8];
    			selected->Kd.x = 0.898;
    			selected->Kd.y = 0.227;
    			selected->Kd.z = 0.227;
    			selected->Vchange = true;
     
    		}
           }

    And this works fine, I still don't understand why the previous code didn't work with "==", but at least I resolved

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •