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 Professional Discussion / Offset limb, rotate limb (or something related) Homeworld style camera jumping

Author
Message
Ben_UK78
15
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 10th Sep 2013 23:45
Hi All,

I have a strange issue that I cannot quite identify.

I have created a camera in the style of Homeworld. It works using an object with 2 limbs. The object can move about. Limb 1 handles left/right rotation and Limb 2 (which is linked to Limb 1) handles the up/down rotation.
I have done this so I don't have to work out the maths and have a system easy for me to follow and use. If I am doing this in a silly way then feel free to tell me.

I have it set up so you click on the right mouse button to rotate around and use the mousez() wheel to move in and out of the model.

The strange behaviour I see is that as I zoom in and out using the mouse wheel very occasionally I see the object flicker on the screen (as if surviving for 1 frame update or so), but in an orientation that suggests that the camera has jumped directly above it...

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 11th Sep 2013 12:01
Instead of defining all camera movements as integer...try as float

I'm not a grumpy grandpa
Ben_UK78
15
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 11th Sep 2013 12:15 Edited at: 11th Sep 2013 14:48
Hi,
Thanks for the reply.

Setting: (global g_CAMERA_Offset# as float) still produces the strange occasional flicker as you zoom in and out. I gave myself a little headslap for not setting it as a float (I did it because it is an offset, not an x,y,z position so I thought it would handle adding it to the models internal variables - or at least imagined that would work).

However, the problem has not gone away. I assume I am missing something simple...

Here is the code with the variable changed to a float incase I missed the change you were referring to.

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 11th Sep 2013 13:57
Try putting the freecam input function at the start of the camera_rts function, rather than at the end of it.

And you don't need to explicitly declare variables in functions as local. They already are.

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 11th Sep 2013 14:31 Edited at: 11th Sep 2013 14:31
Quote: "And you don't need to explicitly declare variables in functions as local. They already are."


100% True, but I think it is a personal matter.

I declare locals explicit anyway for consistency, when your code piles up it becomes more likely for you to forget that a local is also a global.

I also do it so that they syntax highlight in Indigo. I even declare arrays as global, even though they are by default for consistency, the same way in VB.NET I declare properties as public, and in JavaScript i use the var keyword; even though they are so by default.

Something I do not do is local l_CAMObj_Limb_Y# as float because all variables suffixed with # are floats anyway, but again that is personal.

Ben_UK78
15
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 11th Sep 2013 14:46 Edited at: 11th Sep 2013 14:48
Hi All again.

I agree with regard to the local definitions. I use the personal naming l_, g_, and c_ (local, global, constant) when I name variables - that way I always know what type a variable is.

Anyway, sadly it cannot be the code for rotating the camera [function: FREECAM_INPUT_Mouse_Button2()] since commenting it out still produces the effect.

It seems whatever causes it does it just with:
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 11th Sep 2013 14:59 Edited at: 11th Sep 2013 15:25
The Math way to do this would be:

1: Store mouse inputs
2: Update camera angle
3: Work out the look vector based on our angle
4: Scale that look vector by our zoom amount
Edit: 5: Add scaled vector to your point position

You'd position the camera at (5) and just point it where that point is. Also it would use far less code.

Quote: "local definitions"


I just put _ in front of whatever is global and constant are in all caps. No need for the extra letters:

local
_global
CONSTANT


"Get in the Van!" - Van B
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 11th Sep 2013 16:38
Yeah everyone has their own way. I use underscore prefixes for 'precompiled' functions: _NEW Array() is the same as Array Insert At Bottom Array().

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 11th Sep 2013 18:25 Edited at: 11th Sep 2013 18:38
Here a quick example of what I'm talking about, I call it a dirty version cause I wrote it quick.

Press any key to change object focus
Use mouse to rotate and mouse wheel to zoom



There's also a cheap way of making Up, Right and Look(forward) Vectors using objects



"Get in the Van!" - Van B
Ben_UK78
15
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 11th Sep 2013 18:45
Brilliant. Thanks very much - works perfectly. I will adapt this instead.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 11th Sep 2013 23:39
I would like to solve the initial problem but I don't have EZrotate so this is all I could offer. Might look it over just to see if I can work it out!

"Get in the Van!" - Van B
Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 12th Sep 2013 05:08
Quote: "I declare locals explicit anyway for consistency, when your code piles up it becomes more likely for you to forget that a local is also a global."


I agree, even though I don't always adhere to it, this is good form. In DBP I usually set the variables equal to 0 rather than using Local. I wouldn't zero an entire array though unless I had to, due to performance considerations.

Login to post a reply

Server time is: 2026-07-07 00:50:19
Your offset time is: 2026-07-07 00:50:19