Пример #1
0
void Camera::Update(float deltaTime, GLFWwindow* window)
{
	// detect wasd key presses and move camera
	vec3 cameraMove = vec3();

	// move camera based on inputs and its forward/right/up vectors
	if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
		cameraMove += GetForward() * moveForwardSpd;
	if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
		cameraMove -= GetRight() * moveLeftSpd;
	if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
		cameraMove -= GetForward() * moveBackSpd;
	if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
		cameraMove += GetRight() * moveRightSpd;
	if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
		cameraMove += GetUp() * moveUpSpd;
	if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
		cameraMove -= GetUp() * moveDownSpd;
	if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) {
		glfwTerminate();
		std::exit(0);
	}

	// move the camera from the movement and delta time
	vec3 cameraPos = GetPosition();
	SetPosition(cameraPos + cameraMove*deltaTime);
}
Пример #2
0
	void Camera::UpdateMatrix()
	{
		int width = Screen::GetWidth();
		int height = Screen::GetHeight();
		auto transform = GetTransform();

		m_view_matrix = Matrix4x4::LookTo(
			transform->GetPosition(),
			transform->GetForward(),
			transform->GetUp());
		
		if(!m_orthographic)
		{
			m_projection_matrix = Matrix4x4::Perspective(m_field_of_view, width / (float) height, m_near_clip_plane, m_far_clip_plane);
		}
		else
		{
			float top = m_orthographic_size;
			float bottom = -m_orthographic_size;
			float plane_h = m_orthographic_size * 2;
			float plane_w = plane_h * (width * m_rect.width) / (height * m_rect.height);
			m_projection_matrix = Matrix4x4::Ortho(-plane_w/2, plane_w/2, bottom, top, m_near_clip_plane, m_far_clip_plane);
		}

		m_view_projection_matrix = m_projection_matrix * m_view_matrix;
	}
Пример #3
0
void Star::Update()
{
	PhysicsObject::Update();
	this->Translate(GetForward()*speed);
	if(speed > 0.3)
		this->speed -= 0.01;
}
Пример #4
0
	void Door::Update(float delta)
	{
		if(!_active && _counter < 1.0f)
		{
			Player *player = Player::GetSharedInstance();
			
			if(player->GetWorldPosition().GetDistance(GetWorldPosition() - GetForward()) <= 1.0f)
			{
				_active = true;
			}
		}
		else
		{
			Rotate(RN::Vector3(delta*70.0f, 0.0f, 0.0f));
			_counter += delta;
		}
		
		if(_counter > 1.0f && _active)
		{
			_active = false;
			RN::Kernel::GetSharedInstance()->ScheduleFunction([](){
				World *world = static_cast<World*>(RN::World::GetActiveWorld());
				world->SetLevel(world->GetLevel() + 1);
				world->DropSceneNodes();
				world->LoadOnThread(RN::Thread::GetCurrentThread(), nullptr);
			});
		}
	}
Пример #5
0
void Player::CalculateRight() {
	sf::Vector2f f = GetForward();
	m_Right = sf::Vector2f(-f.y, f.x);

	float mag = std::sqrt(std::pow(m_Right.x, 2.f) + std::pow(m_Right.y, 2.f));
	m_Right *= (std::tan(m_FOV/2.f)/mag);
}
Пример #6
0
void Shoot( Actor* actor, EntityFactory* ef )
{
	cml::vector2f shootdir = GetForward( actor );
	ef->SpawnEnemyBullet(
			GetWorld2DPos( actor->transform.position ) + shootdir, 	// shoot point
			shootdir * actor->wep.bullet_speed, 	// weapon bullet speed
			actor->wep.bullet_duration );			// weapon bullet lifetime

}
Пример #7
0
void FireBall::Update()
{
	//if(particles == NULL)
	//{
	//	/*particles = new Particles(AllDirections, BoxPosition, false, gen, Point3D(3.0, 3.0, 3.0), angleGen, AfterE, 14, 9);
	//	scene->AddObject(particles);*/
	//}
	Translate(GetForward()*5);
	//particles->Translate(Point3D(-particles->GetTranslate().x+translate.x, 0.0, -particles->GetTranslate().z+translate.z));
}
Пример #8
0
void Player::Tick(float dt) {
	m_Moving = false;

	// player movement
	sf::Vector2f d(0.f, 0.f);

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
		d.x += GetForward().x;
		d.y += GetForward().y;
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
		d.x -= GetForward().x;
		d.y -= GetForward().y;
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
		d.x -= GetRight().x;
		d.y -= GetRight().y;
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
		d.x += GetRight().x;
		d.y += GetRight().y;
	}

	float mag = std::sqrt(std::pow(d.x, 2.f) + std::pow(d.y, 2.f));

	if (mag > 0) {
		m_Moving = true;
		d*= 1.3f;

		if (m_Sprinting && !m_Crouching)
			d *= 1.5f;

		if (m_Crouching) {
			d *= 0.5f;
		}

		Move(1.8f*dt*d/mag);
	}
}
Пример #9
0
void slSubscription::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
{
    if (!expandedKids)
    {
        expandedKids = true;

        browser->RemoveDummyChild(this);
        // Log

        if (WantDummyChild())
        {
            wxTreeItemId id = browser->GetItemParent(browser->GetItemParent(GetId()));
            if (id)
            {
                slSet *set = (slSet *)browser->GetObject(id);
                if (set && set->IsCreatedBy(setFactory))
                {
                    wxLogInfo(wxT("Adding child object to subscription %s"), GetIdentifier().c_str());

                    browser->AppendCollection(this, slSequenceFactory);
                    browser->AppendCollection(this, slTableFactory);
                }
            }
        }
    }


    if (properties)
    {
        CreateListColumns(properties);

        properties->AppendItem(_("Provider ID"), GetProviderId());
        properties->AppendItem(_("Provider Name"), GetProviderNode());
        properties->AppendItem(_("Receiver ID"), GetReceiverId());
        properties->AppendItem(_("Receiver Name"), GetReceiverNode());

        properties->AppendYesNoItem(_("Active"), GetActive());
        properties->AppendYesNoItem(_("May forward"), GetForward());
        if (GetForward())
            properties->AppendYesNoItem(_("Is forwarded"), GetIsSubscribed());
    }
}
Пример #10
0
 void Camera::RotateAroundPosition(F32 leftRot, F32 upRot, F32 forwardRot) {
     Matrix rot = Matrix::CreateFromAxis(GetLeft(), -leftRot) * 
                 Matrix::CreateFromAxis(Vector3f::Up, -upRot) * 
                 Matrix::CreateRotationAxis(GetForward(), forwardRot);
     Vector3f direction = Vector3f::Normalize(target - position);
     Vector3f newDirection = Vector3f::TransformVector(direction, rot);
     Vector3f newUp = Vector3f::TransformVector(up, rot);
     SetTarget(position + newDirection);
     SetUp(newUp);
     isViewValid = false;
 }
Пример #11
0
D3DXVECTOR3 Camera::GetParallelRight() const
{
	D3DXVECTOR3 up, returnedValue;

	//Point "up"
	up.x = 0.0f;
	up.y = 1.0f;
	up.z = 0.0f;

	D3DXVec3Cross(&returnedValue, &up, &GetForward());

	return returnedValue;
}
void Destructible::EmitDamageParticles(const char *particleName, const Damage_t *damage, Vector2D position)
{
    if (particleName != nullptr && *particleName != 0)
    {
        Vector2D direction(GetForward());

        if (damage != nullptr)
        {
            direction = damage->direction;
        }

        GetGameContext()->GetParticleRoot()->CreateParticles(particleName,
                                          position, direction);
    }
}
Пример #13
0
void FreeMove::ProcessInput(const Input& input, float delta)
{
	float movAmt = m_speed;

	if (input.GetKeyUp(m_forwardKey))
		Move(GetForward(*GetTransform()->GetRot()), movAmt);
	if (input.GetKeyUp(m_backKey))
		Move(GetBack(*GetTransform()->GetRot()), movAmt);
	if ( input.GetKeyUp ( m_leftKey ) )
		Move(GetLeft(*GetTransform()->GetRot()), movAmt);
	if ( input.GetKeyUp ( m_rightKey ) )
		Move(GetRight(*GetTransform()->GetRot()), movAmt);



}
Пример #14
0
wxString slSubscription::GetSql(ctlTree *browser)
{
    if (sql.IsNull())
    {
        if (GetReceiverId() != GetCluster()->GetLocalNodeID())
            sql = wxT("-- Subscription must be maintained on receiver node.\n");
        else
            sql = wxT("-- subscribe replication set\n\n")
                  wxT(" SELECT ") + GetCluster()->GetSchemaPrefix() + wxT("subscribeset(")
                  + NumToStr(GetSet()->GetSlId()) + wxT(", ")
                  + NumToStr(GetProviderId()) + wxT(", ")
                  + NumToStr(GetReceiverId()) + wxT(", ")
                  + BoolToStr(GetForward()) + wxT(");");
    }
    return sql;
}
Пример #15
0
cVector3f cGameLadder::GetStartPosition()
{
	iCharacterBody *pCharBody = mpInit->mpPlayer->GetCharacterBody();

	cVector3f vPos = pCharBody->GetPosition();
	cVector3f vLadderPos =	GetBody(0)->GetWorldPosition() + 
							GetForward()*pCharBody->GetSize().x *0.6f;
	vLadderPos.y = vPos.y+0.05f;

	if(vLadderPos.y > mfMaxY - pCharBody->GetSize().y*0.3f)
		vLadderPos.y = mfMaxY - pCharBody->GetSize().y*0.3f;
	
	if(vLadderPos.y - pCharBody->GetSize().y/2 < mfMinY)
		vLadderPos.y = mfMinY + pCharBody->GetSize().y/2+0.1f;
	
	return vLadderPos;
}
Пример #16
0
void Projectile::OnCollision(ICollidable *other)
{
    Remove();

    if (!data.particle_hit.empty())
        GetGameContext()->GetParticleRoot()->CreateParticles(data.particle_hit.c_str(), GetOrigin(), GetForward());

    Entity *entity = (Entity*)other;

    Damage_t damage;
    damage.damage = 1;
    damage.inflictor = this;
    damage.direction = GetForward();
    damage.statsInflictorName = inflictorName;
    damage.statsInflictorClass = inflictorClass;
    damage.statsWeaponName = GetEntityClassName();
    damage.statsWeaponClass = GetEntityResourceClass();
    entity->TakeDamage(damage);
}
Пример #17
0
void FreeCamera::Update(const tt::GameContext& context)
{
	auto pInputService = MyServiceLocator::GetInstance()->GetService<IInputService>();
	auto pTransform = GetComponent<TransformComponent>();
	
	if(pInputService->IsActionTriggered(InputActionId::CameraMoveForward))
		pTransform->Translate(pTransform->GetForward() * m_MovementSpeed, true);
	
	if(pInputService->IsActionTriggered(InputActionId::CameraMoveBack))
		pTransform->Translate(pTransform->GetBackward() * m_MovementSpeed, true);
	
	if(pInputService->IsActionTriggered(InputActionId::CameraMoveLeft))
		pTransform->Translate(pTransform->GetLeft() * m_MovementSpeed, true);
	
	if(pInputService->IsActionTriggered(InputActionId::CameraMoveRight))
		pTransform->Translate(pTransform->GetRight() * m_MovementSpeed, true);

	if(pInputService->IsActionTriggered(InputActionId::CameraMoveUp))
		pTransform->Translate(pTransform->GetUp() * m_MovementSpeed, true);
	
	if(pInputService->IsActionTriggered(InputActionId::CameraMoveDown))
		pTransform->Translate(pTransform->GetDown() * m_MovementSpeed, true);

	if(!pInputService->IsActionTriggered(InputActionId::CameraUnlockRotation))
		return;

	auto mouseMovement = pInputService->GetMouseMovement();
	mouseMovement *= m_RotationSpeed * context.GameTimer.GetElapsedSeconds();
	m_Yaw += mouseMovement.x;
	m_Pitch += mouseMovement.y;

	tt::Quaternion yawQuat(tt::Vector3::j, m_Yaw);
	tt::Vector3 rotatedRight = tt::Vector3::i.TransformPoint(yawQuat);
	tt::Quaternion pitchQuat(rotatedRight, m_Pitch);

	pTransform->Rotate(yawQuat * pitchQuat);
}
Пример #18
0
void DoSensePlayer( Mob* actor, Player* player )
{
	cml::vector3f playerpos = player->transform.position;
	cml::vector3f mob2player = actor->transform.position - playerpos;
	float angle_to_player = 0;
	actor->player_distance = cml::length( mob2player );
	bool player_visible = false;
	if( actor->player_distance < actor->vision.distance )
	{
		cml::vector2f mob_forward = GetForward( actor );
		angle_to_player = cml::deg(cml::signed_angle_2D( mob_forward, cml::vector2f(mob2player[0],mob2player[2]) ));

			if( abs(angle_to_player) < actor->vision.angle)
			{
				// comprobamos que no haya algun elemento del mapa interrumpiendo la visión
				b2Body* b = actor->GetPhysicBody();
				cml::vector3f actorpos = actor->transform.position;
				cml::vector3f playerpos = player->transform.position;
				if( actorpos != playerpos )
				{
					MyRayCB tehcb;
					tehcb.SetOrigin();
					b2Vec2 apos(-actorpos[0],-actorpos[2]);
					b2Vec2 ppos(-playerpos[0],-playerpos[2]);

					b->GetWorld()->RayCast( &tehcb, apos, ppos );

					// si el rayo NO ha colisionado con algun elemento del mapa, tenemos al player en el cono!
					player_visible = !tehcb.didcollide;
				}
			}
	}
	//if( !player_visible ) actor->angle_to_player = NO_PLAYER;
	actor->angle_to_player = angle_to_player;
	actor->player_visible = player_visible;
}
Пример #19
0
// Called when the game starts or when spawned
void AEnemy::BeginPlay()
{
	Super::BeginPlay();

	//Set Random Material
	int randMat = FMath::RandRange(0, enemyMaterials.Num() - 1);
	StaticMesh->SetMaterial(0, enemyMaterials[randMat]);
	
	//Get reference to gamestate
	gameState = GetWorld() != NULL ? GetWorld()->GetGameState<APacGameState>() : NULL;
	
	//Find player
	for (TActorIterator<AActor> It(GetWorld()); It; ++It)
	{
		AActor* Actor = *It;
		if (Actor->ActorHasTag(FName(TEXT("player"))))
		{
			player = (AUfo*)Actor;
		}
	}

	ufoVelocity = FVector(0.0f, 1.0f, 0.0f)*velMultiplier;
	GetForward();
}
Пример #20
0
// Called every frame
void AEnemy::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );

	//Handles movement
	if (!ufoVelocity.IsZero())
	{
		float railOffsetX = FMath::Fmod(StaticMesh->GetComponentLocation().X, 100.0f);
		float railOffsetY = FMath::Fmod(StaticMesh->GetComponentLocation().Y, 100.0f);

		//If path is clear, consider changing direction
		changedDirTime += DeltaTime;
		if (railOffsetX <= 5.0f && railOffsetY <= 5.0f && changedDirTime >= minChangeDirTime)
		{
			ChangeDir();
			changedDirTime = 0.0f;
		}

		//Try to keep it on rails
		GetForward();
		ufoVelocity = forward*velMultiplier;
		if (forward.X != 0)
		{
			if (railOffsetY > 50.0f)
			{
				ufoVelocity.Y += (100.0f - railOffsetY)*velMultiplier / 50.0f;
			}
			else 
			{
				ufoVelocity.Y -= railOffsetY*velMultiplier / 50.0f;
			}
		}
		else if (forward.Y != 0)
		{
			if (railOffsetX > 50.0f)
			{
				ufoVelocity.X += (100.0f - railOffsetX)*velMultiplier / 50.0f;
			}
			else
			{
				ufoVelocity.X -= railOffsetX*velMultiplier / 50.0f;
			}
		}

		ufoVelocity.Z = (100.0f - StaticMesh->GetComponentLocation().Z);

		//Apply Velocity
		StaticMesh->SetAllPhysicsLinearVelocity(ufoVelocity);

		//Set facing to the direction of movement
		FRotator currRot = StaticMesh->GetComponentRotation();
		FRotator nextRot = FRotator(0.0f, ufoVelocity.Rotation().Yaw, 0.0f);
		float deltaRot = (nextRot - currRot).Yaw;

		//Needed for smooth transitions on yaw limits (0 or 360)
		if (deltaRot >= 180 || deltaRot <= -180)
		{
			deltaRot = -FMath::Sign(deltaRot)*(360 - FMath::Abs(deltaRot));
		}

		if (FMath::Abs(deltaRot) > 0)
		{
			StaticMesh->SetAllPhysicsAngularVelocity(FVector(0.0f, 0.0f, FMath::Sign(deltaRot)*rotMultiplier));
		}
		else
		{
			StaticMesh->SetAllPhysicsAngularVelocity(FVector(0.0f, 0.0f, FMath::Sign(deltaRot)*rotMultiplier*0.1f));
		}
	}
}
Пример #21
0
cVector3f cGameLadder::GetStartRotation()
{
	iCharacterBody *pCharBody = mpInit->mpPlayer->GetCharacterBody();

	return cMath::GetAngleFromPoints3D(cVector3f(0,0,0), GetForward()*-1);
}
Пример #22
0
PAVECTOR	CBody::GetForwardPAVector(void) const
{
	return PAVector(GetForward());
}
Пример #23
0
void	CBody::AdjustRoll(float radianAngle)
{
	AdjustAxisAngle(GetForward(), radianAngle);
}
Пример #24
0
void		CBody::AdjustRollVelocity(float radianAngle)
{
	AdjustAxisVelocity(GetForward(), radianAngle);
}
Пример #25
0
 Vector3f Camera::GetLeft() const {
     return Vector3f::Cross(GetUp(), GetForward());
 }
Пример #26
0
void AEnemy::ChangeDir()
{
	//Check which sides are clear
	FCollisionQueryParams Params;
	Params.AddIgnoredActor(this);

	//Debug draw lines
	//const FName TraceTag("MyTraceTag");
	//GetWorld()->DebugDrawTraceTag = TraceTag;
	//Params.TraceTag = TraceTag;
	
	FHitResult HitF;
	FHitResult HitL;
	FHitResult HitR;

	float range = 150.0f;

	GetForward();

	FVector Start = StaticMesh->GetComponentLocation();
	
	FVector EndF = Start + forward*range/3.0f;
	FVector EndL = Start + forward.RotateAngleAxis(90.0f, FVector::UpVector)*range;
	FVector EndR = Start + forward.RotateAngleAxis(-90.0f, FVector::UpVector)*range;
	
	bool bHitF = GetWorld()->LineTraceSingleByChannel(HitF, Start, EndF, ECC_WorldStatic, Params);
	bool bHitL = GetWorld()->LineTraceSingleByChannel(HitL, Start, EndL, ECC_WorldStatic, Params);
	bool bHitR = GetWorld()->LineTraceSingleByChannel(HitR, Start, EndR, ECC_WorldStatic, Params);

	//Make sure hit results from level objects
	if (bHitF)
	{
		bHitF = HitF.GetActor()->ActorHasTag(TEXT("level"));
	}
	if (bHitL)
	{
		bHitL = HitL.GetActor()->ActorHasTag(TEXT("level"));
	}
	if (bHitR)
	{
		bHitR = HitR.GetActor()->ActorHasTag(TEXT("level"));
	}

	TArray<int> dummy;
	dummy.Add(0);
	if (!bHitL)
	{
		dummy.Add(1);
	}
	if (!bHitR)
	{
		dummy.Add(2);
	}

	int randInt = FMath::Trunc(FMath::RandRange(0.0f, (float)dummy.Num()));
	if (randInt > dummy.Num() - 1)
	{
		randInt = dummy.Num() - 1;
	}
	int randResult = dummy[randInt];
	switch (randResult)
	{
	case 0:
		if (bHitF)
		{
			ufoVelocity = -forward*velMultiplier;
		}
		break;
	case 1:
		ufoVelocity = forward.RotateAngleAxis(90.0f, FVector::UpVector)*velMultiplier;
		break;
	case 2:
		ufoVelocity = forward.RotateAngleAxis(-90.0f, FVector::UpVector)*velMultiplier;
		break;
	}

	GetForward();
}
Пример #27
0
bool MovingCamera::Update(float elapsedTime)
{
	#pragma region WASD EQ

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
	{
		IncrementPosition(GetForward() * moveSpeed * elapsedTime);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
	{
		IncrementPosition(-GetForward() * moveSpeed * elapsedTime);
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
	{
		IncrementPosition(GetSideways() * moveSpeed * elapsedTime);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
	{
		IncrementPosition(-GetSideways() * moveSpeed * elapsedTime);
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::E))
	{
		IncrementPosition(GetUpward() * -moveSpeed * elapsedTime);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q))
	{
		IncrementPosition(GetUpward() * moveSpeed * elapsedTime);
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
	{
		return true;
	}

	#pragma endregion

	#pragma region Mouse

	if (Window == 0)
	{
		return false;
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
	{
        if (!pressedLastFrame)
        {
            Window->setMouseCursorVisible(true);
            pressedLastFrame = true;
            camPaused = !camPaused;
        }
	}
    else pressedLastFrame = false;

    if (camPaused) return false;

	Window->setMouseCursorVisible(false);

	Vector2i mousePos = Conv(sf::Mouse::getPosition());
	Vector2i delta = mousePos - mouseTarget;

	Vector2f rotAmount(delta.x * rotSpeed * elapsedTime, delta.y * rotSpeed * elapsedTime);

	sf::Mouse::setPosition(Conv(mouseTarget));

	AddPitch(-rotAmount.y);
	AddYaw(rotAmount.x);

	#pragma endregion

	return false;
}
Пример #28
0
AglVector3 AglMatrix::GetBackward() const
{
	return -GetForward();
}
Пример #29
0
/// Returns location camera is looking at
vec3 Camera::GetLookAt()
{
	return GetPosition() + GetForward();
}
Пример #30
0
/// Return right vector from camera
vec3 Camera::GetRight()
{
	// Right will be cross of up and forward
	// Becaues it's perpendicular to both
	return cross(GetForward(), GetUp());
}