PDA

View Full Version : problem with glm::vec3



alfox10
06-12-2014, 09:01 AM
Hello,
I have this piece of 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

alfox10
06-12-2014, 07:16 PM
Hi again!
I resolved my problem simply using the ">" and "<" instead of "=="
so my previus code become:



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