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 → A simple vector question.
A simple vector question.
2002-01-19, 6:57 AM #1
Is it possible to find the sector containing a given vector?

------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2002-01-19, 10:19 AM #2
I assume you mean a position in the engine's world, rather than a 'real' vector, as vector's have no position info at all, just a direction and length.

You can always cheat by creating a ghost object at that position, and then use GetThingSector(), and afterwards destroy the ghost.

Raynar


------------------
... the Jedi I admire the most, met up with Darth Maul, now he's toast ...
Rbots - a project to develop a working Bot for Jedi Knight... download the latest development version here
Pagewizard_YKS: "making your own lightsaber doesn't make you a nerd... "
Raynar - the man with a 10.75" ePenis
2002-01-19, 10:20 AM #3
You can retreive the sector directly in MotS with FindSectorAtPos().

But I don't know of any good way to do it in JK.

[edit]

You sure about that, Raynar? If you used CreateThingAtPos(), you'd have to give the sector as a param.

[This message has been edited by SaberMaster (edited January 19, 2002).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-01-19, 12:18 PM #4
You could do something very similar to Raynar's suggestion.

1) Create THING
2) SetThingPos(THING, COORDINATES);
3) GetThingSector(THING);
4) DestroyThing(THING);
- Wisdom is 99% experience, 1% knowledge. -
2002-01-19, 1:20 PM #5
Yes, I do mean a vector position, or 'world coordinate'. Its too bad I dont have MOTS...


You cannot create an object from a ghost position without specifing a sector.


Using 'Setthingpos()' on an object doesnt reset the current sector. It still claims to be in it's previous sector.


I even tried firing a ghost toward the position. But, once it exits the world, it doesnt update it's current sector... It is stuck with the sector number of the one it was in when it left.

------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2002-01-19, 1:28 PM #6
aStuff = CreateThing(ghost, player);
SetThingPos(aStuff, thePos);
bStuff = CreateThing(ghost, player);
TeleportThing(bStuff, aStuff);

How about this? [http://forums.massassi.net/html/smile.gif]

------------------
http://millennium.massassi.net/ - Millennium

[This message has been edited by Hideki (edited January 19, 2002).]
2002-01-19, 1:40 PM #7
That doesnt work either. The problem is simple:


When creating an object, the child assumes various aspects of the parent. Frames, a few flags, and it's sector number. Especially the sector number. (That really stinks, doesnt it?)


When teleporting an object, the teleportee doesnt assume as much, but it does take on the current sector. Now, the problem is, even if the target ghost has an incorrect sector number, it will still be passed on to the teleportee.

In other words, no matter how many times you create/destroy, teleport/setpos, it will never reset it's current sector.


SO[/i], I need to find a way to do this that doesnt involve objects...

------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2002-01-19, 2:01 PM #8
I think this will work, I have not tested it yet... I hope it will not jolt older computers.

Code:
for(i=0; i<GetSectorCount(); i=i+1)
{
 for(e=0; e<GetNumSectorVertices(i)-1; e=e+1)
 {
  vexpos=GetSectorVertexPos(i, e);
  dist=VectorDist(GetSectorCenter(i), vexpos);
  close=VectorDist(GetSectorCenter(i), yourvector);
  if(close < dist)
  {
  vectorsector=i;
  }
 }
}
2002-01-19, 2:04 PM #9
I was trying to rig up a system similar to that, I just couldnt figure out how to get the vecdist right. Ill try it.

------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2002-01-19, 3:04 PM #10
Nope. Doesnt work. [http://forums.massassi.net/html/frown.gif]

------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2002-01-19, 5:14 PM #11
Success !!! , this peice of code fully works.... I tested it.

Code:
distance=9999;
for(i=0; i<GetSectorCount(); i=i+1)
{
 for(e=0; e<GetNumSectorVertices(i)-1; e=e+1)
 {
  vexpos=GetSectorVertexPos(i, e);
  dist=VectorDist(GetSectorCenter(i), vexpos);
  close=VectorDist(GetSectorCenter(i), random);
  if(close < dist && close < distance)
  {
  distance=close;
  vectorsector=i;
  }
 }
}
2002-01-20, 10:34 PM #12
So ...... did it work ?
2002-01-21, 4:11 AM #13
No, it doesnt. The problem is, mesuring sector vertex positions doesnt work. If you have a long, narrow sector,


|^|
| |
| |*
| |
|_|


With the asterisk being the target vector, even though the sector's verticles are farther away than the postion, the position is outside that sector.


Hence, it doesnt work.

------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2002-01-21, 11:54 AM #14
I have a crazy suggestion, but like these others I dont think it will work. Even if it's a stupid suggestion it sure is fun thinking 'outside the box'. [http://forums.massassi.net/html/wink.gif]

1) Create a thing (START) at player pos, so you can return here later.

2) Set your position to 0, 0, 0.
SetThingPos(player, '0 0 0');

3) Fire a non-moving projectile with your custom vector in the fireoffset.

dummy = FireProjectile(player, projectile, -1, -1, YOUR_WORLD_POS, '0 0 0', 1.0, 0x20, autoAimFOV, autoAimFOV);

4) THESECTOR = GetThingSector(dummy);

5) Teleport(player, START);

- Wisdom is 99% experience, 1% knowledge. -
2002-01-21, 12:02 PM #15
That was one fo the first things I tried. It works, until the object leaves the world. Once it does, it is stuck with the sector number of the one it was in when it left (and it keeps that number, even if it returns into the world). So, if you had a line-of-sight with the target coordinates, it would work. Otherwise, no.

 

But thank for the suggestion anyway... [http://forums.massassi.net/html/smile.gif]

------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2002-01-22, 4:15 AM #16
Apparently, LEC could not calculate a thing's sector in JK. Sectors are only assigned to a thing when it enters the sector. Cog verbs like TeleportThing() take the sector from one thing and give it to another - they don't find the sector.

But for MotS, there's FindSectorAtPos(). So LEC did manage it somehow. If they didn't change the engine to do this, some sort of formula might be workable in JK.

Any improvements to that method, Seifer?

------------------
More matter with less art.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-01-22, 7:37 AM #17
I don't doubt there's some math formula that will find the correct sector, but it would be very complicated(though easier for the computer).

My version uses HasLOS() to make sure the center of the sector can see the position.

Code:
# findsector.cog
#
# Find the sector when given only a position.
#
# [SM]
#===========================================#
symbols

thing		player			local

sector	possector		local

template	gtemp=+ghost		local

thing		posghost			local
thing		centghost		local

int		i				local

vector	playerpos		local

message	activated

end
#===========================================#
code
#--------------------------------------------------------
activated:
	player=jkGetLocalPlayer();
	playerpos=GetThingPos(player);

	// Turn off all adjoins.
	for(i=0; i < GetSectorCount(); i=i+1) SectorAdjoins(i, 0);

	for(i=0; i < GetSectorCount(); i=i+1)
	{
		posghost=CreateThingAtPos(gtemp, i, playerpos, '0 0 0');
		centghost=CreateThingAtPos(gtemp, i, GetSectorCenter(i), '0 0 0');
		if(HasLOS(centghost, posghost))
		{
			possector=i;
			Print("Visible in this sector:");
			PrintInt(i);
			PrintInt(GetThingSector(player));
			call turnon;
			DestroyThing(posghost);
			DestroyThing(centghost);
			Return;
		}
		DestroyThing(posghost);
		DestroyThing(centghost);
	}

	turnon:

	// Turn the adjoins back on.
	for(i=0; i < GetSectorCount(); i=i+1) SectorAdjoins(i, 1);

Return;
#--------------------------------------------------------
end


This cog works very well in Canyon Oasis, but in levels like Toy4demo and 15 Escape Ship, it does not return the correct sector. I think this has something to do with the number of sectors the level has. I think Toy4 and ES have over 1000 while CO has under 100. Anyone know something about that?

The code I just wrote will choke JK if it has to search 1000 sectors. A combination of Seifer's code and mine would be better. Seifer's method would return sector candidates and my code would check those sectors to find which one the pos was in.

------------------
More matter with less art.

[This message has been edited by SaberMaster (edited January 22, 2002).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-01-22, 7:43 AM #18
GAH! Why didnt I think of that?!?

 

Sounds like a good idea. Ill try it...

------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2002-01-22, 8:07 AM #19
Welp, I tried it, and it doesnt work as it should. In my test level, it returned 0 as the occupied sector, when the player was actully in 9. [http://forums.massassi.net/html/frown.gif]

------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2002-01-22, 9:05 AM #20
Success.


Code:
Symbols
Message Startup
Flex Sleeptime=1.0
Vector Pos
Template Type
Int Pos_				Local
Int Sec_				Local
Int I=0				Local
End
Code
Startup:
Sleep(Sleeptime);
Pos_ = Createthingatpos(Type, 0, Pos, '0 0 0');
For(I=0;I<Getsectorcount();I=I+1) { Setsectoradjoins(I, 0); }
For(I=0;I<Getsectorcount();I=I+1) {
Sec_ = Createthingatpos(Type, I, Getsectorcenter(I), '0 0 0');
If(Haslos(Sec_, Pos_) == 1) { Printint(I); }
Destryothing(Sec_); }
For(I=0;I<=Getsectorcount();I=I+1) { Setsectoradjoins(I, 1); }
Stop;
End


A slightly modified version of SM's code. It worked on my test level. But my level only has 12 sectors...


I am in the proccess of adapting Seifer's code.

------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2002-01-22, 11:28 AM #21
Completion.

Code:
#01/2002 GBK
Symbols
Message Startup
Flex Sleeptime=1.0
Vector Pos
Template Type
Int Pos_				Local
Int Sec_				Local
Int I=0				Local
Int I2=0				Local
End
Code
Startup:
Sleep(Sleeptime);
Pos_ = Createthingatpos(Type, 0, Pos, '0 0 0');
For(I=0;I<Getsectorcount();I=I+1) { Setsectoradjoins(I, 0); }
For(I=0;I<Getsectorcount();I=I+1) {
For(I2=0;I2<=Getnumsectorvertices(I);I2=I2+1) {
If(Vectordist(Getsectorcenter(I), Getsectorvertexpos(I, I2)) >= Vectordist(Getsectorcenter(I), Pos)) {
Sec_ = Createthingatpos(Type, I, Getsectorcenter(I), '0 0 0');
If(Haslos(Sec_, Pos_) == 1) { Printint(I); }
Destryothing(Sec_); } } }
For(I=0;I<=Getsectorcount();I=I+1) { Setsectoradjoins(I, 1); }
Stop;
End



A simplified combination of bolth techniques. ...And it works... [http://forums.massassi.net/html/biggrin.gif]

 

I ran several tests on it, and it passed. So, if noone minds, I will declare victory and move on. [http://forums.massassi.net/html/wink.gif]

------------------
Success is the inverse relationship between effort, gain, and loss.

[This message has been edited by GBK (edited January 22, 2002).]
And when the moment is right, I'm gonna fly a kite.

↑ Up to the top!