当前位置: 首页>>代码示例>>C++>>正文


C++ Entity::GetEntityPosition方法代码示例

本文整理汇总了C++中Entity::GetEntityPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Entity::GetEntityPosition方法的具体用法?C++ Entity::GetEntityPosition怎么用?C++ Entity::GetEntityPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Entity的用法示例。


在下文中一共展示了Entity::GetEntityPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sendMovePacket

void ServerGame::sendMovePacket(ClassId class_id, int obj_id)
{
		Entity* ent = (Entity*)(EntitySpawner::instance()->GetEntity(class_id, obj_id));

		// If this is not a player and the player is dead, don't update
		if (class_id == ClassId::PLAYER)
		{
			if (!((Player*)ent)->IsAlive())
				return;
		}

        Packet packet;
		packet.hdr.sender_id = SERVER_ID;
        packet.hdr.packet_type = MOVE_EVENT;

        PosInfo p;
        packet.dat.game_data_id = POS_OBJ;
	
		// Extract the vector and send it with the posinfo object
		btVector3 vec = ent->GetEntityPosition();

		p.cid = class_id;
		p.oid = obj_id;
		p.x = vec.getX();
		p.y = vec.getY();
		p.z = vec.getZ();

		if (class_id == PLAYER) {
			p.num_eggs = ((Player*)ent)->GetScore();
			p.jump = ((Player*)ent)->GetJumpSem();
			p.hp = ((Player*)ent)->GetHP();
		}

        p.serialize(packet.dat.buf);

        const unsigned int packet_size = sizeof(Packet);
        char packet_data[packet_size];

        packet.serialize(packet_data);

        network->sendToAll(packet_data, packet_size);
}
开发者ID:bhn26,项目名称:CSE125,代码行数:42,代码来源:ServerGame.cpp

示例2: sendRotationPacket

void ServerGame::sendRotationPacket(int class_id, int obj_id) {
    const unsigned int packet_size = sizeof(Packet);
    char packet_data[packet_size];

	Entity* ent = (Entity*)(EntitySpawner::instance()->GetEntity(class_id, obj_id));

	// If this is not a player and the player is dead, don't update
	if (class_id == ClassId::PLAYER)
	{
		if (!((Player*)ent)->IsAlive())
			return;
	}

    Packet packet;
	packet.hdr.sender_id = SERVER_ID;
    packet.hdr.packet_type = V_ROTATION_EVENT;

    packet.dat.game_data_id = POS_OBJ;

	PosInfo p;
	p.cid = (ClassId) class_id;
	p.oid = obj_id;

	// why do we switch w and y and multiply by negative, we don't know but it fixes it
	btQuaternion q = ent->GetEntityRotation();
	btVector3 v = ent->GetEntityPosition();
	p.x = v.getX();
	p.y = v.getY();
	p.z = v.getZ();
	p.rotw = q.getW();
	p.rotx = q.getX();
	p.roty = q.getY();
	p.rotz = q.getZ();

    p.serialize(packet.dat.buf);
    
    packet.serialize(packet_data);

	network->sendToAll(packet_data, packet_size);
}
开发者ID:bhn26,项目名称:CSE125,代码行数:40,代码来源:ServerGame.cpp


注:本文中的Entity::GetEntityPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。