Skip to main content
GameDev.net gamedev.net
🔒 Locked 🤖 Godot

3d math help needed

Started by rsud Apr 19, 2006 at 2:44 PM 8 replies 1.3k views
Original Post
rsud
rsud
Team name: A company will be formed shortly at the time game is released. Currently I am an independent developer that has coded a game engine and is prepping a first game for release. Follow-on games expected. The first game release will be in a series with follow-on games following an extended the storyline. Project name: Spaced based shooter Brief description: I need code to implement several simple (but not for me!) 3d math functions. Target aim: The game will be sold off of a website (no duh! :-) ) and will be considered retail game at a low price (approx $10). Compensation: I am of limited means at the moment but can pay on a "math function" basis. We can negotiate. Technology: Code will be in C or C++ and used in Visual C++ using directX Talent needed: Someone good with math and game physics. If you know directX and can write code to traverse vertices of a mesh you can help me even more. Team structure: I am the coder of the game engine that needs some math help. Website: None yet... Soon to come. Contacts: Please contact me at sudrajiv@hotmail.com
bodgey
bodgey
Hello, could you post some more information about the kind of functions you need. I wouldn't mind doing this for free if it doesn't take too long. Btw, maths and physics are my areas of expertise ;-)

Bojan
rsud
rsud
Hello Bojan,

Certainly I can post my first need... :-)

Lets hope I can describe it well enough in text:


In the game I have a space fighter which has a pivot point (center of the object around which it rotates, of course). For the fighter I have an orientation in radians and its place in world coordiates.

The fighter has engines which put out a exhaust flame. For an orientation of 0,0,0 radians I have manually figured out the engine nozzel offset from the pivot point. To create the exhaust I use a billboard. With xz being the horizontal plane the billboard is initially oriented along the horizontal plane along with the fighter. Now as the fighter banks I need a function to calculate the billboards rectagular coordinates so it maintains the same orientation as the fighter. A detail is that the length of the billboard (distance moving away from the nozzel) varies depending on how much thrust the fighter is putting out.

Hopefull I have described this somewhat clearly. I could put a graphic together that visually shows this if this description is not clear enough.
rsud
rsud
I should add to my above post before any work is done on this...

To be most useful and efficient for me:

I would want to get the soultion for this down to a function/code for which we would have agreed (and understood) what the input parameters are and what the output parameters are.

The inputs here would be:

- Orientation of object in radians using yaw, pitch, roll.
- Offset to the nozzel center edge at a yaw, pitch, roll of 0,0,0
- The width of the billboard on the horizontal axis per a yaw, pitch, roll of 0,0,0
- The length of the billboard (or length of thrust away from the nozzel) per a yaw, pitch, roll of 0,0,0

The return would be rectanglar coordinates for the billboard.
bodgey
bodgey
Quote:
Original post by rsud
The fighter has engines which put out a exhaust flame. For an orientation of 0,0,0 radians I have manually figured out the engine nozzel offset from the pivot point. To create the exhaust I use a billboard. With xz being the horizontal plane the billboard is initially oriented along the horizontal plane along with the fighter. Now as the fighter banks I need a function to calculate the billboards rectagular coordinates so it maintains the same orientation as the fighter.


I'm not sure if this is right, but do you want the billboard to rotate along with the fighter as if it was rigidly attached to it? If that's the case can't you use the same code you use to rotate the fighter itself?

Bojan
rsud
rsud
> but do you want the billboard to rotate along with the fighter as if it was rigidly attached to it?

You are quite right (and pointidly said)!

But, here are the (my) issues per the rest of your statement:

1) Rotation of the fighter mesh is nicely done for me by directX builtin functions where I just feed in the mesh and its rotation. The way (I have implement) the billboards is that I externally calculate the rectanglar points. I'm sure I could use the same methodology but haven't needed it since I can orient billboards around a pivot point fine as explosions, etc billboards must always face the camera and this I have done well (I am not total lightweight with math). My real problem is #2 below.

2) If the billboard is firmly attached to the engine nozzel I must calculate where the engine nozzle has gone too as the fighter rotates in order to know where to put the billboard. So the nozzel has an "arc" path as the fighter rotates. And then (with my method of implementation) I must calculate the rectangular coordinates from the nozzel point taking into account the fighter orientation. Head hurts...
bodgey
bodgey
Oh, that makes sense. Okay, I'll try to do it today. Do you mind posting the part of code that transforms the fighter, just the directx commands that are used to rotate it will do. (You can also email it to me on bdjo5912 at mail.usyd.edu.au). I'll get started on it now but I want to make sure I'm using the same yaw, pitch, roll order as you.

Bojan
bodgey
bodgey
I emailed you one version, I didn't test it thorougly though. If it doesn't work the way it's supposed to you'll need to post some information about the way you rotate your fighter.

Bojan
rsud
rsud
Hello Bojan,

I have not received any e-mail.

bodgey
bodgey
Quote:
Original post by rsud
Hello Bojan,

I have not received any e-mail.

That's strange, it sent through just fine. Maybe hotmail's marking it as spam. anyway here's the email I sent you:

Hello, I have something that seems to work for me. It probably won't work
correctly straight away because of the order of rotations, but you can try
it. When you calculate the relative position of the nozzle or the billboard
(relative to the pivot point), to rotate that point around the pivot point
you just pass it into the rotate_with_plane function like this:

Vector relative = (0, 0, -0.1); //0.1 units behind the pivot point
Vector rotated = rotate_with_plane(relative, yaw, pitch, roll);

and rotated will be the new vector relative to the pivot point. You then
just need to add the coordinates of the pivot point to translate the
rotated point to the correct location.

I'm not sure which rotation direction you take to be positive so it's
possible that some rotations will be reversed. You can try to change bits,
if it doesn't work you can send me the piece of code where you do your
rotation of the plane and I'll try to match that.

Bojan



#include <math.h>#include <iostream>using namespace std;//not very optimisedstruct Vector{  float x,y,z;  Vector() {}  Vector(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}};struct Matrix{  float a[3][3];};Matrix rotate_matrix(const Vector& n, float angle){  float s=sin(angle);  float c=cos(angle);  Matrix r;  r.a[0][0] = c + n.x*n.x*(1-c) + s*0;  r.a[0][1] = 0 + n.x*n.y*(1-c) + s*(-n.z);  r.a[0][2] = 0 + n.x*n.z*(1-c) + s*n.y;  r.a[1][0] = 0 + n.y*n.x*(1-c) + s*n.z;  r.a[1][1] = c + n.y*n.y*(1-c) + s*0;  r.a[1][2] = 0 + n.y*n.z*(1-c) + s*(-n.x);  r.a[2][0] = 0 + n.z*n.x*(1-c) + s*(-n.y);  r.a[2][1] = 0 + n.z*n.y*(1-c) + s*n.x;  r.a[2][2] = c + n.z*n.z*(1-c) + s*0;  return r;}Vector rotate(const Matrix& r, const Vector& a){  Vector b;  b.x = r.a[0][0]*a.x + r.a[0][1]*a.y + r.a[0][2]*a.z;  b.y = r.a[1][0]*a.x + r.a[1][1]*a.y + r.a[1][2]*a.z;  b.z = r.a[2][0]*a.x + r.a[2][1]*a.y + r.a[2][2]*a.z;  return b;}Vector rotate_with_plane(const Vector& point, float yaw, float pitch, float roll){  Vector up(0,1,0);  Vector left(-1,0,0);  Vector front(0,0,1);  Vector p=point;  cout << p.x << ' ' << p.y << ' ' << p.z << endl;  Matrix R1=rotate_matrix(up, yaw);  left = rotate(R1, left);  front = rotate(R1, front);  p = rotate(R1, p);  cout << p.x << ' ' << p.y << ' ' << p.z << endl;  Matrix R2=rotate_matrix(left, pitch);  up = rotate(R2, up);  front = rotate(R2, front);  p = rotate(R2, p);  cout << p.x << ' ' << p.y << ' ' << p.z << endl;  Matrix R3=rotate_matrix(front, roll);  up = rotate(R3, up);  left = rotate(R3, left);  p = rotate(R3, p);  cout << p.x << ' ' << p.y << ' ' << p.z << endl;  return p;}int main(int argc, char** argv){  //takes a vector relative to the pivot point  Vector r=rotate_with_plane(Vector(0.1,0.1,1), 0, 0, 0.1);  cout << r.x << ' ' << r.y << ' ' << r.z << endl;}


[Edited by - bodgey on April 22, 2006 10:31:46 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.