• Create Account

# Ravnock

Member Since 15 Jul 2008
Offline Last Active Apr 04 2016 12:23 AM

### #5045208The Problems about the FPS Camera

Posted by on 21 March 2013 - 05:30 AM

Hi,every one,

I am a novice in the 3D math.currently , I am tortured by a problem about the rotation of a FPS camera.hope someone can help me .

please allow me to assume that the discussion is based on OpenGL conversion.

suppose the FPS camera is placed at the initial state in which the three axis of camera are aligned with axis of world frame.

I firstly pitch the camera around the x axis of world frame, and then yaw the camera around the y axis of world frame.so I can get the following equation(column-major) :

camera_orientation_matrix_1 = yaw_yworld_matrix * pitch_xworld_matrix =  rotateY(yaw_angle)  *  rotateX(pitch_angle);

some reference  informed me that I can get the same orientation by using the local rotation matrix but applied in a reverse order.

so I firstly yaw the camera with local y axis of camera, then pitch the camera around the local x axis of the camrea.

ie: camera_orientation_matrix _2 = pitch_xlocal_matrix * yaw_ylocal_matrix = rotateX(pitch_angle) * rotateY(yaw_angle) ;

since the  camera_orientation_matrix_1 equals camera_orientation_matrix _2, I derive the following:

rotateY(yaw_angle)  *  rotateX(pitch_angle) === rotateX(pitch_angle) * rotateY(yaw_angle) ;

but the above equation is a fallacy,Is there anyone can tell me where is wrong? Thanks!

From Wikipedia (general case): For n greater than 2, multiplication of n×n rotation matrices is not commutative.

http://en.wikipedia.org/wiki/Rotation_matrix

### #5045195pacman sound effects copyrights and ghost image

Posted by on 21 March 2013 - 04:49 AM

Hi all. I would like to use old pacman sound effect and some images to make my own game.
Do you know if it's legal? there are problems of copyrights?

There was another discussion about copyrights here http://www.gamedev.net/topic/544351-can-you-give-away-free-remakes-of-old-games/ (very polemic, indeed and with opposite opinions), for example:

Names, ideas, concepts and techniques cannot be copyrighted, in other words, the actual game aspect of a game cannot be copyrighted. I don't know why people are implying otherwise to be honest.

The parts of a game that can be copyrighted are sounds (sound effects and music), graphics (photographs, icons, fonts, sprites, etc), literature (instructions, dialogs, etc) and cutscenes.

So you can recreate Pacman without copyright issue provided you don't use the same sound effects and sprites (or sound effects and sprites that have been derived from the originals). If you make brand new sprites and brand new sound effects then you're fine. Though you might not really consider it to be a Pacman clone by then perhaps.

This another website speak about that:

### #5043858help 3D space problem

Posted by on 16 March 2013 - 07:17 PM

given 2 points "a" and "b" in 3D space

b= center of a sphere always radius 1

I want to find vector direction "d"

The "d"s of the answer form a cone around a part of the sphere, i just need one "d"

If c is the intersection point, you know that distance(b,c) =1, the angle between vector(b,c) and vector(a,c) is 90, and the distance(a,c) is known, so you can apply the pythagorean theorem.

distance(a,b)^2 = distance(b,c) ^2 + distance(c,a)

You can easyly get the distance(a,c)

Then it seems to be a Circle-circle intersection problem (Circle 1: center in a, radius is distance a,c and Circle 2: center is b distance 1)

### #5043748VC++ 2010 crashes on ShowWindow(..)

Posted by on 16 March 2013 - 01:42 PM

You're not checking the return value from your CreateWindowEx call (a run in your debugger with a breakpoint set at your ShowWindow call would have told you that you didn't have a valid HWND here).  Also, some of your CreateWindowEx parameters are wrong - please review the documentation at http://msdn.microsoft.com/en-us/library/windows/desktop/ms632680%28v=vs.85%29.aspx and correct them before continuing any further with this.

If it worked on one PC it was certainly by accident rather than by design.

I am trying to shift my project to my other computer. I think I have the compiler set up properly. Initially, I thought it was DX causing the issue, but I narrowed it down to WinMain(..). Here is the code:

```int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc;

ZeroMemory(&wc, sizeof(WNDCLASSEX));

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
// wc.hbrBackground = (HBRUSH)COLOR_WINDOW;    // not needed any more
wc.lpszClassName = "WindowClass";

RegisterClassEx(&wc);

hWnd = CreateWindowEx(NULL,
"WindowClass",
"Our Direct3D Program",
WS_EX_TOPMOST | WS_POPUP,    // fullscreen values
0, 0,    // the starting x and y positions should be 0
int(SCREEN_WIDTH),int( SCREEN_HEIGHT),    // set the window size
NULL,
NULL,
hInstance,
NULL);
//return 0;//exits without crashing
ShowWindow(hWnd, nCmdShow);
return 0;//it will crash here
// set up and initialize Direct3D
GameEngine.initD3D(hWnd,hInstance);

//init the environment here.

// enter the main loop:
UINT ExitMessage=GameEngine.MainLoop();

return ExitMessage;
}

```

Notice the 2 return lines arround ShowWindow(..)? That's how I came to the conclusion it had something to do with showing the window. I believe it's the creation that's actually causing the problem, but I don't know what could cause it to work on one machine and not another. Perhapse I don't have the correct SDK (VC) or I don't have my compiler set up correctly????

If I am not wrong...WS_EX_TOPMOST is an extended style, the extended styles shoud be in the first parameter and the "normal" styles in the fourth

So it should be CreateWindowEx(WS_EX_TOPMOST,  "WindowClass", "Our Direct3D Program", WS_POPUP,...

Probably the WS_EX_TOPMOST is being interpreted wrong and there is a conflict with the WS_POPUP

### #5043067Finding if a player is facing the back of another.

Posted by on 14 March 2013 - 08:38 AM

Hello there guys, I am creating a game based on arena matches, with RPG style fights. I want some abilities to be more poweful (or only usable) when you are facing the enemy's back.

Assuming I have two entities (player or AI controlled pet) and that I know their positions and looking angles, is there any direct way to find the if one is facing the back of the other?

Right now I am using a quadrant approach, for instance If I had two entities A and B and I wanted to know if A is on B's back.

1) I define which quadrant B is relatively to A (assuming A's position as the origin).

2) I add and subtact 45º from A's looking angle and find the quadrants of those resulting angles (I assume the front is 90º wide).

3) If B is on one of those quadrants and its looking angle is in the interval defined in the former step, then A is on B's back.

But I am wondering if there is a better approach?

Using the dot product between the two front vectors (FrontA and FrontB) you are able to know if they are looking in the same direction, and it's quite fast

http://en.wikipedia.org/wiki/Dot_product

if dot(FrontA,FrontB) > 0 then the angle is between PI/2 and -PI/2 (A is looking in the same direction than B)

else if (dot(FrontA,FrontB) < 0) they are looking in the opposite direction

After that you should check the vector distance between B and A to know if A is behind B

dot( Bpos-Apos, FrontA) > 0 then A is behind B

If the signs are ok it should work...

### #5019035Fast sin and cos functions

Posted by on 08 January 2013 - 08:01 AM

I was looking around for fast sin and cos functions, especially for calculating the two together using sse.

I found an old post on devmaster.net describing a fast approximation for sin, but the code was incomplete. So I took that and adapted it for sse intrinsics, adding a SinCos function so I could get the second one for free.

The code is here:

http://dtosoftware.wordpress.com/2013/01/07/fast-sin-and-cos-functions/

Two points:

1. Feel free to use it, though don't bother unless you have a pressing performance reason; the standard sin and cos functions are actually pretty good.
2. Can you do better? Can a look up table beat this? Or can the code be optimised even more?

Maybe you could build a Set with the most used angles. If you need an angle and it isn't in the set then calculate it with that algorithm and store the angle ->result into the set.

But this could only improve your app if you only need few different results...

### #5015188Track Position in OpenGL ES

Posted by on 28 December 2012 - 03:41 PM

I have some models moving around a sphere using glRotate() and glTranslate() which all works how I want. Now I need to add collision detection. Each model has a bounding box and bounding sphere associated with it. How do I keep track of each models' position and apply that to the bounding box and bounding sphere so that I can test for collisions? I am using Java on Android, with the libGDX framework on OpenGL ES 1.1.

http://www.gamedev.net/topic/300428-sphere-box-collision/

I hope it's useful.

### #5013935I need Segfault Help

Posted by on 24 December 2012 - 08:13 AM

Alright guys,

I am soo close to getting done with the Tile Rendering portion of my game, but I have run into a problem that seems unsolvable. I am running this code:

```sf::View view = App->getView();

/* Culling code */
int startX = (view.getCenter().x - view.getSize().x)/TILE_WIDTH;
int endX = (view.getCenter().x + view.getSize().x)/TILE_WIDTH;
int startY = (view.getCenter().y - view.getSize().y)/TILE_HEIGHT;
int endY = (view.getCenter().y + view.getSize().y)/TILE_HEIGHT;

if(startX > MAP_WIDTH)
startX = MAP_WIDTH;
if(startX < 0)
startX = 0;

if(startY > MAP_HEIGHT)
startY = MAP_HEIGHT;
if(startY < 0)
startY = 0;

if(endY > MAP_HEIGHT)
endY = MAP_HEIGHT;
if(endY < 0)
endY = 0;

if(endX > MAP_WIDTH)
endX = MAP_WIDTH;
if(endX < 0)
endX = 0;

for(int y = startY; y < endY; y++)
{
for(int x = startX; x < endX; x++)
{
m_Sprites[GetTile(x,y)].setPosition(x* TILE_WIDTH,y* TILE_HEIGHT);

App->draw(m_Sprites[GetTile(x,y)]);

}
}
```

I am getting a segfault when I try to draw the sprites. I also ran valgrind and found there was an invalid write of 4 bytes when I set the position of the sprite. I also found memory is leaking somewhere when I run it but I can't find where :/. I can post my whole .cpp file if need. Anyone have any ideas why I am getting a segfault in this portion of the program? If not, could any of you wonderful people please help me debug it?

Thankyou very much!!
-Brent

I don't want to be fussy but I always try to avoid posible nulls and call the same function with the same parameters twice, I think this code is much more debuggeable and clear

...

unsigned int uTile = GetTile(x,y);

if (!uTile)

continue; // or control error or whatever

Sprite *pSprite = m_Sprites[uTile];

if (!pSprite)

continue; // or control error or whatever

pSprite.setPosition(x* TILE_WIDTH,y* TILE_HEIGHT);

App->draw(pSprite);

### #5013804Extracting box Vector3 from LPD3DXMESH box

Posted by on 23 December 2012 - 06:48 PM

You forgot a *bdum tish* after the "bound to be the problem" gag ;)

XD

Sorry, I had forgotten completely how to say OBB in English, so I said non AABB

PARTNERS