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 / Keep object in front of the camera

Author
Message
zapakitul
17
Years of Service
User Offline
Joined: 1st Mar 2007
Location: In my world
Posted: 13th Mar 2009 15:48 Edited at: 13th Mar 2009 15:57
I'm trying to "pick up an object" (not using dbPickObject), and position it in front of the camera. Here's what i have until now:

Object 2 is the player model which is followed by the camera. Did that by using dbSetCameraToFollow(etc). Now, the code above picks up the object but if i turn my camera left, the object remains in place. Any ideas?

Edit: dbLockObjectOn is not what i am looking for btw ! I want to do something similar to Fallout 3 object picking. Like when you are a small boy, and you play around with your teddy bear or the ball!
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 14th Mar 2009 08:14 Edited at: 14th Mar 2009 08:15
Here: "dbPositionObject(ID,dbCameraPositionX(),dbObjectPositionY(2),dbObjectPositionZ(2)+7);"

You mix up ID, 2 and the camera? Assuming object 2 is your player object it's quite simple. The issue with your current code is that you're only offsetting the object by 7 units on the Z axis, the Z axis won't always by the direction in front of the player or camera. To get this direction use dbGetObject( objectID )->position.vecLook, this will give you the object's look vector in a D3DXVECTOR3 struct, you can then extract the x/y/z member elements to this vector and add them in place of your +7, but do it on all 3 axis, and make sure you multiply each element when adding it, by the desired distance(7?).

zapakitul
17
Years of Service
User Offline
Joined: 1st Mar 2007
Location: In my world
Posted: 14th Mar 2009 08:46 Edited at: 14th Mar 2009 08:50
Yay for another undocumented function. Thank you dark coder. Here's the result, maybe someone will have the same problem and will need some help:
prasoc
16
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 14th Mar 2009 09:56 Edited at: 14th Mar 2009 09:57
Couldn't you do:



aswell?
zapakitul
17
Years of Service
User Offline
Joined: 1st Mar 2007
Location: In my world
Posted: 14th Mar 2009 09:58
Yeah but i wanted to rotate the object while moving it, and if i would change it's angle, then it would have moved in a different direction then my "camera object"
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 14th Mar 2009 16:48
I said multiply each element by the distance, not just the Z; You need to stop thinking of Z as depth when rotations are involved. Also, it would be faster to get the pointer to the D3DXVECTOR3 structure then dereference each element from that and add it to your object's position than your current method. It would also make the code shorter and neater.

i.e.

D3DXVECTOR3* lookVector = &dbGetObject(ID)->position.vecLook; etc...

Lion Jin
18
Years of Service
User Offline
Joined: 24th Sep 2006
Location:
Posted: 16th Mar 2009 03:22
The most easy way is that,put your object in the position of the camera ,also make its rotation as the camera as well ,then ,using dbMoveObject() to move that object forward a bit.so that ,it will be always in front of the camera.

Login to post a reply

Server time is: 2024-11-25 17:27:01
Your offset time is: 2024-11-25 17:27:01