AggrorJorn Posted March 30, 2010 Share Posted March 30, 2010 I'm working on my "picking up objects" code but I am facing a problem. I can pick up the object but the positioning of the object is not working correctly. The object is being placed by using the camera position plus 2 more in the z axis. However, since the axis of the camera doesn't rotate, the object is always placed in the wrong place: if pick.entity~=nil then pickedUpEntity = pick.entity pickedUpEntity:SetPosition(Vec3(camera.position.x+1,camera.position.y,camera.position.z+1)) end Quote Link to comment Share on other sites More sharing options...
Canardia Posted March 30, 2010 Share Posted March 30, 2010 You can use the global rotation of the camera. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 31, 2010 Author Share Posted March 31, 2010 thanks for the reply Lumooja. The rotation can display a very high value since the camera can be looking from 360 to -360 degrees on the Y axis alone. Any suggestions on how I can calculate the z axis from a camera perspective? Quote Link to comment Share on other sites More sharing options...
Joh Posted March 31, 2010 Share Posted March 31, 2010 I don't think to understood correctly, but couldn't you use camerapick? Quote Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10. Link to comment Share on other sites More sharing options...
Rick Posted March 31, 2010 Share Posted March 31, 2010 So as I understand it when you pick up and object in the world, you want that model to be directly in front of the camera and follow the camera around. I think what I would do is first create a permanent pivot with the camera. Init it at the position/rotation of the camera and then use MoveTo(Vec3(0, 0, 2)) (pos or neg I can't remember) to move the pivot "forward" in front of the camera. Then parent this pivot to the camera so when the camera moves this pivot will always move with it and will always be in front of the camera. Then when you pick up an object all you have to do is assign it's position to this pivots global position. Now it'll always be in front of the camera no matter what. 1 Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 31, 2010 Author Share Posted March 31, 2010 Rick thats briljant. Way easier then what I had in mind. I'll try that out immediately. When It works I'll post the code back here. Quote Link to comment Share on other sites More sharing options...
Rick Posted March 31, 2010 Share Posted March 31, 2010 Glad to help. This is why I love entity programming so much. The solutions are generally really easy. The only downside is that you end up creating a bunch of "objects", like pivots, and have to manage/free them where if you did it with math you wouldn't need to worry about that, but it's just so much easier to avoid the complicated math. Quote Link to comment Share on other sites More sharing options...
Joh Posted March 31, 2010 Share Posted March 31, 2010 I always prefer complicated math Quote Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10. Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 31, 2010 Author Share Posted March 31, 2010 Sure math would have been a lot cooler. First you would have to get the position of the camera. Then you would have to get the current rotation of the camera Then you would have to convert the current rotation value into the z axis of the current camera perspective. Quote Link to comment Share on other sites More sharing options...
Joh Posted March 31, 2010 Share Posted March 31, 2010 mmm i really didn't understand so much what are you trying to do but i think you can easly use tform.. If you set the position as local you will have the face of your entity (Camera) so just use z axis should be ok. It's similar to bullet.. Quote Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10. Link to comment Share on other sites More sharing options...
Rick Posted March 31, 2010 Share Posted March 31, 2010 Entities are just easier Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 31, 2010 Author Share Posted March 31, 2010 mmm i really didn't understand so much what are you trying to do but i think you can easly use tform.. If you set the position as local you will have the face of your entity (Camera) so just use z axis should be ok. It's similar to bullet.. I tried that but if I would specify a Z value then the object is being placed in the scene's z axis direction, instead of the z axis from the camera point of view. No matter from what angle I approach the object. Quote Link to comment Share on other sites More sharing options...
Joh Posted March 31, 2010 Share Posted March 31, 2010 TFormVector( Vec3(0,0,1), entity, null ) I was speaking of this. 1 Quote Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10. Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 31, 2010 Author Share Posted March 31, 2010 Thanks Joh that looks good. I have trouble understanding this command: TFormVector( Vec3(0,0,2),source, destiny ) Correct me if I am wrong: the 'source value' is the global position vector from the picked up entity (oildrum)? This vector is then converted to a local 'destiny' vector (the camera position)? Then the first value (the Vec3) is then added to the destiny command? Quote Link to comment Share on other sites More sharing options...
Rick Posted April 1, 2010 Share Posted April 1, 2010 Aggror, you edited what you had. Can you place that back so we can see how the TFormVector works? Quote Link to comment Share on other sites More sharing options...
Joh Posted April 1, 2010 Share Posted April 1, 2010 Correct me if I am wrong: the 'source value' is the global position vector from the picked up entity (oildrum)? This vector is then converted to a local 'destiny' vector (the camera position)? Then the first value (the Vec3) is then added to the destiny command? Sorry i was at home.. Well no you need to transform the local space of your entity to global space so it will be: Vec3(0,0,1) (just in front of your entity in local space) Source entity? camera (you need to place an object in fornt of it right?) Destination entity? null (null = global, you can also find the position based on other entities, but this isn't your case) so: V:TVec3 = TFormVector( Vec3(0,0,1), cam, null ); EDITED: (Thanks macklebee to remeber this..) V= Vec3(EntityPosition(cam).x +V.x,EntityPosition(cam).y +V.y,EntityPosition(cam).z +V.z); Where V is the position of 1 in front of your cam in global space, so you will place the oildrum there. This should work nicely. There is a really nice example here (this make the inverse thing, from global to local): http://www.leadwerks.com/wiki/index.php?title=TFormVector Quote Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10. Link to comment Share on other sites More sharing options...
macklebee Posted April 1, 2010 Share Posted April 1, 2010 you will also need to add the camera's position to this resulting TFormVector position when you are setting the position of the picked entity. 1 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Joh Posted April 1, 2010 Share Posted April 1, 2010 I forgot that.. Sorry. 1 Quote Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10. Link to comment Share on other sites More sharing options...
AggrorJorn Posted April 1, 2010 Author Share Posted April 1, 2010 Wwesome Joh and Macklebee! I would have never found that out myself. The object is being placed in front of the camera no matter what angle I approach the object now. The only thing remaining is stabalizing the object so that it doesn't start to rotate on incoming collisions. @Rick. I removed it because it wasn't working, but see the txt for what I have so far (editor game script). It is not finished ofcourse, since you can pickup every single model that exists. But At least I have something now where I can base my code on. thanks again for your enormous help! FPSpickupObjects.zip Quote Link to comment Share on other sites More sharing options...
Rick Posted April 1, 2010 Share Posted April 1, 2010 Cool. Mind was relative to another entity so I was able to get it working without the addition. This is generally why I just use the "entity" way though. It's easier for me to think in those terms. When messing around with 3D coords and different spaces my mind sort of gets lost. Quote Link to comment Share on other sites More sharing options...
Joh Posted April 1, 2010 Share Posted April 1, 2010 The only thing remaining is stabalizing the object so that it doesn't start to rotate on incoming collisions. I think there are 2 ways to do this: 1) Store object rotation and re-set it every loop (till you keep it) 2) Use SetBodyOmega with a vec3(0) till keep it (this should "freeze" the body) Never tested so it can be wrong. Quote Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10. Link to comment Share on other sites More sharing options...
ESP Posted April 1, 2010 Share Posted April 1, 2010 Could you bung this in a .zip for us? Robin Quote Programmer , Intel Quad core, NVIDIA GeForce GT 220, Windows 7 Pro, Galaxy Tab 2 ( 7" and 10"), LE2,LE3,3DWS Link to comment Share on other sites More sharing options...
macklebee Posted April 1, 2010 Share Posted April 1, 2010 I think there are 2 ways to do this: 1) Store object rotation and re-set it every loop (till you keep it) 2) Use SetBodyOmega with a vec3(0) till keep it (this should "freeze" the body) Never tested so it can be wrong. A combination of turning off the bodygravitymode and SetOmega seems to work just fine. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
macklebee Posted April 1, 2010 Share Posted April 1, 2010 sent the code to you in a PM, esp Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.