コード例 #1
0
void Cross::activateGrab() {
    if(isGrabActive) return;
    isGrabActive = true;

    float minDistance = 1000;
    RenderObject * minBody = NULL;

    // TODO children hack
    const vec3 crossPos = this->getPosition();
    std::vector<RenderObject *> allSceneObjects;
    for(unsigned int i = 0; i < sceneObjects->size(); i++){
        RenderObject * body = (*sceneObjects)[i];
        allSceneObjects.push_back(body);
        const std::vector<RenderObject *>& children = body->getChildren();
        for(unsigned int j = 0; j < children.size(); j++){
            allSceneObjects.push_back(children[j]);
        }
    }

    for(unsigned int i = 0; i < allSceneObjects.size(); i++){
        RenderObject * body = (allSceneObjects)[i];
        if(!body->isGrabable()) continue;

        const vec3& bodyPos = body->getPosition();

        float dx = crossPos.x - bodyPos.x;
        dx *= dx;
        float dy = crossPos.y - bodyPos.y;
        dy *= dy;
        float dz = crossPos.z - bodyPos.z;
        dz *= dz;
        float distance = sqrt(dx + dy + dz);
        if(distance < grabRadius){
            if(distance < minDistance){
                minDistance = distance;
                minBody = body;
            }
        }
    }
    if(minBody != NULL){
        grabedMap.clear();
        grabedMap[minBody] = BodyInfo(minDistance, *minBody->getColor());
        minBody->setColor(grabedColor);
        minBody->setSelected(true);
    }


}
コード例 #2
0
void Cross::activateGrab(const std::vector<RenderObject*>& renderObjects) {
    if(isGrabActive) return;
    isGrabActive = true;
    grabedMap.clear();

    for(unsigned int i = 0; i < renderObjects.size();i++){
        RenderObject* object = renderObjects[i];

        grabedMap[object] = BodyInfo(0, *(object->getColor()));
        object->setSelected(true);

        const std::vector<RenderObject*>& components = object->getComponents();
        for(unsigned int i = 0 ; i < components.size(); i++){
            grabedMap[components[i]] = BodyInfo(0, *(components[i]->getColor()));
            components[i]->setSelected(true);
        }
    }
}