Game Development Community

GuiWayPointHud

by Chris "Dark" Evans · in Torque Game Engine · 03/08/2006 (6:40 am) · 15 replies

I know most people were sleeping when I posted this last night. Just to clarify, this hud works as is. If you have a player based FPS then this will work by just dropping it in and setting the variables. The arrow points wherever your target is set to.

I'm not a guy with ideas who only wants people to make things for me (unlike too many people here). I did the best I could with the math I knew and the docs on the net I could find. However, I couldn't find anything that takes the camera's roll into account, which is all I really need help with now.


I wrote that post fast last night so it came out kinda sloppy.


Thanks,
Dark

#1
03/08/2006 (7:14 am)
This is a neat resource, thanks Dark, mind if I roll it into the MMORPG Enhancement Kit? My beta testers are screaming for a waypoint system just like this!
#2
03/08/2006 (8:32 am)
Yeah, go for it. It's not really done yet. I want to add a few more things to it. I wanted to make it to give to the community.
#3
03/08/2006 (8:05 pm)
Where'd all the math wizzards go? lol. I thought people would jump all over this. I haven't seen a resource like this here yet. I'm planning on adding additional waypoints that only the client will see, and some other cool things, and it'll all be accessed through scripts. All the GUI objects I make I want to give out as resources. I just need help on this math...
#4
03/08/2006 (8:20 pm)
If this is what I think it is, I'm going to be ecstatic. :) I've been wanting to put in waypoint markers and directional locators for a while now.
#5
03/08/2006 (8:30 pm)
Yep, that's what this is. But I haven't put the waypoint markers in yet. It does have a directional arrow though. But right now it only works right for objects that don't roll. Flying vehicles will have to orient themselves somewhat horizontally or the arrow won't point in the right direction. That's the part I need fixed.
#6
03/09/2006 (2:18 am)
Perhaps instead of using guiobjectview, you can just attach an arrow to a node, and use the code from setaimobject. Or just have the arrow always positioned at x,y,z from the player/vehicle, that way it's physical position always matches but the arrow will always point where you want it to.

Just an idea, hope you know what I am talking about, I am not sure I can explain it any better :-p

- Anthony
#7
03/09/2006 (6:03 am)
..Ah I understand what this is. In that case, it's not what I meant. I meant having a 2D arrow that rotates around the edge of the screen pointing in the direction one must turn to get to a waypoint. Like in Halo, the triangle at the top of this image, rotates around the edge of the screen.
#8
03/09/2006 (6:30 am)
C2, Have you looked at the shapenamehud? I'd bet that it has practically all of the math that you would need to do that, besides the offscreen arrow.
#9
03/09/2006 (6:37 am)
This looks exactly what I'm searching for. I'll give it a try. Thanks!
#10
03/09/2006 (6:42 am)
This is great, I wonder if it can be modified to be similiar like the Freelancer one, I am thinking a Arrow that rotates around a circular nav compass, It color changes to indicate what you have targeted, Red hostile, Blue for Neutral, Green for Friendly and Yellow for Ally or Party member.

As far as the math, I know it possible to get directional information, because in MOM you have the tracking ability and MOM uses a Dog that rotates in his own view you follow to find your target. The better your tracking skill the more accurate you get in finding your target.

The distance to target is displayed in meters, But once the formula for determining distance is in place you can set this to be anything from miles or kilometers, to even lightyears heh. Going to download it and thanks this is a great resource.

EDIT: Also I have to dig, but I did find a site that explain about the 360 degree radar that elite uses, it mainly focused on the math behind it, and not necessary how it was implemented, but if I come across it I will post a link back here.

But I do know you need points of reference, to determine accurate locations, the ship or player you control would be a known point. Anyway I need this knowledge anyway for my own Sci-fi RPG.

EDIT: It wasn,t a site it was a thread from last year hopes this help you out :)

Radar
#11
03/09/2006 (7:26 am)
Damn this is extremly cool. I just put it in and it works. Exactly what I searched for. Very useful resource! Thanks again.
#12
03/09/2006 (8:09 am)
@Anthony
Do you mean attach a node to the player, or whatever object I'm controlling? That would work, but I don't want to have to edit all my models to include it. It might be possibly to attach it to the eye or cam node, then just offset it so it's in front of the player/vehicle. If I can't get this figured out I might try that, but I know putting it in a GUI will work.

@C2
I know now what you're talking about. Drew is right, shapename hud should have nearly everything you need. That's kind of what I'm talking about with the other waypoints I'm going to add. When the waypoint is in your FOV, it'll show like a sprite on the screen, or maybe even a 3D model. But when it's off the screen it'll have little arrows around the edges pointing toward it. The main locator arrow is meant to be set to one of those positions so if you have a bunch of waypoints you can focus on one at a time.

@Johnny
I'm not familiar with the freelancer compass. Is it like what Anthony said, but instead of the arrows rotating around the whole screen it's just around the compass? The arrows around the screen will be the ones that display distance, and so will the way points themselves. You'll have the distance to every waypoint at once. Right now it's using the client's controlled camera as point A and the target location as point B. That's the easy part. The hard part is using the camera's rotation to make the arrow on the GUI appear to be pointing where it should.

@Martin
Thanks :) It should be a lot better when it's finished though.
#13
03/09/2006 (8:14 am)
I can figure out the control camera's Y rot (or roll) and do the math to make the arrow rotate like it needs to. I guess the main problem I'm having right now is passing it to the camera matrix (for the gui). I'm so unfamiliar with torque's math functions. I know there are functions that probably calculate all this stuff for me, but I just don't know/understand them yet.

bool GuiWaypointHud::processCameraQuery( CameraQuery* query )
{
	// Make sure the orbit distance is within the acceptable range:

	if(mOrbitDist < mMinOrbitDist)
		mOrbitDist = mMinOrbitDist;
	else if(mOrbitDist > MaxOrbitDist)
		mOrbitDist = MaxOrbitDist;

	// Adjust the camera so that we are still facing the model:
	Point3F vec;
	MatrixF xRot, yRot, zRot;

	xRot.set( EulerF( mCameraRot.x, 0, 0 ) );
	yRot.set( EulerF( 0, mCameraRot.y, 0 ) ); // added this
	zRot.set( EulerF( 0, 0, mCameraRot.z ) );

	mCameraMatrix.mul(xRot, zRot);
	mCameraMatrix.getColumn( 1, &vec );
	vec *= mOrbitDist;
	mCameraPos = mOrbitPos - vec;

	query->nearPlane = 0.1;
	query->farPlane = 2100.0;
	query->fov = 3.1415 / 3.5;
	mCameraMatrix.setColumn( 3, mCameraPos );
	query->cameraMatrix = mCameraMatrix;
	return( true );
}

I don't know how to put yRot into mCameraMatrix and make it work. "mCameraMatrix.mul(xRot, zRot)" is how x and z get passed to it, but I'm not sure how to put y in the mix. Any ideas? After that I'm sure I can do everything else I need in renderWorld.
#14
03/09/2006 (7:48 pm)
This is turning out to be a pretty big learning experience for me. I've learned more about math in the last couple of days from reading things on the net and looking around in these forums than I ever did in school. I've begun to understand the vector manipulation better to clean up the code a little. I figured out how to pass the y vec to the camera matrix, that was the easy part.

here's the new processCameraQuery:

bool GuiWaypointHud::processCameraQuery( CameraQuery* query )
{
	// Make sure the orbit distance is within the acceptable range:

	if(mOrbitDist < mMinOrbitDist)
		mOrbitDist = mMinOrbitDist;
	else if(mOrbitDist > MaxOrbitDist)
		mOrbitDist = MaxOrbitDist;

	// Adjust the camera so that we are still facing the model:
	Point3F vec;

	mCameraMatrix = MatrixF(EulerF(mCameraRot.x, mCameraRot.y, mCameraRot.z));
	mCameraMatrix.getColumn( 1, &vec );
	vec *= mOrbitDist;
	mCameraPos = mOrbitPos - vec;

	query->nearPlane = 0.1;
	query->farPlane = 2100.0;
	query->fov = 3.1415 / 3.5;
	mCameraMatrix.setColumn( 3, mCameraPos );
	query->cameraMatrix = mCameraMatrix;
	return( true );
}

I also rewrote the math a little in renderWorld:
MatrixF matrix;
	Point3F camPos;
	VectorF camDir;

	conn->getControlCameraTransform(0,&matrix);
	matrix.getColumn(3, &camPos);
	matrix.getColumn(1, &camDir);

	F32 camDirX = camDir.x;
	F32 camDirY = camDir.y;
	F32 camDirZ = camDir.z;

	VectorF vec = camPos - mTargetPos;
	vec.normalize();
	vec.neg();

	mCameraRot.x = vec.z - camDir.z;
	mCameraRot.y = 0;
	mCameraRot.z = mAtan((vec.x * -1.0F), vec.y) - mAtan((camDir.x * -1.0F), camDir.y);

This is a LOT cleaner than it was before. But I'm sure there are better ways to do this, lol. Anyway, as you can see I haven't figured out how to calculate the Y rotation and get them all to work together. I know most games here keep their players and vehicles parallel to the ground. So there's not a lot of use to it unless you have a flying vehicle that can roll and maneuver in every axis. However it's perfect for space sims or a horizon indicator! Any pointers or ideas on how to do it?
#15
06/27/2006 (7:25 am)
Has somebody ported this over to TSE?