Need help with spatial geometry
#1

Hello, I`m trying to make a crane system, it`s complete, but, I need help to get REAL position of crane magnet, this magnet is an attached object to another object and I don`t know how I can get real position, not attached offsets.
Is any method?

Thank you!
Reply
#2

When i am not complete wrong, its just the x,y,z of the crane +offsetX, +offsetY, +offsetZ of the magnet
Reply
#3

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
When i am not complete wrong, its just the x,y,z of the crane +offsetX, +offsetY, +offsetZ of the magnet
Good idea, I tried right now, but, don`t work..

Quote:
Originally Posted by ******
Посмотреть сообщение
Assuming the crane rotates, you need trigonometry. Look up how to find a point on a circle.
Can you give me a small example, please?
Reply
#4

This is what I use create an explosion infront of the player. Not sure how good it is but it works, i think if you mess around with the code and the formula enough you can make your thing work.

PHP код:
new Float:x;
new 
Float:y;
new 
Float:z;
new 
Float:PlayerFacingAngle;
new const 
Float:DISTANCE 3.0;
GetPlayerFacingAngle(playeridPlayerFacingAngle);
PlayerFacingAngle PlayerFacingAngle-180.0;
new 
Float:F_FLOATSIN floatsin(-PlayerFacingAngledegrees);
new 
Float:F_FLOATCOS floatcos(-PlayerFacingAngledegrees);
F_FLOATSIN = -F_FLOATSIN;
F_FLOATCOS = -F_FLOATCOS;
GetPlayerPos(playeridx,z);
CreateExplosion(DISTANCE F_FLOATSINDISTANCE F_FLOATCOSz60); 
Reply
#5

Maybe you need this exact same thing: https://sampforum.blast.hk/showthread.php?tid=586841.
Reply
#6

Quote:
Originally Posted by IstuntmanI
Посмотреть сообщение
Maybe you need this exact same thing: https://sampforum.blast.hk/showthread.php?tid=586841.
Thank you verry much!
Now, I need to know real rotations of attached object.
Reply
#7

Quote:
Originally Posted by Lunoxx
Посмотреть сообщение
Thank you verry much!
Now, I need to know real rotations of attached object.
Using that function isn't going to help you then! You need something else.

https://github.com/Pottus/Texture-St...dio/tsmain.pwn
Line 1610

Код:
AttachPoint(Float:offx, Float:offy, Float:offz, Float:offrx, Float:offry, Float:offrz, Float:px, Float:py, Float:pz, Float:prx, Float:pry, Float:prz, &Float:RetX, &Float:RetY, &Float:RetZ, &Float:RetRX, &Float:RetRY, &Float:RetRZ, sync_rotation = 1)
The first six parameters is your attached object's XYZ/RXRYRZ offsets the next 6 parameters is the XYZ/RXRYRZ in which the the attached object is attached to.

Returns the actual position xyz/rxryrz of the attached object.
Reply
#8

I did something like: https://i.imgur.com/KQYZLSn.png, for test.. but, don`t work. Returns is only attached offsets of magnet. What`s wrong in my code?
Thank you for your response!

@Pottus
Reply
#9

Quote:
Originally Posted by Lunoxx
Посмотреть сообщение
I did something like: https://i.imgur.com/KQYZLSn.png, for test.. but, don`t work. Returns is only attached offsets of magnet. What`s wrong in my code?
Thank you for your response!

@Pottus
Because you are using two sets of offsets that is not that this function does! You need to calculate from a static XYZ/RXRYRZ point for this to work.
Reply
#10

Quote:
Originally Posted by Pottus
Посмотреть сообщение
Because you are using two sets of offsets that is not that this function does! You need to calculate from a static XYZ/RXRYRZ point for this to work.
I tried to calculate position for Crane Cabine, from crane base which is an real object, single "real object" from this crane, but, returns is invalid position, I will try again, probably I used wrong parameters.
Reply
#11

Same result.
Code: https://i.imgur.com/8kPEo7a.png
Results:
Код:
values 1: 0.000000 0.000000 -0.009998 -0.469998 0.000000 90.000000 // offsets of crane cabine
values ret: -383.852844 1154.011108 -0.009998 -0.469991 0.000000 136.199996 // returned by function
And real position of crane-base:
Код:
-1541.100219,130.634063,26.704730,0.000000,0.000000,46.199996 // position of crane base (CreateDynamicObject)
(Crane cabine is directly attached to crane-base)
Reply
#12

You messed up you are passing rotation values for position and rotation.

@Edit

Show me your attached offset positions.
Reply
#13

Quote:
Originally Posted by Pottus
Посмотреть сообщение
You messed up you are passing rotation values for position and rotation.

@Edit

Show me your attached offset positions.
Код:
AttachDynamicObjectToObject_lnx(cabina, baza, 0.000000,0.000000,-0.009999,-0.469999,0.000000,90.000000); // cabine to base
AttachDynamicObjectToObject_lnx(brat, cabina, 0.000000,-2.069998,8.448098,0.000000,0.000000,0.000000); // crane-arm (i think) to cabine
AttachDynamicObjectToObject_lnx(cablu0, brat, 0.000000,36.869819,-0.569999,0.000000,0.000000,0.000000); // cable to arm
AttachDynamicObjectToObject_lnx(magnet, cablu0, 0.000000, 0.000000,-7.440086,0.000000,0.000000,0.000000); // magnet to cable
AttachDynamicObjectToObject_lnx(cablu1, magnet, 0.000000, 0.000000,7.440086,0.000000,0.000000,0.000000); // suplimentary cable for "effect go-down"
EDIT: _lnx because I saved in this function offsets in variables.
Reply
#14

Show me the values basepos[]

@Edit

I also noticed you are attaching objects to object to object etc.. that means you need to rotate the point several times! Using the result as the next point of reference and translating the offsets to the next position rotation. It sounds complicated but it's very easy.

Код:
// List of attached objects to the base we need to calculate sequentially in
// order to figure out the position of the last attached object
static Float:CraneOffsets[6][6] = {
	{ 0.000000,0.000000,-0.009999,-0.469999,0.000000,90.000000 },// cabine to base
	{ 0.000000,-2.069998,8.448098,0.000000,0.000000,0.000000 },// crane-arm (i think) to cabine
	{ 0.000000,36.869819,-0.569999,0.000000,0.000000,0.000000 },// cable to arm
	{ 0.000000, 0.000000,-7.440086,0.000000,0.000000,0.000000 },// magnet to cable
	{ 0.000000, 0.000000,7.440086,0.000000,0.000000,0.000000 }// suplimentary cable for "effect go-down"
};


FindCraneOffset()
{
	// Get the position of the cranebase (unless it doesn't change you can set this)
	new Float:ret[6];
	GetDynamicObjectPos(ret[0], ret[1], ret[2]);
	GetDynamicObjectRot(ret[3], ret[4], ret[5]);

	// The first return reference is of course the base!
	for(new i = 0; i < 6; i++)
	{
		// Loop through each offset and rotation calculate real world position
		AttachPoint(CraneOffsets[i][0], CraneOffsets[i][1], CraneOffsets[i][2], CraneOffsets[i][3], CraneOffsets[i][4], CraneOffsets[i][5],
		ret[0], ret[1], ret[2], ret[3], ret[4], ret[5],
		ret[0], ret[1], ret[2], ret[3], ret[4], ret[5]);
	}
	return 1;
}
Didn't test it but the idea is you start with the base it's position+rotation.
Now you need to calculate the real world position of the first object based on it's offsets and rotation.
Then the next based off the last...
etc...

Get it? Maybe? Sort of? You also might not have to do all the objects only up to where you need to but that is how it is done.
Reply
#15

Quote:
Originally Posted by Pottus
Посмотреть сообщение
Show me the values basepos[]

@Edit

I also noticed you are attaching objects to object to object etc.. that means you need to rotate the point several times! Using the result as the next point of reference and translating the offsets to the next position rotation. It sounds complicated but it's very easy.

Код:
// List of attached objects to the base we need to calculate sequentially in
// order to figure out the position of the last attached object
static Float:CraneOffsets[6][6] = {
	{ 0.000000,0.000000,-0.009999,-0.469999,0.000000,90.000000 },// cabine to base
	{ 0.000000,-2.069998,8.448098,0.000000,0.000000,0.000000 },// crane-arm (i think) to cabine
	{ 0.000000,36.869819,-0.569999,0.000000,0.000000,0.000000 },// cable to arm
	{ 0.000000, 0.000000,-7.440086,0.000000,0.000000,0.000000 },// magnet to cable
	{ 0.000000, 0.000000,7.440086,0.000000,0.000000,0.000000 }// suplimentary cable for "effect go-down"
};


FindCraneOffset()
{
	// Get the position of the cranebase (unless it doesn't change you can set this)
	new Float:ret[6];
	GetDynamicObjectPos(ret[0], ret[1], ret[2]);
	GetDynamicObjectRot(ret[3], ret[4], ret[5]);

	// The first return reference is of course the base!
	for(new i = 0; i < 6; i++)
	{
		// Loop through each offset and rotation calculate real world position
		AttachPoint(CraneOffsets[i][0], CraneOffsets[i][1], CraneOffsets[i][2], CraneOffsets[i][3], CraneOffsets[i][4], CraneOffsets[i][5],
		ret[0], ret[1], ret[2], ret[3], ret[4], ret[5],
		ret[0], ret[1], ret[2], ret[3], ret[4], ret[5]);
	}
	return 1;
}
Didn't test it but the idea is you start with the base it's position+rotation.
Now you need to calculate the real world position of the first object based on it's offsets and rotation.
Then the next based off the last...
etc...

Get it? Maybe? Sort of? You also might not have to do all the objects only up to where you need to but that is how it is done.
Yes, I understand what you said.. but, don`t work
Returned by your code: https://i.imgur.com/Q8YeDPB.png

Anyway, thank you, maybe you have a another ideea? :d

@ Firstly, I tried to get only cabine coordonates with AttachPoint function, to test function, but, without success..
Reply
#16

I told you what you need to do but I know there is something you are over looking. How am I supposed to know without seeing all the code ?
Reply
#17

Quote:
Originally Posted by Pottus
Посмотреть сообщение
I told you what you need to do but I know there is something you are over looking. How am I supposed to know without seeing all the code ?
I will send you all of code in PM.

edit: Done.
Reply
#18

Bump?
Reply
#19

another idea?
Reply
#20

Bumppp
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)