Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Help I suck at 3D

Author
Message
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 29th Aug 2009 05:55
For the DBC challenge I'm attempting a simple FPS (mainly to get some practice for the DarkAwesomeDudesWithNoName team).
I've made a crude gun by sticking two cylinders to a host object but rotating the gun and keeping it flat is proving difficult. If I yrotate and look up/down the gun twists. What am I doing wrong?
Should I be fixing the pivot?

TGC Forum - converting error messages into sarcasm since 2002.
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 29th Aug 2009 06:21
to pitch the gun up you have two options:

pitch object up/down

or

xrotate object

pitch would probably be best since you dont need to know the angle or the gun to use it

Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 29th Aug 2009 06:45 Edited at: 29th Aug 2009 06:47
Put the gun back into your modelling package and position it so that it is centred near to the handle (where the gun would pivot if you were holding it), then save it again.

That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 29th Aug 2009 06:47
I think the "gun" is made in game rather than externally saved pincho

Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 29th Aug 2009 06:49
Oh.. can't remember how to do it in code.

Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 29th Aug 2009 07:07
Quote: "Put the gun back into your modelling package and position it so that it is centred near to the handle (where the gun would pivot if you were holding it), then save it again."

Ah I figured having it pivot from the middle would work but I'll try offsetting it, thanks.
Smartguy's right, it's just in DB.

TGC Forum - converting error messages into sarcasm since 2002.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 29th Aug 2009 07:47
If it's 3 separate objects you could also have problems, because they should be 3 limbs.

BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 29th Aug 2009 08:39
You could position it at the camera then using the Free Flight Rotation commands (roll pitch turn object) you could place them and then use the SET OBJECT TO CAMERA ORIENTATION command.

Rather involved but could be done in a subroutine or function to clean things up.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 29th Aug 2009 11:16 Edited at: 29th Aug 2009 11:32
Quote: "DarkAwesomeDudesWithNoName"


This has got to be the name for the team!

I think the offset should work. Assumingly, the cylinder is the barrel of the gun so it initially points in the y direction. So create it, scale it, Xrotate it 90 degrees, then offset it half the y length in the z direction. Then make it into a mesh, and delete the original object. Add the mesh as a limb to another object and position that object at the camera's location. The example shows the details.



Enjoy your day.
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 29th Aug 2009 11:37
try "lock object on".

TheComet


Make the paths of your enemies easier with WaypointPro!
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 29th Aug 2009 12:11
The problem with the Lock Object commands is that it resets the coordinate system, which makes it difficult for certain actions. For instance, if you try to shoot from the guns position using the OBJECT POSITION commands, they will return the offset values from the camera, rather than real world coordinates.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 29th Aug 2009 13:13
Quote: "try "lock object on"."


Quote: "The problem with the Lock Object commands is that it resets the coordinate system, which makes it difficult for certain actions. For instance, if you try to shoot from the guns position using the OBJECT POSITION commands, they will return the offset values from the camera, rather than real world coordinates."


Lock object on can be a quick solution and should suffice in many situations, but I'd have to agree with BN2 that it opens up a new set of problems. Besides the problems that BN2 mentioned, the locked object will not respond to changes in lighting angles based on the camera position and direction. Objects locked on can sometimes appear inside out, or be partially clipped in ways that are undesirable. I think lock object on is best used for radars and displays or panels. It can work for weapons but is subject to the above challenges.

Enjoy your day.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 29th Aug 2009 15:31
Offsetting the gun didn't seem to help.
I tried using sin and cos to control the rotation on each axis, but when the gun is at 90 on y axis, rotating x or z twists the barrel, i've checked and there's no typo, I can't understand why both x and z produce the same rotation.
Maybe this has something to do with the zyx rotation?

Thanks for the help.
Sorry I can't post a snippet, I'd have to copy it out by hand and it took 1.5 hours last time I did that!

TGC Forum - converting error messages into sarcasm since 2002.
Hk47
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 29th Aug 2009 19:22
if you are only rotating on the x and y axises, try doing: set object rotation zyx after you create the object.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 29th Aug 2009 23:20
@Obese87

The snippet I posted above works with a cylinder fixed to the camera's rotation. What about the method couldn't you adapt to what you are doing? The offset in my example changes the pivot point of the cylinder from it's center to it's end (like swinging a baseball bat instead of spinning a wheel). Just offsetting the cylinder alone without changing it's pivot will not move the pivot point from the center to the end. You change the pivot point by offsetting limb 0 of the cylinder then making a mesh out of it. Use the mesh as a limb to another object and delete the original cylinder. Or delete the original cylinder and make a new object out of the cylinder mesh.

And like Hk47 suggested, if you are orienting an object to the camera's rotation, you have to reverse the rotation order with set object rotation zyx.

Quote: "I can't understand why both x and z produce the same rotation"

That's the problem with Eulers. You can get around it by using limbs (with their pivot offset properly) or by using 3d matrix math. But using limbs is much easier. The main object rotates on the y axis and the limb rotates on it's own x and z.

Enjoy your day.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 30th Aug 2009 00:54
Ah I think the independant limb rotation might be the answer, why doesn't euler work properly??
The gun is offset from it's host object (a plain), so I'll control the y axis with the host and x/z with the gun.

In my attempts to stabilise the gun I realised that the y angle of the host object affects the amount of x/z rotation required to tilt the gun up and down, i.e. y=0 puts the tilt bang on the x axis, and y= 90 puts the tilt bang on the z axis. so I thought I'd try to use trigonometry to adjust these values for me.

Am I on the right track? Is this still required?

Man this is more difficult than I was expecting

TGC Forum - converting error messages into sarcasm since 2002.
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 30th Aug 2009 01:31
This is the method I was thinking of. I have used it before and it works.



Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 30th Aug 2009 02:14
@BN2
Thanks for the code, I don't like the idea of moving the gun all over the place to get it in the right position though.

There has to be a simple way to do this, I'm sure I'm just missing the maths. Can we start the DarkAwesomeDudesWithNoName project so I can learn how to do this

Thanks for all your input, you all gave me stuff to work with but I am very fussy and I want this to be simple like it should be

TGC Forum - converting error messages into sarcasm since 2002.
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 30th Aug 2009 07:52
Quote: "Thanks for the code, I don't like the idea of moving the gun all over the place to get it in the right position though."


Nor do I, but I hate working with trig a little more (simple 2d trig is easy, its 3d that I hate).

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 30th Aug 2009 20:59
Quote: "Thanks for all your input, you all gave me stuff to work with but I am very fussy and I want this to be simple like it should be"

It's not simple. The simplest method is LOCK OBJECT ON. The next simplest method is setting an object with a limb that is the gun to the camera's position and orientation or set the camera to the object's position and orientation - with the pivot point of the limb set at it's base instead of it's center. The next simplest method is trig.

No matter what the case, the object or the camera have to be placed at the other's location and oriented to match.

Quote: "why doesn't euler work properly??"

It's not that they don't work properly it's just that many combinations of rotations end up in the same place. A single 180 degree Y rotation is the same as a 180 Degree X rotation + a 180 degree Z rotation. The Object ends up in the same orientation. The rotation order of the angles determines the orientation. If we just rotated Y 180 degrees, a single rotation of 180 degrees X would face the same way as the Y rotation, but the object would be upside down.

So when you rotate angles in DBC, it uses it's internal rotation order to determine the final orientation - which may not end up like you want. The other monkey wrench in the machinery is that the camera rotation order is opposite from the object rotation order. So if you are trying to orient an object to the camera you should use SET OBJECT ROTATION ZYX.

Enjoy your day.
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 30th Aug 2009 22:24
Hey, I threw this together this morning, but it isn't working, though it ALMOST is.



Apart from not quite getting the x and z offsets right, the object angle X seems to randomly switch between positive and negative when rotating around the y axis for some reason.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 30th Aug 2009 23:34
Quote: "Apart from not quite getting the x and z offsets right, the object angle X seems to randomly switch between positive and negative when rotating around the y axis for some reason."

Well, when you change the x y and z angles of an object, you can change it's orientation such that the behavior of rotation can be opposite of what you'd expect.

Tilting an object on a terrain is a great example of the same thing that is happening here. For example, if you xrotate an object 30 degrees, then y rotate it 180 degrees, the actual x orientation relative to the direction the object is facing would be 330 degrees (at angle y=0 the object would be pointing down and at y=180 the object would be pointing up). However, DB would still be reporting the x angle as 30 degrees. If the object had been on a downward slope at y=0, then when it turns around to y=180, it would be on an upward slope so the tilt calculation would be in the opposite direction. The tilt calculation would calculate the angle at 330. If you were now to tilt the object 330 degrees it would point the object on the wrong tilt (down on an upward slope).

Make any sense?

Whenever I speak about the pivot point of an object, I'm talking about the point that all the vertices would be rotated around. When you create a primative in DBC, the pivot point is the center of the object. In order to move this pivot, limb 0 has to be offset in the opposite direction to where you want the pivot point to be. The object then has to be converted to a mesh, and then made back into an object or added as a limb to set this new pivot point. The same with changing the facing of an object. FIX OBJECT PIVOT doesn't really change the rotational facing but calculates a rotational offset internally.

Anyway, here is a link to a function for the matrix math (trig) method of locking an object to the camera:

Lock Object to Camera

Enjoy your day.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 31st Aug 2009 02:48 Edited at: 31st Aug 2009 02:51
Haha I was just about to post about the same thing!
Yes it seems the DB orientation commands take care of the effect on the other axis (plural anyone?) by turning them 180 degrees.

I tried latch's suggestion of two "hinged" rigging objects working the separate axis's's, it worked well but then I tried to position the camera on the gun and found the same problems as before. Then I used the DB orientation (turn & pitch) on the camera and it worked fine but a strange thing happened. when the gun was over/under a certain vertical tilt it would no longer turn with the camera, it got stuck. I coded my program to switch between FPS view to 3rd person and in 3rd person the gun still moved around fine.

Quote: "If the object had been on a downward slope at y=0, then when it turns around to y=180, it would be on an upward slope so the tilt calculation would be in the opposite direction. The tilt calculation would calculate the angle at 330. If you were now to tilt the object 330 degrees it would point the object on the wrong tilt (down on an upward slope)."

Of course, that's so obvious now you say it!

I think we inadvertantly started work on the DADWNN project here!
I go on holiday tomorrow though haha, back wednesday 8th.

And when I return I will defeat Euler and avenge the death of my father!
He was a pilot and one day he pulled up 60 degrees on the x axis forgetting he was facing the wrong way and crashed into matrix mountain...

TGC Forum - converting error messages into sarcasm since 2002.

Login to post a reply

Server time is: 2024-05-09 17:12:22
Your offset time is: 2024-05-09 17:12:22