Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Need some vector help
Need some vector help
2004-11-13, 3:52 PM #1
Ok I need to make a 3d sprite type deal. The thing is, I need it to rotate toward the player along its x and y axis, but remain fixed to its z axis, kind of like the "3d" sprites in duke nukem. I just need the math ;)

[Oh yeah, this is with a 3do, not an actual sprite obviously]
Jedi Knight Enhanced
Freelance Illustrator
2004-11-13, 4:20 PM #2
The closest thing I could think of was to get the SpriteThing UVec and SetThingRotVel(0, 0, +/-Speed) based on a position/vector to check against, but finding that Pos/Vec is where I'm comming into coders block.

[This isn't a reply as a solution, it's a reply for help! :o ]
-Hell Raiser
2004-11-13, 6:37 PM #3
I was just uhh.. messing around, and well, I figured it out :eek:

Code:
flags=0x240

symbols
thing		pipe
thing		player	local
vector	playerpos	local
vector	pipepos		local
flex	xflex		local
flex	yflex		local
vector	spritelook	local
message		startup
message		pulse

end

code

startup:

player = GetLocalPlayerThing();
   SetPulse(0.1);
   return;

pulse:
playerpos = GetThingPos(player);
pipepos = GetThingPos(pipe);
cross = VectorCross(playerpos,pipepos);
Zflex = VectorZ(pipepos);
Xflex = VectorX(cross);
yflex = Vectory(cross);
spritelook = VectorSet(xflex,yflex,zflex);
SetThingLook(pipe,spritelook);
   return;

end


Theres my test cog. it follows the player around the correct axis' only.

[nevermind, fixed my spelling errors and it works, yay!]
Jedi Knight Enhanced
Freelance Illustrator
2004-11-14, 2:37 PM #4
Ahh.. well I tried it with a custom 3do that is a flat plane, and the results weren't good. This way it only uses the world z axis i guess. We need it to rotate around its own axis.
Jedi Knight Enhanced
Freelance Illustrator
2004-11-14, 7:40 PM #5
Doesn't SetThingLook do what you want, i.e. rotate the thing along the thing's uvec (its "z-axis") while looking at the player?

You should be able to do this:
Code:
pulse:
  playerpos = GetThingPos(player);
  pipepos = GetThingPos(pipe);
  SetThingLook(pipe, VectorSub(playerpos, pipepos));
return;
:)

[Edit: Swapped the VectorSub arguments.]
2004-11-15, 12:10 AM #6
Thats not quite what we're looking for...

What we need is for the thing to roll towards the camera/player, but what I'm having a hard time figuring out, is how to check and see which way the 3do should rotate, based off of where it's UVec is looking in relation to a mystery point based off the camera/player position.
-Hell Raiser
2004-11-15, 3:59 AM #7
Following pseudo-code might help:
Code:
a = GetThingPos(player);
b = GetThingPos(object);
c = VectorSub(b, a);
c = VectorSet(VectorX(c), VectorY(c), 0);
SetThingLook(object, VectorNorm(c));

[http://www.rockundpop.ch/vectorscheme.gif]

[edit]
I just noticed that Zeq already posted the solution. He got the VectorSub params in the wrong order, though. His solution should always look away from the player. And he forgot to insert a 0 for the z axis.
[/edit]
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2004-11-15, 1:05 PM #8
Heh, if I am wrong about the arguments, then the DataMaster is wrong:
"Vector1 is the destination for the subvec and vector2 is the source." (Which means the vector points in the direction of the first argument.)

I did not insert 0 for the z-axis because I imagine the camera could face all directions (like up), so the z-coordinate will not always be zero.

:)
2004-11-15, 1:06 PM #9
*sigh* I really tried with your code Zagibu, but SetThingLook() refuses to set the roll of the Thing like I want it to. You can move the pitch and yaw with SetThingLook by modifying the Z and X values respectively, but I need to modify the roll. :(
-Hell Raiser
2004-11-16, 2:13 AM #10
Oh, now I understand the problem. Well, you might be able to do something like this, or wait until I have more than 5 minutes to really come up with a useful solution :):

Code:
//my code from above, without the SetThingLook line
FireProjectile(object, obj_tpl, -1, -1, c, '0 0 0', 0, 0, 0, 0);
DestroyThing(object);


I hope you get the idea...
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2004-11-16, 6:07 AM #11
Heh. I think if Shred18 and Hell Raiser want real help with the "rolling" problem, they will need to post some pics.

I have chatted with HR about the "rolling" problem, and it wasn't until I saw a couple of pics that I finally realized what the situation was. And no, I am not going to attempt to explain it in words. :p

(They might have already solved the problem, I'm not sure.)

:)
2004-11-16, 11:41 PM #12
[http://www.hellraiser64.com/Pics/JSHOT007.jpg]

That "beam" is made up of 6 or 7 segments of 3dos that only have one face. I need the pieces to roll towards the camera so they don't appear flat, yet keep their look vector. (Note that the ends will be "capped")

I don't want them to move anywhere except for rolling along their Y-Axis.
-Hell Raiser
2004-11-17, 6:24 AM #13
Ok. maybe include the screenshot right from the start next time, cause I thought you'd want to create a billboard kind of thing...
I still don't see what your trying to do.
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2004-11-17, 2:57 PM #14
[http://www.hellraiser64.com/tdir/screenshots/Other/help.jpg]
Jedi Knight Enhanced
Freelance Illustrator
2004-11-17, 8:24 PM #15
*Fanfare*

No out of the way vector math!

No things created!

So smack yourselves in the head and say "Doh!"

Here it is!

Code:
V1=GetThingRVec(BeamSprite);
V2=VectorNorm(VectorSub(CameraPos, SpritePos));
	
VDot=VectorDot(V1, V2);
	
SetThingRotVel(BeamSprite, VectorSet(0, 0, VDot*3600));


Put that puppy in a SetThingPulse(Thing, 0.01); and you've got yourself a sprite that can maintain it's look vector and still orientate towards the camera. Now if I only could have done this a few years ago

Haha, I rule and ya'll drool. :p :o [/poking fun]
-Hell Raiser
2004-11-17, 8:49 PM #16
And here is our desired effect:

[http://www.hellraiser64.com/Pics/JSHOT024.jpg]
-Hell Raiser
2004-11-17, 11:35 PM #17
Quote:
Originally posted by Shred18
Ok I need to make a 3d sprite type deal. The thing is, I need it to rotate toward the player along its x and y axis, but remain fixed to its z axis, kind of like the "3d" sprites in duke nukem. I just need the math ;)

[Oh yeah, this is with a 3do, not an actual sprite obviously]

Ok, I see now what you are doing. Unfortunately, it's quite the opposite of what Shred18 described above. But hey, it's solved, so YAY!
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2004-11-18, 6:57 PM #18
It took me a day to explain it just right to ZeqMacaw, lol. :o
-Hell Raiser

↑ Up to the top!