Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 07 Mar 2002
Offline Last Active Today, 08:43 AM

Posts I've Made

In Topic: Rotating Camera

21 July 2016 - 09:58 AM

So you need to translate to make the camera be at the origin, rotate the "look-at" point and then undo the translation.

Here's some C++ code that does what you want:
#include <iostream>

struct Vector {
  float x, y, z;
  Vector(float x, float y, float z) : x(x), y(y), z(z) {

struct Point {
  float x, y, z;
  Point(float x, float y, float z) : x(x), y(y), z(z) {

std::ostream &operator<<(std::ostream &os, Point p) {
  return os << '(' << p.x << ',' << p.y << ',' << p.z << ')';

Vector operator-(Point p1, Point p2) {
  return Vector(p1.x-p2.x, p1.y-p2.y, p1.z-p2.z);

Point operator+(Point p, Vector v) {
  return Point(p.x+v.x, p.y+v.y, p.z+v.z);

// --- Start reading here ---

Vector rotate_about_y_axis(Vector v, float cos, float sin) {
  return Vector(v.x * cos - v.z * sin, v.y, v.x * sin + v.z * cos);

Point rotate_about_y_axis_around_center(Point p, float cos, float sin, Point center) {
  return center + rotate_about_y_axis(p - center, cos, sin);

int main() {
  Point eye(0.0f, 1.2f, 0.0f);
  Point lookat(0.0f, 1.0f, -2.0f);
  float cos = 0.0f; // std::cos(angle)
  float sin = 1.0f; // std::sin(angle)
  Point rotated_lookat = rotate_about_y_axis_around_center(lookat, cos, sin, eye);
  std::cout << "lookat after rotation = " << rotated_lookat << '\n';

In Topic: Rotating Camera

20 July 2016 - 08:13 PM

You talk about rotating around your character, but you then don't include the character anywhere in the details of your problem. If you mean to rotate the camera without displacing it, you only need to rotate the center point around the eye point. If the character and the camera are not at the same point (unclear from your post), you'll need to rotate both `center' and `eye' around the character.

In order to rotate a point around another point, first apply a translation that makes the center of rotation be the origin, then rotate, then undo the translation.
Point rotate_around_point(Point p, Point center, Rotation rotation) {
  return rotate_around_origin(p - center, rotation) + center;

Are you missing anything?

In Topic: How To Start Game Programming With C++

20 July 2016 - 06:10 AM

I would start by installing SFML and going through their tutorials.

In Topic: Move The Player Along The Direction It Is Facing

18 July 2016 - 06:07 AM

I would generally recommend against using quaternions unless you can explain in great detail why they are superior to matrices. There are cases where quaternions are the answer, but pitch, yaw, and roll (which are not Euler angles by the way) not being functional is not one of them.

Quaternions are more compact, much easier to renormalize and better for interpolating. Is that enough detail for you?

Regardless of how you are representing rotations internally, you should have a mechanism to apply a rotation to a vector, without worrying about the details. So your code should look something like this:
void InputPlayer::MoveForward(float dt) {
  player->SetPos(player->GetPos() + apply_rotation(player->GetAttitude(), glm::vec3(0, 0, 5)));

In Topic: Particle Lighting 101

17 July 2016 - 05:30 PM

It looks like HL2 does mean Half Life 2. They seem to use a particular orthonormal basis in their lighting computations. The slide "Resurrecting an old friend: HL2 basis" has the exact vectors. You can also find them here: http://www.valvesoftware.com/publications/2006/SIGGRAPH06_Course_ShadingInValvesSourceEngine.pdf