mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-09 20:32:43 +01:00
Implement weapon firing, debug tracers
This commit is contained in:
parent
0214a29ca3
commit
799127f8f8
@ -123,9 +123,10 @@ namespace Activities {
|
||||
DECL_ACTIVITY( ShootWeapon )
|
||||
|
||||
WeaponItem* _item;
|
||||
bool _fired;
|
||||
|
||||
ShootWeapon( WeaponItem* item )
|
||||
: _item(item) {}
|
||||
: _item(item), _fired(false) {}
|
||||
|
||||
bool update(CharacterObject *character, CharacterController *controller);
|
||||
};
|
||||
|
@ -112,7 +112,7 @@ public:
|
||||
/**
|
||||
* Performs a weapon scan against things in the world
|
||||
*/
|
||||
void doWeaponScan( WeaponScan& scan );
|
||||
void doWeaponScan(const WeaponScan &scan );
|
||||
|
||||
/**
|
||||
* Returns the current hour
|
||||
|
@ -45,6 +45,8 @@ class GameRenderer
|
||||
|
||||
float _renderAlpha;
|
||||
|
||||
std::vector<std::pair<glm::vec3, glm::vec3>> _tracers;
|
||||
|
||||
public:
|
||||
|
||||
GameRenderer(GameWorld*);
|
||||
@ -92,6 +94,10 @@ public:
|
||||
*/
|
||||
void renderPaths();
|
||||
|
||||
void addTracer(const glm::vec3& from, const glm::vec3& to) {
|
||||
_tracers.push_back({from, to});
|
||||
}
|
||||
|
||||
static GLuint currentUBO;
|
||||
template<class T> void uploadUBO(GLuint buffer, const T& data)
|
||||
{
|
||||
|
@ -184,6 +184,17 @@ bool Activities::ShootWeapon::update(CharacterObject *character, CharacterContro
|
||||
character->animator->setAnimation(shootanim, false);
|
||||
if( character->animator->getAnimationTime() >= wepdata->animLoopEnd / 100.f ) {
|
||||
character->animator->setAnimationTime( wepdata->animLoopStart / 100.f );
|
||||
_fired = false;
|
||||
}
|
||||
if( !_fired && character->animator->getAnimationTime() >= wepdata->animFirePoint / 100.f ) {
|
||||
auto farTarget = character->getPosition() +
|
||||
character->getRotation() * glm::vec3(0.f, wepdata->hitRange, 0.f);
|
||||
auto fireOrigin = character->getPosition() +
|
||||
character->getRotation() * wepdata->fireOffset;
|
||||
|
||||
character->engine->doWeaponScan(WeaponScan(wepdata->damage, fireOrigin, farTarget));
|
||||
|
||||
_fired = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -402,7 +402,7 @@ void GameWorld::destroyObject(GameObject* object)
|
||||
delete object;
|
||||
}
|
||||
|
||||
void GameWorld::doWeaponScan(WeaponScan &scan)
|
||||
void GameWorld::doWeaponScan(const WeaponScan &scan)
|
||||
{
|
||||
if( scan.type == WeaponScan::RADIUS ) {
|
||||
// TODO
|
||||
@ -411,6 +411,7 @@ void GameWorld::doWeaponScan(WeaponScan &scan)
|
||||
else if( scan.type == WeaponScan::HITSCAN ) {
|
||||
btVector3 from(scan.center.x, scan.center.y, scan.center.z),
|
||||
to(scan.end.x, scan.end.y, scan.end.z);
|
||||
glm::vec3 hitEnd = scan.end;
|
||||
btCollisionWorld::ClosestRayResultCallback cb(from, to);
|
||||
cb.m_collisionFilterGroup = btBroadphaseProxy::AllFilter;
|
||||
dynamicsWorld->rayTest(from, to, cb);
|
||||
@ -419,7 +420,7 @@ void GameWorld::doWeaponScan(WeaponScan &scan)
|
||||
if( cb.hasHit() ) {
|
||||
GameObject* go = static_cast<GameObject*>(cb.m_collisionObject->getUserPointer());
|
||||
GameObject::DamageInfo di;
|
||||
di.damageLocation = glm::vec3(cb.m_hitPointWorld.x(),
|
||||
hitEnd = di.damageLocation = glm::vec3(cb.m_hitPointWorld.x(),
|
||||
cb.m_hitPointWorld.y(),
|
||||
cb.m_hitPointWorld.z() );
|
||||
di.damageSource = scan.center;
|
||||
@ -427,6 +428,9 @@ void GameWorld::doWeaponScan(WeaponScan &scan)
|
||||
di.hitpoints = scan.damage;
|
||||
go->takeDamage(di);
|
||||
}
|
||||
|
||||
// Make the renderer draw a tracer.
|
||||
renderer.addTracer(scan.center, hitEnd);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -480,7 +480,34 @@ void GameRenderer::renderWorld(float alpha)
|
||||
glUniform4f(skyUniBottom, skyBottom.r, skyBottom.g, skyBottom.b, 1.f);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, skydomeSegments * skydomeRows * 6, GL_UNSIGNED_SHORT, NULL);
|
||||
|
||||
|
||||
// Draw bullets like this for now
|
||||
if( _tracers.size() > 0 ) {
|
||||
glUseProgram(worldProgram);
|
||||
glBindVertexArray( vao );
|
||||
glBindBuffer(GL_ARRAY_BUFFER, debugVBO);
|
||||
glBindTexture(GL_TEXTURE_2D, debugTex);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * _tracers.size() * 2, _tracers.data(), GL_STREAM_DRAW);
|
||||
GLint posAttrib = glGetAttribLocation(worldProgram, "position");
|
||||
glEnableVertexAttribArray(posAttrib);
|
||||
glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
uploadUBO<ObjectUniformData>(
|
||||
uboObject, {
|
||||
glm::mat4(),
|
||||
glm::vec4(1.f),
|
||||
1.f, 1.f
|
||||
});
|
||||
|
||||
float img3[] = {1.f, 1.f, 0.f};
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D, 0, GL_RGB, 1, 1,
|
||||
0, GL_RGB, GL_FLOAT, img3
|
||||
);
|
||||
glDrawArrays(GL_LINES, 0, _tracers.size());
|
||||
|
||||
_tracers.clear();
|
||||
}
|
||||
|
||||
glUseProgram(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
@ -744,6 +771,6 @@ void GameRenderer::renderPaths()
|
||||
glDrawArrays(GL_LINES, 0, pedlines.size());
|
||||
|
||||
pedlines.clear();
|
||||
carlines.clear();
|
||||
carlines.clear();
|
||||
glBindVertexArray( 0 );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user