News:

One Minute Game Review by The Happy Friar: https://ugetube.com/@OneMinteGameReviews
Also on Rumble: https://rumble.com/c/c-1115371

idTech 4 (aka Doom 3 tech) Discord Server! https://discord.gg/9wtCGHa

Main Menu

idtech 4 Vectors?

Started by argoon, November 16, 2016, 12:51:54 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

argoon

Cheers people can anyone explain how to use vectors on idtech 4? As always before asking i tried doing it my self and even reading other people code to learn but i'm just not getting anywhere, math was never my strong point,  i'm trying to make a grass system (using script not c++ code) where every grass model shoots a trace downwards and detects the surface below at init() so it gets on the ground and follows the terrain bumps, without the need for me to manually do that, problem i'm totally failing, because i can't seam to shoot a trace straight down for all models using only code, i tried to learn vector math, it seams easy but when i try to implement it in code i fail, all models just shoot the trace in random directions, can anyone with sufficient knowledge about idtech 4 vectors give me some hints?

here is the code that i have for that, is ugly and just me messing around trying everything so have petty.


void grass_sys::alignToFloor(){
vector traceStart;
vector tracEnd;
vector  downVec;
vector  normVec;
vector  traceNormal;
vector traceStartAng;

traceStart = self.getWorldOrigin();

//traceStart = traceStart - getWorldOrigin();

sys.println("tracStart is: " + traceStart);

/*
traceStartAng = sys.VecToAngles(traceStart);
sys.println("tracStartAng is: " + traceStartAng);

normVec = sys.vecNormalize(traceStart);
sys.println("normVec is: " + normVec);
*/

downVec = sys.angToForward(traceStart);
sys.println("downVec is: " + downVec);

tracEnd = traceStart + downVec * 50;
sys.println("tracEnd is: " + tracEnd);

sys.debugArrow('0 1 0', traceStart, tracEnd, 4, 100 );


Also vectors from where i read http://www.wildbunny.co.uk/blog/vector-maths-a-primer-for-games-programmers/vector/ seam to be
QuoteA Vector is a quantity which has both magnitude (size) and direction, but no position
so how does in idtech 4 they do seam to have a position in space? By using getWorldOrigin() or getOrigin() i get a position this tell me they are points in space but that quote implies otherwise, I'm just not comprehending this well or they are different vectors?

How can you visualize a single vector in idtech 4 script? By using debugLine or debugArrow you need two vectors, a start and a end vector, but isn't a single vector already a "arrow"?

Sorry if this are really dumb questions but i'm just ignorant on this stuff and i'm stuck and would like to learn this. 

Thanks.

caedes

"A Vector is a quantity which has both magnitude (size) and direction, but no position"

Some engines/people differentiate between vectors and points - both usually have 3 components (.x, .y, .z), but a point describes  a position, while a vector a direction/magnitude.
So if you had a Point p1 = (1, 1, 1) and another p2 = (2, 3, 4) you could do p2 - p1 = (1, 2, 3) - and (1, 2, 3) is a Vector which describes "how to get from p1 to p2", so it has a direction and a size (its length/size/magnitude - calculated as sqrt(x*x+y*y+z*z) - is the distance between p1 and p2, in this case sqrt(1+4+9) = sqrt(14) = 3.7417).

idtech4 just uses the vector type for both points and vectors

argoon

#2
Thanks caedes that helps indeed, i also found a tutorial about vectors for UE4 and was happy to see i can do almost all with idtech 4 code instead, one thing in the UE4 tut below that i still have to find a similar function in idtech 4 script is the "rotate vector" function, that takes two vectors/points and rotate them (if i understood the guy well, English is not my language) any hint would be appreciated.

Here is the UE4 tut:



:)


p.s - Can anyone explain how to use the anglemode180 and anglemod360 doom utilities it seams they are used to rotate angles but i'm not getting the desired effect. 

argoon

d3xp has a rotateVector(vector vec, vector ang)!!! custom function    :) was able to enable it in my fhdoom engine based mod, is still not working exactly like the UE4 tut (it inverted the player view up and down movement?!) but at lest is working better then before, walking the path there.