You may want to first cast a ray and then fire. Here below is a way do it, the variable direction in the second snippet is coming from the raycast or could be the position of your camera.

**Code:**

glm::vec3 Camera::castRay(glm::ivec2 mousePosition) {

logStderr(VERBOSE, "mouse position %d, %d...\n", mousePosition.x, mousePosition.y);

float tanFOV = 1.0f / NEAR_PLANE;

float aspect = WINDOW_WIDTH / (float)WINDOW_HEIGHT;

glm::vec3 viewVector = -glm::normalize(m_viewVector);

viewVector *= FAR_PLANE;

glm::vec3 upVector = glm::normalize(m_upVector);

upVector *= FAR_PLANE * tanFOV;

glm::vec3 rightVector = glm::normalize(m_rightVector);

rightVector *= FAR_PLANE * tanFOV;

rightVector *= aspect;

glm::vec3 center = m_cameraPosition + viewVector;

glm::vec3 horizontalDistance = 1.0f / float(WINDOW_WIDTH) * rightVector;

glm::vec3 verticalDistance = upVector / float(WINDOW_HEIGHT);

glm::vec3 raycast = center - 0.5f * rightVector + 0.5f * upVector;

raycast += (float)mousePosition.x * horizontalDistance;

raycast -= (float)mousePosition.y * verticalDistance;

logFileStderr(VERBOSE, "raycast: "); printVec3(raycast);

return raycast;

}

void Inception::shootGeode(std::string typeGeode, const btVector3& direction) {

logStderr(VERBOSE, "MESSAGE: Shooting geode(s)...\n");

std::shared_ptr<Geode> geode;

glm::vec3 cameraPosition = m_camera->getPosition();

btVector3 position = glm2bullet(cameraPosition + 3.0f * glm::normalize(m_camera->getTarget() - cameraPosition));

if (typeGeode == "cube")

geode = m_objectFactory->createCube("cube", new btBoxShape(btVector3(1.0f, 1.0f, 1.0f)), position, "dice");

if (typeGeode == "sphere")

geode = m_objectFactory->createSphere("sphere", new btBoxShape(btVector3(1.0f, 1.0f, 1.0f)), position);

btVector3 velocity = direction;

velocity.normalize();

velocity *= 25.0f;

geode->getRigidBody()->setLinearVelocity(velocity);

}