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 → Much help needed old boys!
Much help needed old boys!
2007-05-30, 7:01 PM #1
i have an issue with x y and z dimensions of JK.

in a cog, the line VectorSet x,y,z refers to the GLOBAL co-ordinates :rant:

I need a line of code to find the x,y,z in relation to THE PLAYER.

ie, Y would be the direct distance away from the player, - and + X would be to its sides etc.

the reason i need this is due to JK clipping. I can create perfect translucent layering in smoke, but only if its timed perfectly, and placed perfectly. I need faster fading smoke templates to be created FURTHER away from the player, and slower fading smoke templates to be created closer. THere's about 4 different smoke fade speeds.*



heres the cog for creating smoke templates

# SMOKEGENERATOR.COG
# JKSG1 by Ruthven
# STAGE 3
# This cog is attached to a blank decor item. +createsmoke.
# It is created from one of the final staff exp
# smoke 3do anmation frames.
# This will create a few fading smoke 3do's.
# NOTE: We require special vector alterations to create perfect non clipping
# effects on the smoke 3do layers. GET HELP.
# There will be 4-5 different smoke templates, of varying fade speed.

symbols
message created

thing player
Flex maxdistance=6 local


thing dummy local

template smoke3dos=+testsmoke1 local
//template smoke3dos2
//int count=0 local

vector position local
vector rising local
vector spinning local

end


code
created:


##-------- INSERT SPECIAL CODE HERE-------##

// if the player is within a certain distance
If(Vectordist(Getthingpos(Getsenderref()), Getthingpos(Player)) < maxdistance){
position = VectorSet((Rand()-.5)*0.01, (Rand()-.5)*0.01, 0.0 + Rand()*0.005);
rising = VectorSet((0.25*(Rand()-0.5)), (0.25*(Rand()-0.5)), (0.15 + (Rand()/20)));
spinning = VectorSet(0.0, 0.0, (Rand()-.5)*400);


dummy = CreateThingAtPos(smoke3dos, GetThingSector(Getsenderref()), Vectoradd(Getthingpos(Getsenderref()), position), '0 0 0');



Setthinglook(dummy, Vectorsub(Getthingpos(dummy), Getthingpos(Player)));
SetThingVel(dummy, rising);
SetThingRotVel(dummy, spinning);
}
return;


end




any ideas?

* and for those wondering what the hell i'm on about, JK allows for non clipping of translucent layers if the one behind it was created or updated after the one in front. :)
Code:
if(getThingFlags(source) & 0x8){
  do her}
elseif(getThingFlags(source) & 0x4){
  do other babe}
else{
  do a dude}
2007-05-30, 9:42 PM #2
I'm not sure what you mean by this "ie, Y would be the direct distance away from the player, - and + X would be to its sides etc."
That implies that the Y is the distance from the player to the smoke while the x is the distance to the left/right of the player and z is... something.

But judging from the rest of your question, is this what you mean:
You want the x,y,z as if the player is at 0,0,0 and the y-axis is the direction the player is looking?
Sam: "Sir we can't call it 'The Enterprise'"
Jack: "Why not!"
2007-05-30, 10:30 PM #3
tldr

Originally posted by Ruthven:
I need a line of code to find the x,y,z in relation to THE PLAYER.
A vector is a direction. The vector you input is a direction relative to an arbitrary point which can be numerically represented as a position in space relative to the origin. The player's position is also, thus, a vector. The operation to convert the direction (the point in space relative to the origin) is a simple translation by the desired origin.

Add the vector to the player's position to find the final position relative to the player.


If you want to find the position in 3D space relative to the player taking player rotation into account, the operation is a little more complex.

If you only have to rotate in the XY plane you can do a simple trigonometric rotation (x' = xcosθ + ysinθ; y' = ycosθ - xsinθ; where θ is yaw). This would, however, require a JK cog patch that included trigonometric functions.

The other option would be to use VectorCross. Again, if you are only rotating in the XY plane, you can retrieve a vector for the direction right of the player by supplying VectorCross with the player's thinglook vector (not player look) and a vector pointing straight up (0/0/1). You can then multiply that vector by the distance from the player you want the object and then add it to the player's position to get the final coordinates of the thing.
2007-05-31, 10:34 AM #4
thats great, but i dont have a clue how to code ANY of that :(:psyduck:
Code:
if(getThingFlags(source) & 0x8){
  do her}
elseif(getThingFlags(source) & 0x4){
  do other babe}
else{
  do a dude}
2007-05-31, 10:42 AM #5
Can you be more specific about what you're trying to do and why you need a vector perpendicular to the orientation of the player? If you're simply doing a depth sort you will get exactly the same result whether you are rotating your vector first or not.
2007-05-31, 12:21 PM #6
its not just depth but i also need a - and + X vector from the player's orient.

basically i need a template to be created at a first, then b , then c , then d . The positions in relation to the player is vital!

heres a pic
Attachment: 16381/untitled.jpg (17,958 bytes)
Code:
if(getThingFlags(source) & 0x8){
  do her}
elseif(getThingFlags(source) & 0x4){
  do other babe}
else{
  do a dude}
2007-05-31, 12:36 PM #7
Okay, but why do you need to know the X coordinate?

Edit: Surely the player isn't always going to be looking straight at the smoke generator, right? The only thing I can think of is that you're trying to solve Z-fighting issues around the outer edges of the screen, but that's because of the way FOV perspective projection works and not because objects mysteriously get closer together as they move closer to the outer edges.

If I'm right, and that's your problem, you can fix it by having the smoke things' thinglook values set to the inverse of the player's thinglook value.

If I'm wrong, and you absolutely require this even though it makes no sense to me (:confused:), something like this should work

Code:
symbols:
vector vRelPosition local
vector vResult local
flex fXcomp local
flex fYcomp local

[...]

// Find the relative position of the smoke thing to the player thing
vRelPosition = VectorSub(SmokeSpritePosition, PlayerPosition);

// Get the relative X distance from the player (rotated in XY plane)
fXcomp = VectorDot(VectorCross(GetThingLook(player), VectorSet(0, 0, 1)), vRelPosition);

// Get the relative Y distance from the player (rotated in XY plane)
fYcomp = VectorDot(GetThingLook(player), vRelPosition);

// Get the result by multiplying a 2D unit vector by the X and Y scales
vResult = VectorSet(1 * fXcomp, 1 * fYcomp, 0);


of course, VectorDist(PlayerPosition, SmokeSpritePosition) and VectorLen(vResult) both return exactly the same number, so I'm still not sure what you're hoping to accomplish by this. :confused:
Please explain it to me as though JK were a terrible and incomprehensible engine because it is and I have no idea what you're trying to do that wouldn't be solved by a simple straight forward depth sort.
2007-05-31, 1:26 PM #8
the x dimension is required for a random vector placement. anywhere between 0.05 and 0.15 in the + or - [related to the centre of the template creator orient/position]

the y dimension is rather a depth thing. Doesnt matter where the player is looking. its more his position. explosio/template A must be created closest to the player.

if i used jk's normal X axis, it could mess up the depth values (cos in a certain direction, X could be on the same axis as the Y axis/depth line from the template creator to the player.)



so in conclusion.

the Y axis i want is the line connecting the template creator position to the player.

the X axis is perpendicular to taht.
Code:
if(getThingFlags(source) & 0x8){
  do her}
elseif(getThingFlags(source) & 0x4){
  do other babe}
else{
  do a dude}
2007-05-31, 2:00 PM #9
If I've understood you right, you'd like to have a relative coordinate system where the y axis connects the player and the template creator and the x axis runs perpendicularly to it. If so, the vector yAxis = VectorNorm(VectorSub(GetThingPos(player), GetThingPos(smokething))) can be used as y axis. You should set your smoke creator thing's look vector to point in the same direction with SetThingLook(smokething, yAxis), then use xAxis = GetThingRVec(smokething) to get the x axis.
Now, to create a thing 2m closer to the player and 3m left of the smokething, use FireProjectile with an offset of VectorAdd(GetThingPos(smokething), VectorAdd(VectorScale(yAxis, 0.2), VectorScale(xAxis, -0.3)));
Maybe you have to strip the yAxis of it's coordinates and reassemble it with a z-value of 0 BEFORE you use VectorNorm on it, in case you don't want to take the height difference between player and smoke thing into account.
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)

↑ Up to the top!