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.

Dark GDK / Positions

Author
Message
AlexI
19
Years of Service
User Offline
Joined: 31st Dec 2004
Location: UK
Posted: 2nd Nov 2008 13:35
Hi,
I have written this code to offset the position of a gun:

I don't want to use offset limb or lock object

Could someone show me how i could use maths so that I would'nt need to use the move object commands and that I would just need to position the object once.
Thanks,
Alex

jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 2nd Nov 2008 17:15
Why? THhe code you have there seems to be fine, except possibly move the rotate command the to before all the move commands. It shouldn't be much of a performance hit if you're only going to run that once a frame.
AlexI
19
Years of Service
User Offline
Joined: 31st Dec 2004
Location: UK
Posted: 2nd Nov 2008 18:28
It would be more efficient to use maths i think And i want to know how you would do that too

General Reed
18
Years of Service
User Offline
Joined: 24th Feb 2006
Location:
Posted: 3rd Nov 2008 23:09
Yes it is more efficient. Here are a set of useful functions i created a while back, in DBPro for one of my engines.

Quote: "`Returns the correct x position, for the specified offset
function offsetGetXPosition(angleX as float, angleY as float, angleZ as float, xOff as float, yOff as float, zOff as float)
sx as float : sy as float : sz as float
cx as float : cy as float : cz as float
xPos as float : yPos as float : zPos as float
sx = sin(angleX) : cx = cos(angleX)
sy = sin(angleY) : cy = cos(angleY)
sz = sin(angleZ) : cz = cos(angleZ)
xPos = xOff*(cy*cz) + yOff*(sx*sy*cz-cx*sz) + zOff*(cx*sy*cz+sx*sz)
endfunction xPos

`Returns the correct y position, for the specified offset
function offsetGetYPosition(angleX as float, angleY as float, angleZ as float, xOff as float, yOff as float, zOff as float)
sx as float : sy as float : sz as float
cx as float : cy as float : cz as float
xPos as float : yPos as float : zPos as float
sx = sin(angleX) : cx = cos(angleX)
sy = sin(angleY) : cy = cos(angleY)
sz = sin(angleZ) : cz = cos(angleZ)
yPos = xOff*(cy*sz) + yOff*(cx*cz+sx*sy*sz) + zOff*(cx*sy*sz-sx*cz)
endfunction yPos

`Returns the correct z position, for the specified offset
function offsetGetZPosition(angleX as float, angleY as float, angleZ as float, xOff as float, yOff as float, zOff as float)
sx as float : sy as float : sz as float
cx as float : cy as float : cz as float
xPos as float : yPos as float : zPos as float
sx = sin(angleX) : cx = cos(angleX)
sy = sin(angleY) : cy = cos(angleY)
sz = sin(angleZ) : cz = cos(angleZ)
zPos = xOff*(-1*sy) + yOff*(sx*cy) + zOff*(cx*cy)
endfunction zPos"


Get the x y and z offset positions, from those commands. Then add the parent object's position, to the offset values returned from those functions. Then rotate the child object, to the angle of the parent object. And there you go, it should be correctly offset.

Hope this helps

-General Reed

CPU: AMD X2 6000+ 3.0ghz GFX: NVIDIA BFG Geforce 8800GTS 640MB OC-550mhz core RAM: 2048mb

Login to post a reply

Server time is: 2024-11-25 05:35:36
Your offset time is: 2024-11-25 05:35:36