Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
haveblue
Aug 15, 2005



Toilet Rascal

Subotai posted:

Well I have a texture I am dynamically generating and putting text on it and then putting it on a billboard. The billboard size is defined in world space coordinates and I need it to match the texture size which is defined in pixels. If the sizes dont match the text looks stretched or squished.

Without knowing exactly what you intend to do with this texture, it sounds like it may be easier to change the projection/viewport so that world space is identical to screen space.

Adbot
ADBOT LOVES YOU

haveblue
Aug 15, 2005



Toilet Rascal
The main thing I found the Red Book good for is structuring how you get started exploring GL- first vertices, then transformations, then lighting and shading, and so on.

haveblue
Aug 15, 2005



Toilet Rascal

tyrelhill posted:

I'd have to disagree and say you should start way down at the bottom with simple stuff like Pong and Frogger before you go look at binary search trees and crap like that.

I think you missed the point a little. Sure, modding a game won't teach you OpenGL or how a BSP tree works, but it lets you skip directly to the entities and world state - *game* programming, as opposed to just graphics and simulation programming (not to mention input, sound, I/O, etc). The foundation is already there.

I agree that examining a complete cutting-edge engine is a very bad way to learn the basics of graphics programming, if that's your objective.

haveblue
Aug 15, 2005



Toilet Rascal

Nyvinyd posted:

That's cool, I don't actually know what XNA is.

Ok so the basic idea I'm getting here is that before I learn graphics, I should learn text, and that a good book on C++ in general, along with the compiler, should get me there. I will do this. Thanks for the advice.

Graphics is an application (in the original sense, not the computer sense); first you have to learn C++ itself. That learning process will likely not involve graphics, but at the end of it you'll be able to move on to that.

It's like how you have to learn Greek if you want to study classical philosophy.

haveblue
Aug 15, 2005



Toilet Rascal

Twiggy794 posted:

Then what would you describe it as? A 3D engine?

It's a system architecture focused on game development. It's more comparable to something like SDL rather than a game engine.

haveblue
Aug 15, 2005



Toilet Rascal

samiamwork posted:

drat. I was afraid of that. I was really hoping to avoid using FBOs, but if that's what I have to use, that's what I'll used.

Thanks guys.

Sorry, that's the only way to do it at all. No current 3D API allows reading directly from the render target.

quote:

Someone else just suggested to me that if I have a vector for the direction I want to move in before the rotation (say (0,1,0)) and I rotate this with the verticies, I could just add this vector * the amount I want to move to the vertcies and it should move them in the direction I want after the rotation. I wont be able to try this for a while, does this sound like it would work though?

Yes, but you'll want to periodically regenerate the direction vector from scratch to avoid error accumulation. In general, you don't want to perform endless stacking transformations on the same data when using floats- it's better to have an unchanging base value which is transformed into a current value each frame it is needed.

haveblue fucked around with this message at 17:25 on Dec 7, 2007

haveblue
Aug 15, 2005



Toilet Rascal
Well, the first thing I notice is that your degree/radian conversion is wrong- all those 360s should be 180.

haveblue fucked around with this message at 23:04 on Dec 10, 2007

haveblue
Aug 15, 2005



Toilet Rascal

Barrackas posted:

I can't remember where I picked this up, but it's in the back of my head somewhere that older cards that don't support with NPOT textures will actually deal with them by breaking the NPOT texture down into the a series of POT textures.

So, for example, 100x100 texture gets broken into 9 POT textures, as follows;

64x64
64x32
64x4
32x64
32x32
32x4
4x64
4x32
4x4

Hence the performance hit related to NPOT texture use. This may just have been something that Java3D did (that was the platform I developed on), before sending textures to the GPU, but it's been over a year since I looked at this so I can't really remember.

I think it's something Java3D did. If a graphics card doesn't support rectangular textures then they can't be used in OpenGL, it's an optional extension (at least, it used to be, and rectangular texture support has been present in all 3D cards for the past several generations).

haveblue
Aug 15, 2005



Toilet Rascal
Even better, you write the loading (and storing) code for the editor and then add those files to the game engine project.

haveblue
Aug 15, 2005



Toilet Rascal

FlyingDodo posted:

I've just finished writing Vector,Quaternion and Matrix classes (c++). I understand vectors and matrices (well I hope I understand enough). I want to make a class which can be used to rotate things through 6dof. I can use the quaternions to make a basic fps camera which works fine but I have no idea how I am supposed to make a 6dof camera.

By "basic fps camera" do you mean a camera that uses Euler angles? If you can convert the angle and axis from a quaternion to an orientation matrix, you can use it to transform the camera just like any other object.

Then, to spin the camera around a relative axis like in Descent, you transform the target axis with the camera quaternion, convert the result and the magnitude to a quaternion, and multiply it back into the camera orientation.

If that didn't make any sense, I can try to find the book I got this from in the first place. It's been a really long time since I had to work with quaternions.

haveblue
Aug 15, 2005



Toilet Rascal

FlyingDodo posted:

No didn't make any sense :(. I'm not very good at maths. All I want is to be able to do is rotate things around for a space game. Like rotating spaceships around all possible orientations, based on pitch/roll/yaw.

And yet, you have a quaternion class :)

There are 2 things you need to be able to do to implement Descent-style movement- change the value of a quat by combining it with another quat, and generating a rotation matrix equivalent to a given quat. These are probably already methods of your class, but if they're not:

The first one is accomplished by multiplying the two quats together. If c is the cosine of the angle in the quat and v is the axis around which it is rotated:

code:
void MultiplyQuats(Quaternion *op1,Quaternion *op2,Quaternion *result)
{
    result->c = op1->c*op2->c - (op1->v.x*op2->v.x + op1->v.y*op2->v.y + op1->v.z*op2->v.z);
    result->v.x = op1->c*op2->v.x + op1->v.x*op2->c + (op1->v.y*op2->v.z - op2->v.y*op1->v.z);
    result->v.y = op1->c*op2->v.y + op1->v.y*op2->c + (op2->v.x*op1->v.z - op1->v.x*op2->v.z);
    result->v.z = op1->c*op2->v.z + op1->v.z*op2->c + (op1->v.x*op2->v.y - op2->v.x*op1->v.y);
}
The result of this operation is a quat containing the orientation you'd get by rotating through op1 and then through op2, just like concatenating matrix transformations.

The next thing you want to be able to do is generate the rotation matrix. I'm guessing you can already do this because you say you can use the quats for a basic camera, but still:
code:
void RotationMatrixFromQuat(Quaternion *src, float result[4][4])
{

    result[0][0] = 1.0 - 2.0*(src->v.y*src->v.y+src->v.z*src->v.z);
    result[0][1] = 2.0*src->v.x*src->v.y-2.0*src->c*src->v.z;
    result[0][2] = 2.0*src->c*src->v.y+2.0*src->v.x*src->v.z;
    result[0][3] = 0.0;
    
    result[1][0] = 2.0*src->v.x*src->v.y + 2.0*src->c*src->v.z;
    result[1][1] = 1.0 - 2.0*(src->v.x*src->v.x+src->v.z*src->v.z);
    result[1][2] = -2.0*src->c*src->v.x + 2.0*src->v.y*src->v.z;
    result[1][3] = 0;

    result[2][0] = -2.0*src->c*src->v.y + 2.0*src->v.x*src->v.z;
    result[2][1] = 2.0*src->c*src->v.x + 2.0*src->v.y*src->v.z;
    result[2][2] = 1.0 - 2.0*(src->v.x*src->v.x + src->v.y*src->v.y);
    result[2][3] = 0;

    result[3][0] = 0;
    result[3][1] = 0;
    result[3][2] = 0;
    result[3][3] = 1;
}
This will transform a vector around the origin by the angle and around the axis that were in the quat.

Now, to let the ship move along a camera-relative axis, you take the axis you want to move along (say, forward, which is probably along the positive Z axis), transform it by the quaternion, and then add the resulting vector to the ship's position.

code:
void Ship::TranslateAlongRelativeVector(double vector[3])
{
     //member: Quaternion q;
     //member: float position[3];
     float tempMatrix[4][4];
     float absoluteDirection[4];
     RotationMatrixFromQuat(q, tempMatrix);
     MultiplyMatrixAndVector(tempMatrix, vector, absoluteDirection);
     position[0] += absoluteDirection[0];
     position[1] += absoluteDirection[1];
     position[2] += absoluteDirection[2];
}
And there you have it- {0,0,1} becomes whatever that is to make it point directly into the screen in the camera's current orientation, and then the ship is moved in that direction.

Rotation is a bit trickier, because after performing the same initial steps you have to modify the quaternion with the result:

code:
void Ship::RotateAroundRelativeVector(double axis[3], float magnitude)
{
     //member: Quaternion q;
     //member: float position[3];
     float tempMatrix[4][4];
     float absoluteDirection[4];
     Quaternion delta;
     RotationMatrixFromQuat(q, tempMatrix);
     MultiplyMatrixAndVector(tempMatrix, axis, absoluteDirection);
     delta = QuaternionFromAxisAndAngle(absoluteDirection, magnitude);
     q = MultiplyQuats(q, delta);
}
That should give you a Descent spaceship with the right arguments (which depend on the rest orientation of your camera).

I should probably admit that I couldn't actually find the book and that's all based on old code, but I remember that it used to work. Hope it helped!

haveblue fucked around with this message at 21:33 on Dec 30, 2007

haveblue
Aug 15, 2005



Toilet Rascal

FlyingDodo posted:

I'm a bit lost here. I'm assuming that MultiplyMatrixAndVector(tempMatrix, axis, absoluteDirection); multiplies axis by tempMatrix and stores the result in absoluteDirection. So why is delta made from axis and magnitude. Shouldn't it be absoluteDirection and magnitude?

Sorry, you're right. It should be absoluteDirection.

haveblue
Aug 15, 2005



Toilet Rascal

FlyingDodo posted:

I'm still having problems trying to make this all work. I made a class which is easy to use (well if it worked properly it would be). All you have to do is give it axis/angles and it gives back an opengl matrix. For some reason it only works for rotations around one axis at a time, otherwise it goes all weird. I hate to dump a wall of text but could you take a look at my code? There must be some mistake in it somewhere that I can't find.
http://rafb.net/p/jNVHEl32.html

Do you mean that if you use, say, <0,1,0> as the axis it works fine, but <0, .7071, .7071> generates garbage?

haveblue
Aug 15, 2005



Toilet Rascal

Nibelheim posted:

Things are much clearer now. Thanks.

This though, is regarding sprite vs sprite collision. Can the same theory be applied to the game's map? The level itself is not a sprite per se, but rather a.. well, map.

Sure. You can populate the tree with static entities representing level geometry, or some sort of reference to a subset of background tiles.

haveblue
Aug 15, 2005



Toilet Rascal

Murodese posted:

Similar to this, how do I go about 3d collision detection for non-regular objects? They won't be massively complex, but something like a bounding sphere or aabb won't be precise enough.

I had a look at http://www.gamasutra.com/features/20000203/lander_02.htm which was kinda helpful but fairly old, and the journal articles I want to read on the subject aren't available to me :( We're not allowed to use external libraries, it all has to be coded by us.

Obviously I can use the above stuff to cut down the possibilities, but what about lower-end methods?

Usually the easiest way to do this is to implement a set of primitives and then assign each of your colliding objects a number of these to form their shape.

I don't know how complex or precise your collisions have to be, but you can fill just about any model with spheres and cylinders and get it close enough for a 3D game.

haveblue
Aug 15, 2005



Toilet Rascal

Vinlaen posted:

It seems like no game engines include automatic network synchronization... :(

It's very difficult to implement this in a completely general-purpose "free" manner. Too much of it is tied to the expected behavior of the value you're trying to replicate, and there's no room to add metadata to the network traffic. Unreal can do it because they control the virtual machine your game logic runs upon, and because they've been working on it for over ten years.

haveblue
Aug 15, 2005



Toilet Rascal

eshock posted:

This seems like something you'd want to write a shader for.

Especially since indexed color is practically deprecated and probably won't work right on modern hardware.

haveblue
Aug 15, 2005



Toilet Rascal

Pfhreak posted:

Yeah. We're using a physics library, and all of the agents will be affected by it. We are defining the world using textured polygons of arbitrary size. Thus, the world isn't tiled. The agents have a bounding box that defines their collision size, and they currently move back and forth by sliding along the ground. (By altering their linear velocity.)

Does that help? I'm trying to think of a similar game. Abuse is pretty close. (Actually, they make their source available, maybe I'll check that out!)

Abuse uses tiles, but it'll probably still be useful.

haveblue
Aug 15, 2005



Toilet Rascal
You're not taking the camera's current orientation into account when rotating, so all rotations are being performed around the same 3 axes. You need to take the axis the key command is supposed to rotate around and rotate *that* to be relative to the camera before using it to change the camera itself.

I made a fairly long post about this a few pages back. You already have most of it down, so just look at the last two blocks.

haveblue fucked around with this message at 16:24 on Mar 20, 2008

haveblue
Aug 15, 2005



Toilet Rascal

Murodese posted:

So if I'm understanding right, to yaw I should be getting the "y" axis from the current rotation and multiplying the current rotation by the quat generated by (m_x, ("y")) instead, then doing the same for the other axes that need to be rotated that frame?

Pretty much. You already have the current camera orientation as a quat. You take the natural Y axis and rotate it with this quat, so that from the camera's perspective it's where the Y axis should be. Then you rotate the camera around this new axis by the amount the user inputted.

haveblue
Aug 15, 2005



Toilet Rascal

Girl With Huge Tits posted:

One of my problems is I can't find any examples of doing something like I want to do, so maybe you could answer this. If I wan't to have normal mapping and toon shading in one shader, should they be different passes in the same technique, or different techniques?

You should be able to write a shader that does both. One technique involves calculating the fragment color based on the normal, the other is calculating the normal by a transformation of a texture sample. If you can find examples of both it should be relatively simple to create a shader that does one and feeds the result into the second.

haveblue
Aug 15, 2005



Toilet Rascal
totalSeconds is not the time of that frame, it's the total time elapsed since your game was launched. You have to calculate the frame time by storing the elapsed time from the last frame and finding the difference.

haveblue
Aug 15, 2005



Toilet Rascal

ultra-inquisitor posted:

So the shader knows which polygon is selected, but how do I get this information back to the actual program?

Try using GL's selection mode instead of a shader; it's made for that sort of thing.

If you can't do that, you'll have to copy the framebuffer back to main memory with glReadPixels to inspect it.

haveblue
Aug 15, 2005



Toilet Rascal
I'm not really familiar with GLSL, but I have a hunch it's reacting badly to in-place editing of inputs. What happens if you copy gl_Position to a temp before messing with it?

haveblue
Aug 15, 2005



Toilet Rascal
The Torque engine from GarageGames would do that. Or Unity.

haveblue
Aug 15, 2005



Toilet Rascal
e: double post

haveblue
Aug 15, 2005



Toilet Rascal
If you don't intend to sell your game, you could make it a total conversion for an Unreal or Source title.

And I didn't realize Unity didn't have a Windows editor.

haveblue
Aug 15, 2005



Toilet Rascal

fret logic posted:

Anyone here well versed with GLUT? If so how did you get learned in it? I'm not trying to really make anything serious, just kind of getting my feet wet with graphics programming, and I'm not sure if I should be reading up on GLUT specifically or general OpenGL programming. I'm using C by the way.

GLUT shouldn't take more than a few hours to learn; it's a very simple API that's just designed to get an OpenGL context and some basic input handling up and running in as little time and code as possible. You still use "general OpenGL programming" for drawing.

haveblue
Aug 15, 2005



Toilet Rascal

heeen posted:

I'm trying to use glClipPlane here, but no matter what values I send, it doesn't clip anything. If I try a positive and a negative halfspace surely some clipping should be noticable?

glEnable(GL_CLIP_PLANE0);

Also remember that clip planes use eye coordinates.

haveblue
Aug 15, 2005



Toilet Rascal

heeen posted:

I have it enabled alright, to no effect. If I try 0,0,1,0 and 0,0,-1,0 or 0,1,0,0 and 0,-1,0,0 as parameters at least one of them should clip something, right?

If you set <1,0,0,0> (or <-1,0,0,0>) you should see exactly half of your scene.

Are you doing anything weird with your projection matrix?

haveblue fucked around with this message at 00:31 on May 15, 2008

haveblue
Aug 15, 2005



Toilet Rascal

Jo posted:

As an extension of my original question: What blending mode performs a multiply?

e: I wasn't thinking. Setting the texture mode to modulate will cause the texel color to be multiplied into the fragment color.

If you want the destination to be assigned the product of the results of 2 texture units, you need to use the texture combiner extension.

haveblue fucked around with this message at 18:27 on May 15, 2008

haveblue
Aug 15, 2005



Toilet Rascal

UberJumper posted:

How can i have a day night cycle with a variable speed? =(

All i really want to do right now is control the ambience, lighting setting.

ambientLightIntensity = sin(currentMilliseconds/millisecondsPerDay*pi*2)?

As for the actual ambient light, that depends on your graphics system, but in general you'd want to set up a directional light and rotate it around an axis in the ground plane based on that formula.

haveblue
Aug 15, 2005



Toilet Rascal

Kennedy posted:

EDIT: Bahah, as always, hits me in the face as soon as I post :unsmith:
code:
 Vector3 camLookForward = new Vector3(0f, 0f, -0.5f);
            camLookForward = Vector3.Transform(camLookForward, Matrix.CreateFromQuaternion(playerRotation));
            camLookForward += playerPosition;
Here's a pretty sill Vector math question:

I'm programming a camera for my XNA game. At the moment, it's a 3rd person view of the player's vehicle, pointed at the model's center.

However, I'd like it to look along the forward vector of the player, so more of the screen is visible. What's the math I need so that the camera is always looking at a point 2f along the player's forward vector?



And here's my current code:
code:
            // slerps the camera to follow just behind the player
            cameraRotation = Quaternion.Lerp(cameraRotation, playerRotation, 0.1f);

            // moves the camera in relation to the player position
            Vector3 campos = new Vector3(0.0f, 0.15f, 0.5f);
            campos = Vector3.Transform(campos, Matrix.CreateFromQuaternion(cameraRotation));
            campos += playerPosition;
            
            // make the camera look ahead of the player
            // code goes here
   

            // positions the camera's up vector
            Vector3 camup = new Vector3(0, 1, 0);
            camup = Vector3.Transform(camup, Matrix.CreateFromQuaternion(cameraRotation));

            // creates the view matrix from the player's position for the camera, and the projection matrix for the camera
            viewMatrix = Matrix.CreateLookAt(campos, playerPosition, camup);
            projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 0.2f, 500.0f);
And how it looks currently (please ignore the Ferrari in Tron):


Well, you're using a lookat call, so you have all the info you need right here. Just drop campos to the ground, find the vector extending from it to playerPosition, scale that vector up by however much, and use its new endpoint instead of playerPosition.

haveblue
Aug 15, 2005



Toilet Rascal

timecircuits posted:

I'm not using a library for concurrency because I don't really feel that I learn anything by using Boost and calling it a day. Seeing as how the rest of my programming career is probably going to be writing multithreading-aware code, I should get on this ahead of time.

Does anybody have a better answer?

The rest of your concurrency programming career is not going to be done with raw pthread calls or atomic intrinsics. You use those to learn the fundamentals and then move on to something more streamlined and practical, which may as well be Boost.

haveblue
Aug 15, 2005



Toilet Rascal

GuyGizmo posted:

Quick question: What's the programming language and libraries used for non-XNA Xbox 360 development? In particular, the SDK for Xbox Live Arcade? I assume the Xbox 360 SDK uses some kind of variant of DirectX, and I think you can program with it in both C# and C++, but I'm not sure.




(edit: clarity)

This is essentially correct. The 360 C++ API is a variant of Win32 and the graphics system is a variant of DirectX 9 with some 10 stuff thrown in like geometry shaders.

haveblue fucked around with this message at 14:57 on Oct 27, 2009

haveblue
Aug 15, 2005



Toilet Rascal

Stanlo posted:

It doubled the latency or something?

That would be a 50% decrease. A 200% decrease would be performance so bad that the router poo poo itself and dropped traffic for every computer in the room.

haveblue
Aug 15, 2005



Toilet Rascal
I suggest Prolog

haveblue
Aug 15, 2005



Toilet Rascal
As long as it's not a ponderous flash gallery or some hideous neon-orange-on-black geocities abortion it should be fine. Clean up any obvious design or HTML errors and make sure it can be navigated quickly.

haveblue
Aug 15, 2005



Toilet Rascal

guenter posted:

Around this time I gave up and started looking at heuristics and stuff =/

What we're doing to pretty good effect to solve the orbiting problem:

-Calculate the turning radius of the ship at the current speed
-Multiply this distance by the sine of the relative angle of the target (this approximates the length of the chord from the ship's initial position to where it would be in its trajectory if it underwent a turn to the target heading)
-If the distance to the target is smaller than this value, the ship is going to overshoot despite turning so reduce speed.

This makes the ship spiral in on the target; its final orientation can be anything but it usually stops on a dime where directed. I'd need to draw a diagram to properly justify this but it seems to work well enough.

haveblue fucked around with this message at 23:33 on Dec 21, 2009

Adbot
ADBOT LOVES YOU

haveblue
Aug 15, 2005



Toilet Rascal
What you're seeing is normal behavior. Each time you change the camera orientation, you're also changing the axes around which future orientation changes will be made. The effect adds up so that when you make that input you don't end up exactly back where you started.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply