Well now you can. Presenting the code that will allow a cogger the ability to find if a thing is on a surface.
Please credit me if you use this.
The operation principle is as follows:
I know that that is somewhat long winded and I probably confused people more with it, but its not something easy to explain. This is untested, but logistically it works.
Also, you can use my sector of posistion to find that sector, uses roughly the same priciple.
------------------
Major projects working on:
SATNRT
JK Pistol Mod
Aliens TC
edit - updated code for attached_surface.cog
[This message has been edited by Descent_pilot (edited August 09, 2004).]
Please credit me if you use this.
Code:
# Jedi Knight Cog Script # # ATTACHED_SURFACE.COG # # Gets the surface that a thing is on # # [DP] # pos = GetThingPos(GetParam(0)); thingsec = GetThingSector(GetParam(0)); onsurface = 0; For(i=0; !onsurface; i=i+1) { onsurface = GetSectorSurfaceRef(thingsec, i); For(j=0; j<GetNumSurfaceVertices(GetSectorSurfaceRef(thingsec, i)); j=j+1) { dot = VectorDot(GetSurfaceNormal(i), VectorNorm(VectorSub(GetSurfaceVertexPos(i, j), pos))); If(dot >= .05 || dot <= -.05) onsurface = 0; } If(i > GetNumSectorSurfaces(thingsec)) onsurface = -1; } Return; end
The operation principle is as follows:
- Facts relvent
- All surfaces in a level must be planear
- planear means the vertices lie in one 2d field
- Cosine can be used to find the degrees of an angle between 0-180º
- A surfaces normal is the direction which it is looking so it is perpendicular to the plane of the surface facing the rendering direction. (ie the lookvector facing inside the sector).
Operation - This cog goes through each surface inside a sector
- It finds teh dot product (cosine) of the surface normal and each of the surfaces vertices
- If any of the cosines are not close to 0 (90º) then it is not on that surface
Reason why it works - For a posistion to exist on a surface, it must be planear to the surface as well, to check this, you use the normal of the surface (which is perpendicular to the plane) and since were dealing with looking vectors, the origin of the angle is irrelevnt, and if the normal is also perpendicular to the look vector of the posision to all the vertices, then it must lie in the surface (and inside the verticies for that matter).
I know that that is somewhat long winded and I probably confused people more with it, but its not something easy to explain. This is untested, but logistically it works.
Also, you can use my sector of posistion to find that sector, uses roughly the same priciple.
Code:
# Jedi Knight Cog Script # # SECTOR_OF_POSISTION.COG # # Gets the sector of a posistion # # [DP] # insector = 0; pos = GetThingPos(GetParam(0)); For(i=0; !insector; i=i+1) { insector = i; For(j=0; j<GetNumSectorVertices(i); j=j+1) { dot = VectorDot(VectorNorm(VectorSub(GetSectorCenter(i), pos)), VectorNorm(VectorSub(GetSectorVertexPos(i, j), pos))); If(dot >= 0) insector = 0; } If(i > GetSectorCount()) insector = -1; } Return;
------------------
Major projects working on:
SATNRT
JK Pistol Mod
Aliens TC
edit - updated code for attached_surface.cog
[This message has been edited by Descent_pilot (edited August 09, 2004).]
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms
Completed
Judgement Day (HLP), My level pack
SATNRT, JK Pistol Mod, Aliens TC, Firearms
Completed
Judgement Day (HLP), My level pack