void ModelComponent::getBoundingBox(int *x1, int *y1, int *x2, int *y2) {
	// If the object was drawn by being a component
	// of it's parent then don't draw it

	if (_parent && _parent->isVisible())
		return;
	// Need to translate object to be in accordance
		// with the setup of the parent
	translateObject(false);

	_hier->getBoundingBox(x1, y1, x2, y2);

	// Need to un-translate when done
	translateObject(true);
}
void ModelComponent::draw() {
	// If the object was drawn by being a component
	// of it's parent then don't draw it

	if (_parent && _parent->isVisible())
			return;
	// Need to translate object to be in accordance
	// with the setup of the parent
	translateObject(false);

	_hier->draw();

	// Need to un-translate when done
	translateObject(true);
}
Beispiel #3
0
TriggerObject::TriggerObject(Mesh* mesh, TRIGGEROBJECTS objectName, Vector3 Pos, Vector3 scale, float angle, bool active, SoundManager &sfx_mano, Player* player)
{
	/* set object */
	Set("checking", mesh, NULL, false, false);
	translateObject(Pos.x, Pos.y, Pos.z);
	scaleObject(scale.x, scale.y, scale.z);
	type = objectName;
	this->active = active; //render

	/* set boundbox */
	collideBound.Set(Pos, scale, Collision::BOX);

	this->player = player;

	isTriggered = true; //trigger
	triggerTimer = 0;
	initialPos = Pos;
	speed = 10.f;
	arrowCooldown = 1.f;

	my_sfx_man = &sfx_mano;

	triggerTimer = 0.f;
	duration = 0.f;
}
Beispiel #4
0
JSONObject* WriteVisitor::createJSONLight(osg::Light* light)
{
    if (_maps.find(light) != _maps.end())
        return _maps[light]->getShadowObject();

    osg::ref_ptr<JSONObject> jsonLight = new JSONLight;
    jsonLight->addUniqueID();
    _maps[light] = jsonLight;

    translateObject(jsonLight.get(), light);

    jsonLight->getMaps()["LightNum"] = new JSONValue<int>(light->getLightNum());
    jsonLight->getMaps()["Ambient"] = new JSONVec4Array(light->getAmbient());
    jsonLight->getMaps()["Diffuse"] = new JSONVec4Array(light->getDiffuse());
    jsonLight->getMaps()["Specular"] = new JSONVec4Array(light->getSpecular());
    jsonLight->getMaps()["Position"] = new JSONVec4Array(light->getPosition());
    jsonLight->getMaps()["Direction"] = new JSONVec3Array(light->getDirection());

    jsonLight->getMaps()["ConstantAttenuation"] = new JSONValue<float>(light->getConstantAttenuation());
    jsonLight->getMaps()["LinearAttenuation"] = new JSONValue<float>(light->getLinearAttenuation());
    jsonLight->getMaps()["QuadraticAttenuation"] = new JSONValue<float>(light->getQuadraticAttenuation());
    jsonLight->getMaps()["SpotExponent"] = new JSONValue<float>(light->getSpotExponent());
    jsonLight->getMaps()["SpotCutoff"] = new JSONValue<float>(light->getSpotCutoff());
    return jsonLight.release();
}
void ModelComponent::translateObject(ModelNode *node, bool reset) {
	if (node->_parent)
		translateObject(node->_parent, reset);

	if (reset) {
		node->translateViewpointBack();
	} else {
		node->translateViewpoint();
	}
}
Beispiel #6
0
GameObject::GameObject(Mesh* mesh, Vector3 Pos, Vector3 scale, bool active)
{
	/* set object */
	Set("", mesh, NULL, false, false);
	translateObject(Pos.x, Pos.y, Pos.z);
	scaleObject(scale.x, scale.y, scale.z);
	this->active = active; //render

	/* set boundbox */
	collideBound.Set(Pos, scale, Collision::BOX);
}
Beispiel #7
0
template <class T> JSONObject* createImageFromTexture(osg::Texture* texture, JSONObject* jsonTexture, bool inlineImages,
                                                      int maxTextureDimension, const std::string &baseName = "")
{
    T* text = dynamic_cast<T*>( texture);
    if (text) {
        translateObject(jsonTexture,text);
        JSONObject* image = createImage(text->getImage(), inlineImages, maxTextureDimension, baseName);
        if (image)
            jsonTexture->getMaps()["File"] = image;
        return jsonTexture;
    }
    return 0;
}
Beispiel #8
0
JSONObject* WriteVisitor::createJSONBlendColor(osg::BlendColor* sa)
{
    if (_maps.find(sa) != _maps.end())
        return _maps[sa]->getShadowObject();

    osg::ref_ptr<JSONObject> json = new JSONObject;
    json->addUniqueID();
    _maps[sa] = json;

    translateObject(json.get(), sa);

    json->getMaps()["ConstantColor"] = new JSONVec4Array(sa->getConstantColor());
    return json.release();
}
Beispiel #9
0
JSONObject* WriteVisitor::createJSONBlendFunc(osg::BlendFunc* sa)
{
    if (_maps.find(sa) != _maps.end())
        return _maps[sa]->getShadowObject();

    osg::ref_ptr<JSONObject> json = new JSONObject;
    json->addUniqueID();
    _maps[sa] = json;

    translateObject(json.get(), sa);

    json->getMaps()["SourceRGB"] = getBlendFuncMode(sa->getSource());
    json->getMaps()["DestinationRGB"] = getBlendFuncMode(sa->getDestination());
    json->getMaps()["SourceAlpha"] = getBlendFuncMode(sa->getSourceAlpha());
    json->getMaps()["DestinationAlpha"] = getBlendFuncMode(sa->getDestinationAlpha());
    return json.release();
}
Beispiel #10
0
JSONObject* WriteVisitor::createJSONMaterial(osg::Material* material)
{
    if (_maps.find(material) != _maps.end())
        return _maps[material]->getShadowObject();

    osg::ref_ptr<JSONObject> jsonMaterial = new JSONMaterial;
    _maps[material] = jsonMaterial;

    translateObject(jsonMaterial.get(), material);

    jsonMaterial->getMaps()["Ambient"] = new JSONVec4Array(material->getAmbient(osg::Material::FRONT));
    jsonMaterial->getMaps()["Diffuse"] = new JSONVec4Array(material->getDiffuse(osg::Material::FRONT));
    jsonMaterial->getMaps()["Specular"] = new JSONVec4Array(material->getSpecular(osg::Material::FRONT));
    jsonMaterial->getMaps()["Emission"] = new JSONVec4Array(material->getEmission(osg::Material::FRONT));
    jsonMaterial->getMaps()["Shininess"] = new JSONValue<float>(material->getShininess(osg::Material::FRONT));

    return jsonMaterial.release();
}
Beispiel #11
0
bool addJSONChannel(const std::string& channelType, T* channel, bool packByCoords, JSONObject& anim, WriteVisitor* writer, osg::Object* parent) {
    if (channel && channel->getSampler()) {
        osg::ref_ptr<JSONObject> json = new JSONObject;
        std::string jsonType = channelType + (packByCoords ? "Packed" : "");

        translateObject(json.get(), channel);

        json->getMaps()["Name"] = new JSONValue<std::string>(channel->getName());
        json->getMaps()["TargetName"] = new JSONValue<std::string>(channel->getTargetName());

        typename T::KeyframeContainerType* keys = channel->getSamplerTyped()->getKeyframeContainerTyped();
        typedef typename T::UsingType KeyframeType;
        typedef typename osg_array<KeyframeType>::array_type KeyframeArray;

        osg::ref_ptr<JSONObject> jsKeys = new JSONObject;
        osg::ref_ptr<osg::FloatArray> timesArray = new osg::FloatArray;
        osg::ref_ptr<KeyframeArray> valuesArray = new KeyframeArray;

        for (unsigned int i = 0; i < keys->size(); i++) {
            timesArray->push_back((*keys)[i].getTime());
            valuesArray->push_back((*keys)[i].getValue());
        }

        jsKeys->getMaps()["Time"] = writer->createJSONBufferArray(timesArray.get(), parent);

        osg::ref_ptr<KeyframeArray> values;
        if(packByCoords) { // data channel packing
            values = pack<KeyframeArray, KeyframeArray>(valuesArray.get());
        }
        else {
            values = valuesArray;
        }

        jsKeys->getMaps()["Key"] = writer->createJSONBufferArray(values.get(), parent);
        json->getMaps()["KeyFrames"] = jsKeys;

        osg::ref_ptr<JSONObject> jsonChannel = new JSONObject();
        jsonChannel->getMaps()[jsonType] = json;
        anim.getMaps()["Channels"]->asArray()->getArray().push_back(jsonChannel);
        return true;
    }
    return false;
}
Beispiel #12
0
JSONObject* WriteVisitor::createJSONCullFace(osg::CullFace* sa)
{
    if (_maps.find(sa) != _maps.end())
        return _maps[sa]->getShadowObject();

    osg::ref_ptr<JSONObject> json = new JSONObject;
    json->addUniqueID();
    _maps[sa] = json;

    translateObject(json.get(), sa);

    osg::ref_ptr<JSONValue<std::string> > mode = new JSONValue<std::string>("BACK");
    if (sa->getMode() == osg::CullFace::FRONT) {
        mode = new JSONValue<std::string>("BACK");
    }
    if (sa->getMode() == osg::CullFace::FRONT_AND_BACK) {
        mode = new JSONValue<std::string>("FRONT_AND_BACK");
    }
    json->getMaps()["Mode"] = mode;
    return json.release();
}
void ModelComponent::translateObject(bool res) {
	ModelNode *node = _hier->_parent;
	if (node) {
		translateObject(node, res);
	}
}
Beispiel #14
0
JSONObject* WriteVisitor::createJSONGeometry(osg::Geometry* geom)
{
    if (_maps.find(geom) != _maps.end())
        return _maps[geom]->getShadowObject();

    if (needToSplit(*geom))
        error();

    osg::ref_ptr<JSONObject> json = new JSONNode;
    json->addUniqueID();
    _maps[geom] = json;

    if (geom->getStateSet())
        createJSONStateSet(json, geom->getStateSet());

    translateObject(json.get(), geom);

    osg::ref_ptr<JSONObject> attributes = new JSONObject;

    int nbVertexes = geom->getVertexArray()->getNumElements();
            
    if (geom->getVertexArray()) {
        attributes->getMaps()["Vertex"] = createJSONBufferArray(geom->getVertexArray());
    }
    if (geom->getNormalArray()) {
        attributes->getMaps()["Normal"] = createJSONBufferArray(geom->getNormalArray());
        int nb = geom->getNormalArray()->getNumElements();
        if (nbVertexes != nb) {
            osg::notify(osg::FATAL) << "Fatal nb normals " << nb << " != " << nbVertexes << std::endl;
            error();
        }
    }
    if (geom->getColorArray()) {
        attributes->getMaps()["Color"] = createJSONBufferArray(geom->getColorArray());
        int nb = geom->getColorArray()->getNumElements();
        if (nbVertexes != nb) {
            osg::notify(osg::FATAL) << "Fatal nb colors " << nb << " != " << nbVertexes << std::endl;
            error();
        }
    }
            
    std::stringstream ss;
    for ( int i = 0; i < 32; i++) {
        ss.str("");
        ss << "TexCoord" << i;
        //osg::notify(osg::NOTICE) << ss.str() << std::endl;
        if (geom->getTexCoordArray(i)) {
            attributes->getMaps()[ss.str()] = createJSONBufferArray(geom->getTexCoordArray(i));
            int nb = geom->getTexCoordArray(i)->getNumElements();
            if (nbVertexes != nb) {
                osg::notify(osg::FATAL) << "Fatal nb tex coord " << i << " " << nb << " != " << nbVertexes << std::endl;
                error();
            }
        }
    }
    if (geom->getVertexAttribArray(TANGENT_ATTRIBUTE_INDEX)) {
        attributes->getMaps()["Tangent"] = createJSONBufferArray(geom->getVertexAttribArray(TANGENT_ATTRIBUTE_INDEX));
        int nb = geom->getVertexAttribArray(TANGENT_ATTRIBUTE_INDEX)->getNumElements();
        if (nbVertexes != nb) {
            osg::notify(osg::FATAL) << "Fatal nb tangent " << nb << " != " << nbVertexes << std::endl;
            error();
        }
    }

    if (geom->getVertexAttribArray(BITANGENT_ATTRIBUTE_INDEX)) {
        attributes->getMaps()["Bitangent"] = createJSONBufferArray(geom->getVertexAttribArray(BITANGENT_ATTRIBUTE_INDEX));
        int nb = geom->getVertexAttribArray(BITANGENT_ATTRIBUTE_INDEX)->getNumElements();
        if (nbVertexes != nb) {
            osg::notify(osg::FATAL) << "Fatal nb bitangent " << nb << " != " << nbVertexes << std::endl;
            error();
        }
    }

    json->getMaps()["VertexAttributeList"] = attributes;

    if (!geom->getPrimitiveSetList().empty()) {
        osg::ref_ptr<JSONArray> primitives = new JSONArray();
        for (unsigned int i = 0; i < geom->getPrimitiveSetList().size(); ++i) {

            osg::ref_ptr<JSONObject> obj = new JSONObject;
            if (geom->getPrimitiveSetList()[i]->getType() == osg::PrimitiveSet::DrawArraysPrimitiveType) {
                osg::DrawArrays* da = dynamic_cast<osg::DrawArrays*>((geom->getPrimitiveSetList()[i].get()));
                primitives->getArray().push_back(obj);
                if (da->getMode() == GL_QUADS) {
                    obj->getMaps()["DrawElementsUShort"] = createJSONDrawElements(da);
                } else {
                    obj->getMaps()["DrawArrays"] = createJSONDrawArray(da);
                }

            } else if (geom->getPrimitiveSetList()[i]->getType() == osg::PrimitiveSet::DrawElementsUIntPrimitiveType) {
                osg::DrawElementsUInt* da = dynamic_cast<osg::DrawElementsUInt*>((geom->getPrimitiveSetList()[i].get()));
                primitives->getArray().push_back(obj);
                obj->getMaps()["DrawElementsUShort"] = createJSONDrawElementsUInt(da);

            }  else if (geom->getPrimitiveSetList()[i]->getType() == osg::PrimitiveSet::DrawElementsUShortPrimitiveType) {
                osg::DrawElementsUShort* da = dynamic_cast<osg::DrawElementsUShort*>((geom->getPrimitiveSetList()[i].get()));
                primitives->getArray().push_back(obj);
                obj->getMaps()["DrawElementsUShort"] = createJSONDrawElementsUShort(da);

            }  else if (geom->getPrimitiveSetList()[i]->getType() == osg::PrimitiveSet::DrawElementsUBytePrimitiveType) {
                osg::DrawElementsUByte* da = dynamic_cast<osg::DrawElementsUByte*>((geom->getPrimitiveSetList()[i].get()));
                primitives->getArray().push_back(obj);
                obj->getMaps()["DrawElementsUShort"] = createJSONDrawElementsUByte(da);

            }  else if (geom->getPrimitiveSetList()[i]->getType() == osg::PrimitiveSet::DrawArrayLengthsPrimitiveType) {
                osg::DrawArrayLengths* dal = dynamic_cast<osg::DrawArrayLengths*>((geom->getPrimitiveSetList()[i].get()));
                primitives->getArray().push_back(obj);
                obj->getMaps()["DrawArrayLengths"] = createJSONDrawArrayLengths(dal);

            } else {
                osg::notify(osg::WARN) << "Primitive Type " << geom->getPrimitiveSetList()[i]->getType() << " not supported, skipping" << std::endl;
            }
        }
        json->getMaps()["PrimitiveSetList"] = primitives;
    }
    return json;
}
Beispiel #15
0
void TriggerObject::updateTrigger(double dt, bool* myKey)
{
	triggerTimer += dt; //timer for trigger
	arrowCooldown += dt;

	if(type == FIRETRIGGER)
	{
		if(triggerTimer > 2)
		{
			if(player->QuickAABBDetection(this) && myKey[KEY_E] && isTriggered == true) //Switch off fire trap
			{
				isTriggered = false;
				triggerTimer = 0;
				my_sfx_man->stop_fire();
			}
			else if(player->QuickAABBDetection(this) && myKey[KEY_E] && isTriggered == false) //Switch on fire trap
			{
				isTriggered = true;
				triggerTimer = 0;
			}
		}
	}
	else if (type == ARROWTRAP)
	{
		if (this->mesh->name == "arrow left" && this->isTriggered == true)
		{
			translateObject(Vector3(-speed, 0, 0));
		}
		else if (this->mesh->name == "arrow right" && this->isTriggered == true)
		{
			translateObject(Vector3(speed, 0, 0));
		}
		else if (this->mesh->name == "arrow up" && this->isTriggered == true)
		{
			translateObject(Vector3(0, speed, 0));
		}
		else if (this->mesh->name == "arrow down" && this->isTriggered == true)
		{
			translateObject(Vector3(0, -speed, 0));
		}
	}
	else if (type == ARROWTRIGGER)
	{
		if (player->QuickAABBDetection(this) && isTriggered == false) //Switch on arrow trap
		{
			isTriggered = true;
			my_sfx_man->play_stone_move();
		}
	}
	else if (type == SPIKEREAPPEAR)
	{
		if (triggerTimer > duration)
		{
			if (active == true)
			{
				active = false;
				isTriggered = false;
				triggerTimer = 0.f;
				my_sfx_man->play_spike();
			}
			else if (active == false)
			{
				active = true;
				isTriggered = true;
				triggerTimer = 0.f;
				my_sfx_man->play_spike();
			}
		}
	}
}
Beispiel #16
0
Player::Player(Mesh* mesh, Vector3 Pos, Vector3 scale, float angle, float Speed, bool active, SoundManager &sfx_mano)
{
	PLAYER_SPEED = 4;
	score = 0;
	health = 100;
	stamina = 100;
	damage = 10;
	throwingCoin = false;

	/* set object */
	Set("sdfdf", mesh, NULL, false, false);
	translateObject(Pos.x, Pos.y, Pos.z);
	scaleObject(scale.x, scale.y, scale.z);

	/* set angle */
	angleZ = angle;

	/* set physics */
	info.setSpeed(Speed);
	info.setDir(Vector2(1, 0));	//should be based on angle
	info.setTimer(0);

	/* set boundbox */
	collideBound.Set(Pos, scale, Collision::BOX);
	invisible = false;

	jumpSpeed = 0;

	setType(GO_PLAYER);
	// Sound setup
	my_sfx_man = &sfx_mano;

	deceleration = 15;
	vel = 0;
	LeftOrRight = false;
	UpOrDown = false;
	checkLR = false;
	checkUD = false;

	/* drop rate */
	dropRate = 0.1;
	dropTimer = dropRate;

	/* Store all non-invisibility sprites */
	//Player sprites
	Sprite_invisibility_texture_file_path = "Image//Sprites//Hero2_invisible.tga";

	storeSpriteAnimation("black guard", 21, 13, "Image//Sprites//Hero2.tga");
	processSpriteAnimation(Player::UP, 0.5f, 0, 8, 8, 8, 1);
	processSpriteAnimation(Player::DOWN, 0.5f, 0, 10, 8, 10, 1);
	processSpriteAnimation(Player::LEFT, 0.5f, 0, 9, 8, 9, 1);
	processSpriteAnimation(Player::RIGHT, 0.5f, 0, 11, 8, 11, 1);
	processSpriteAnimation(Player::ATTACKUP, 0.5f, 0, 4, 7, 4, 1);
	processSpriteAnimation(Player::ATTACKDOWN, 0.5f, 0, 6, 7, 6, 1);
	processSpriteAnimation(Player::ATTACKLEFT, 0.5f, 0, 5, 7, 5, 1);
	processSpriteAnimation(Player::ATTACKRIGHT, 0.5f, 0, 7, 7, 7, 1);

	/* Set coin list */
	for(int i = 0; i < 20; ++i)
	{
		Coin* coin;
		coin = new Coin(Geometry::meshList[Geometry::GEO_COIN], false);
		coinList.push_back(coin);
	}

	throwTime = 7.f;
	throwTimer = throwTime;
}
Beispiel #17
0
JSONObject* WriteVisitor::createJSONGeometry(osg::Geometry* geometry, osg::Object* parent)
{
    if(!parent) {
        parent = geometry;
    }

    if (_maps.find(geometry) != _maps.end())
        return _maps[geometry]->getShadowObject();

    osg::ref_ptr<JSONObject> json = new JSONObject;
    json->addUniqueID();
    _maps[geometry] = json;

    if (geometry->getStateSet())
        createJSONStateSet(json.get(), geometry->getStateSet());

    translateObject(json.get(), geometry);

    osg::ref_ptr<JSONObject> attributes = new JSONObject;

    int nbVertexes = 0;

    if (geometry->getVertexArray()) {
        nbVertexes = geometry->getVertexArray()->getNumElements();
        attributes->getMaps()["Vertex"] = createJSONBufferArray(geometry->getVertexArray(), parent);
    }
    if (geometry->getNormalArray()) {
        attributes->getMaps()["Normal"] = createJSONBufferArray(geometry->getNormalArray(), parent);
        int nb = geometry->getNormalArray()->getNumElements();
        if (nbVertexes != nb) {
            osg::notify(osg::FATAL) << "Fatal nb normals " << nb << " != " << nbVertexes << std::endl;
            error();
        }
    }
    if (geometry->getColorArray()) {
        attributes->getMaps()["Color"] = createJSONBufferArray(geometry->getColorArray(), parent);
        int nb = geometry->getColorArray()->getNumElements();
        if (nbVertexes != nb) {
            osg::notify(osg::FATAL) << "Fatal nb colors " << nb << " != " << nbVertexes << std::endl;
            error();
        }
    }

    std::stringstream ss;
    for ( int i = 0; i < 32; i++) {
        ss.str("");
        ss << "TexCoord" << i;
        //osg::notify(osg::NOTICE) << ss.str() << std::endl;
        if (geometry->getTexCoordArray(i)) {
            attributes->getMaps()[ss.str()] = createJSONBufferArray(geometry->getTexCoordArray(i), parent);
            int nb = geometry->getTexCoordArray(i)->getNumElements();
            if (nbVertexes != nb) {
                osg::notify(osg::FATAL) << "Fatal nb tex coord " << i << " " << nb << " != " << nbVertexes << std::endl;
                error();
            }
        }
    }

    osg::Array* tangents = getTangentSpaceArray(*geometry);
    if (tangents) {
        attributes->getMaps()["Tangent"] = createJSONBufferArray(tangents, parent);
        int nb = tangents->getNumElements();
        if (nbVertexes != nb) {
            osg::notify(osg::FATAL) << "Fatal nb tangent " << nb << " != " << nbVertexes << std::endl;
            error();
        }
    }

    json->getMaps()["VertexAttributeList"] = attributes;

    if (!geometry->getPrimitiveSetList().empty()) {
        osg::ref_ptr<JSONArray> primitives = new JSONArray();
        for (unsigned int i = 0; i < geometry->getNumPrimitiveSets(); ++i) {
            osg::ref_ptr<JSONObject> obj = new JSONObject;
            osg::PrimitiveSet* primitive = geometry->getPrimitiveSet(i);
            if(!primitive) continue;

            if (primitive->getType() == osg::PrimitiveSet::DrawArraysPrimitiveType) {
                osg::DrawArrays* da = dynamic_cast<osg::DrawArrays*>((primitive));
                primitives->getArray().push_back(obj);
                if (da->getMode() == GL_QUADS) {
                    obj->getMaps()["DrawElementsUShort"] = createJSONDrawElements(da, parent);
                } else {
                    obj->getMaps()["DrawArrays"] = createJSONDrawArray(da, parent);
                }
            } else if (primitive->getType() == osg::PrimitiveSet::DrawElementsUIntPrimitiveType) {
                osg::DrawElementsUInt* da = dynamic_cast<osg::DrawElementsUInt*>((primitive));
                primitives->getArray().push_back(obj);
                obj->getMaps()["DrawElementsUInt"] = createJSONDrawElementsUInt(da, parent);

            }  else if (primitive->getType() == osg::PrimitiveSet::DrawElementsUShortPrimitiveType) {
                osg::DrawElementsUShort* da = dynamic_cast<osg::DrawElementsUShort*>((primitive));
                primitives->getArray().push_back(obj);
                obj->getMaps()["DrawElementsUShort"] = createJSONDrawElementsUShort(da, parent);

            }  else if (primitive->getType() == osg::PrimitiveSet::DrawElementsUBytePrimitiveType) {
                osg::DrawElementsUByte* da = dynamic_cast<osg::DrawElementsUByte*>((primitive));
                primitives->getArray().push_back(obj);
                obj->getMaps()["DrawElementsUByte"] = createJSONDrawElementsUByte(da, parent);

            }  else if (primitive->getType() == osg::PrimitiveSet::DrawArrayLengthsPrimitiveType) {
                osg::DrawArrayLengths* dal = dynamic_cast<osg::DrawArrayLengths*>((primitive));
                primitives->getArray().push_back(obj);
                obj->getMaps()["DrawArrayLengths"] = createJSONDrawArrayLengths(dal, parent);
            } else {
                osg::notify(osg::WARN) << "Primitive Type " << geometry->getPrimitiveSetList()[i]->getType() << " not supported, skipping" << std::endl;
            }
        }
        json->getMaps()["PrimitiveSetList"] = primitives;
    }
    if (geometry->getComputeBoundingBoxCallback()) {
           osg::ref_ptr<JSONObject> jsonObj = new JSONObject;
           jsonObj->addUniqueID();
           json->getMaps()["osg.ComputeBoundingBoxCallback"] = jsonObj;
    }
    return json.get();
}
Beispiel #18
0
void GameObject::TranslateOffset(Vector3 offset)
{
	translateObject(offset);
}
Beispiel #19
0
JSONObject* WriteVisitor::createJSONStateSet(osg::StateSet* stateset)
{

    if (_maps.find(stateset) != _maps.end()) {
        return _maps[stateset]->getShadowObject();
    }

    osg::ref_ptr<JSONObject> jsonStateSet = new JSONStateSet;
    _maps[stateset] = jsonStateSet;
    jsonStateSet->addUniqueID();

    translateObject(jsonStateSet.get(), stateset);

    if (stateset->getRenderingHint() == osg::StateSet::TRANSPARENT_BIN) {
        jsonStateSet->getMaps()["RenderingHint"] = new JSONValue<std::string>("TRANSPARENT_BIN");
    }

    bool blendEnabled = false;
    if (stateset->getMode(GL_BLEND) == osg::StateAttribute::ON) {
        blendEnabled = true;
    }

    osg::ref_ptr<JSONArray> textureAttributeList = new JSONArray;
    int lastTextureIndex = -1;
    for (int i = 0; i < 32; ++i) {
        osg::Texture* texture = dynamic_cast<osg::Texture*>(stateset->getTextureAttribute(i,osg::StateAttribute::TEXTURE));

        JSONArray* textureUnit = new JSONArray;
        JSONObject* jsonTexture = createJSONTexture(texture);
        textureAttributeList->getArray().push_back(textureUnit);

        if (jsonTexture) {
            JSONObject* textureObject = new JSONObject;
            textureObject->getMaps()["osg.Texture"] = jsonTexture;
            textureUnit->getArray().push_back(textureObject);
            lastTextureIndex = i;
        }
    }
    if (lastTextureIndex > -1) {
        textureAttributeList->getArray().resize(lastTextureIndex+1);
        jsonStateSet->getMaps()["TextureAttributeList"] = textureAttributeList;
    }


    osg::ref_ptr<JSONArray> attributeList = new JSONArray;

    osg::Material* material = dynamic_cast<osg::Material*>(stateset->getAttribute(osg::StateAttribute::MATERIAL));
    if (material) {
        JSONObject* obj = new JSONObject;
        obj->getMaps()["osg.Material"] = createJSONMaterial(material);
        attributeList->getArray().push_back(obj);
    }

    osg::BlendFunc* blendFunc = dynamic_cast<osg::BlendFunc*>(stateset->getAttribute(osg::StateAttribute::BLENDFUNC));
    if (blendFunc) {
        JSONObject* obj = new JSONObject;
        obj->getMaps()["osg.BlendFunc"] = createJSONBlendFunc(blendFunc);
        attributeList->getArray().push_back(obj);
    } else if (blendEnabled == true) {
        JSONObject* obj = new JSONObject;
        osg::ref_ptr<osg::BlendFunc> defaultBlend = new osg::BlendFunc();
        obj->getMaps()["osg.BlendFunc"] = createJSONBlendFunc(defaultBlend.get());
        attributeList->getArray().push_back(obj);
    }

    osg::ref_ptr<osg::CullFace> cullFace = dynamic_cast<osg::CullFace*>(stateset->getAttribute(osg::StateAttribute::CULLFACE));
    osg::StateAttribute::GLModeValue cullMode = stateset->getMode(GL_CULL_FACE);
    if (cullFace || cullMode != osg::StateAttribute::INHERIT) {
        JSONObject* obj = new JSONObject;
        JSONObject* cf = 0;
        if (cullMode == osg::StateAttribute::OFF) {
            osg::ref_ptr<osg::CullFace> defaultCull = new osg::CullFace();
            cf = createJSONCullFace(defaultCull.get());
            cf->getMaps()["Mode"] = new JSONValue<std::string>("DISABLE");
            obj->getMaps()["osg.CullFace"] = cf;
            attributeList->getArray().push_back(obj);
        } else {
            if (!cullFace) {
                cullFace = new osg::CullFace();
            }
            cf = createJSONCullFace(cullFace);
        }
        obj->getMaps()["osg.CullFace"] = cf;
        attributeList->getArray().push_back(obj);
    }

    osg::BlendColor* blendColor = dynamic_cast<osg::BlendColor*>(stateset->getAttribute(osg::StateAttribute::BLENDCOLOR));
    if (blendColor) {
        JSONObject* obj = new JSONObject;
        obj->getMaps()["osg.BlendColor"] = createJSONBlendColor(blendColor);
        attributeList->getArray().push_back(obj);
    }
    

    if (!attributeList->getArray().empty()) {
        jsonStateSet->getMaps()["AttributeList"] = attributeList;
    }


    osg::StateSet::ModeList modeList = stateset->getModeList();
    for (unsigned int i = 0; i < modeList.size(); ++i) {
        // add modes
    }

    if (jsonStateSet->getMaps().empty())
        return 0;
    return jsonStateSet.release();
}
Beispiel #20
0
void Player::Update(double dt, bool* myKey)
{
	Vector3 Pos;

	// Counts from 0
	info.setTimer(info.getTimer() + dt);

	/* if invisible, staminia */
	if(invisible)
	{
		setStamina(getStamina() - INVISIBILITY_PRICE * dt);	
	}

	/* if throw coin */
	if(throwingCoin)
	{
		throwingCoin = false;
		setStamina(getStamina() - COIN_PRICE);
	}

	/* If not enough staminia, invisible 0 */
	if(getStamina() <= 0)
	{
		setStamina(0);

		if(invisible)
		{
			switchInvisibleState();
		}
	}

	/* update inventory */
	inventory.Update(dt, myKey);

	/* Use item */
	useItem(myKey);

	//cout << animationList[UP]->startRow << " " << animationList[DOWN]->startRow << endl;
	//setState(IDLE);
	if(myKey[KEY_W])
	{
		UpOrDown = false;
		checkUD = false;
		if(vel.y < PLAYER_SPEED)
		{
			vel.y += 0.5;
			Pos.y = vel.y;
		}
		else
		{
			vel.y = PLAYER_SPEED;
			Pos.y = vel.y;
		}

		//Movement / physics
		//translateObject(0, 4, 0);
		//Animation
		setState(UP);
		if (animationList[UP]->ended == true)
		{
			animationList[UP]->Reset();
		}

		//Sound
		sf_walk = true;
	}

	else if(myKey[KEY_S])
	{
		UpOrDown = true;
		checkUD = true;
		if(vel.y > -PLAYER_SPEED)
		{
			vel.y -= 0.5;
			Pos.y = vel.y;
		}
		else
		{
			vel.y = -PLAYER_SPEED;
			Pos.y = vel.y;
		}

		setState(DOWN);
		if (animationList[DOWN]->ended == true)
		{
			animationList[DOWN]->Reset();
		}

		sf_walk = true;
	}	


	else if(myKey[KEY_A])
	{
		LeftOrRight = true;
		checkLR = true;
		if(vel.x >= -PLAYER_SPEED)
		{
			vel.x -= 0.5;
			Pos.x = vel.x;
		}
		else
		{
			vel.x = -PLAYER_SPEED;
			Pos.x = vel.x;
		}
		
		setState(LEFT);
		if (animationList[LEFT]->ended == true)
		{
			animationList[LEFT]->Reset();
		}
		sf_walk = true;
	}

	else if(myKey[KEY_D])
	{
		LeftOrRight = false;
		checkLR = false;
		if(vel.x <= PLAYER_SPEED)
		{
			vel.x += 0.5;
			Pos.x = vel.x;
		}
		else
		{
			vel.x = PLAYER_SPEED;
			Pos.x = vel.x;
		}
		
		setState(RIGHT);
		if (animationList[RIGHT]->ended == true)
		{
			animationList[RIGHT]->Reset();
		}
		sf_walk = true;
	}
	
	if(!myKey[KEY_W] && !myKey[KEY_S] && vel.y != 0)
	{
		if(UpOrDown == false && checkUD == false)
		{
			vel.y -= deceleration * dt;
			if(vel.y < 0 && !myKey[KEY_W])
			{
				vel.y = 0;
			}
		}

		if(UpOrDown == true && checkUD == true)
		{
			vel.y += deceleration * dt;
			if(vel.y > 0 && !myKey[KEY_S])
			{
				vel.y = 0;
			}
		}
		Pos.y += vel.y;
	}

	if(!myKey[KEY_A] && !myKey[KEY_D] && vel.x != 0)
	{
		if(LeftOrRight == false && checkLR == false)
		{
			vel.x -= deceleration * dt;
			if(vel.x < 0 && !myKey[KEY_D])
			{
				vel.x= 0;
			}
		}

		if(LeftOrRight == true && checkLR == true)
		{
			vel.x += deceleration * dt;
			if(vel.x > 0 && !myKey[KEY_A])
			{
				vel.x = 0;
			}
		}
		Pos.x += vel.x;
	}

	translateObject(Pos);

	if(!myKey[KEY_W] && !myKey[KEY_A] && !myKey[KEY_S] && !myKey[KEY_D])
	{
		sf_walk = false;
	}

	switch(state)
	{
	case UP:
		{
			if(mesh != animationList[UP])
			{
				setMesh(animationList[UP]);
			}
			animationList[UP]->Update(dt);
			break;
		}
	case DOWN:
		{
			if(mesh != animationList[DOWN])
			{
				setMesh(animationList[DOWN]);
			}
			animationList[DOWN]->Update(dt);
			break;
		}
	case LEFT:
		{
			if(mesh != animationList[LEFT])
			{
				setMesh(animationList[LEFT]);
			}
			animationList[LEFT]->Update(dt);
			break;
		}
	case RIGHT:
		{
			if(mesh != animationList[RIGHT])
			{
				setMesh(animationList[RIGHT]);
			}
			animationList[RIGHT]->Update(dt);
			break;
		}
	case ATTACKUP:
		{
			if(mesh != animationList[ATTACKUP])
			{
				setMesh(animationList[ATTACKUP]);
			}
			animationList[ATTACKUP]->Update(dt);
			break;
		}
	case ATTACKDOWN:
		{
			if(mesh != animationList[ATTACKDOWN])
			{
				setMesh(animationList[ATTACKDOWN]);
			}
			animationList[ATTACKDOWN]->Update(dt);
			break;
		}
	case ATTACKLEFT:
		{
			if(mesh != animationList[ATTACKLEFT])
			{
				setMesh(animationList[ATTACKLEFT]);
			}
			animationList[ATTACKLEFT]->Update(dt);
			break;
		}
	case ATTACKRIGHT:
		{
			if(mesh != animationList[ATTACKRIGHT])
			{
				setMesh(animationList[ATTACKRIGHT]);
			}
			animationList[ATTACKRIGHT]->Update(dt);
			break;
		}
	};

	//Sound
	if (sf_walk == true)
	{
		my_sfx_man->play_plyr_steps();
	}

}