Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (1 invisible), 857 guests, and 10 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Help me convert this simple camera code block? #219519
08/03/08 00:14
08/03/08 00:14
Joined: Feb 2002
Posts: 288
California, USA
J
jaknine Offline OP
Member
jaknine  Offline OP
Member
J

Joined: Feb 2002
Posts: 288
California, USA
I have the following as part of my camera code:
Code:
if(mouse_right) 
{
	mouse_map=cursor_orbit;

	//center_cursor();
	MOUSE_POS.X = (screen_size.x / 2);
	MOUSE_POS.Y = (screen_size.y / 2);

	// add mouse forces
	MY.skill1 -= (mickey.x*cameraFree01_mouse_force)*(time_step * 1.5); // pan
	MY.skill2 -= (mickey.y*cameraFree01_mouse_force)*(time_step * 1.5); // tilt

}


When the user holds the right mouse button, the mouse cursor is centered in the view and the camera rotates around its own axis.

This code is being used in a modified "cameraFree01.wdl" file. The cameraFree action is assigned to a dummy entity in my level.

I would like the camera to orbit (instead of rotate) around a point in the center of the view at an arbitrary distance. I want to do this in my existing modified cameraFree code (instead of switching to cameraOrbit or something else).

How can I change the code above to do this?

Thanks!

Re: Help me convert this simple camera code block? [Re: jaknine] #219528
08/03/08 02:18
08/03/08 02:18
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Hi, i've just written a little snippet that should do the job. Just add this to your script file, and then assign the action in wed.

Code:
action orbit_player()

{
var centerx = 0; // centre of circle (x)
var centery = 0;  // centre of circle (y)
var radius = 400; // radius of circle
var theta = 0; // degrees done around the circle
	
player = me;
camera.genius = me;
while(1)
{ 
		
camera.pan = my.pan;
camera.tilt = clamp(camera.tilt,-70,70);
		
if(mouse_right)
{
theta+=1*time_step;
me.x = centerx +(radius * sinv(theta));
me.y = centery + (radius * cosv(theta));
		
vec_set(temp,centrex); 
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp); // now MY looks at YOU
vec_set(camera.x,my.x);
}
wait(1);
}
}


This doesn't do exactly what you wanted, but when you hold the right-mouse button the camera will orbit a central point.

1) Change centerx and centery to get a different pivot point.
2) Increase radius to get a wider orbit.
3) Change the 1 in theta=1*time_step to speed up or slow down the camera.

If you wanted to orbit around an entity or a specific object, you can set the vector to them like this...

vec_set(temp,weapon.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp);

weapon is a pointer to an entity, make sure you have created pointers properly before using this.

Anyway, it should work, i've tested it.

Last edited by DJBMASTER; 08/03/08 02:19.
Re: Help me convert this simple camera code block? [Re: DJBMASTER] #219530
08/03/08 02:38
08/03/08 02:38
Joined: Feb 2002
Posts: 288
California, USA
J
jaknine Offline OP
Member
jaknine  Offline OP
Member
J

Joined: Feb 2002
Posts: 288
California, USA
Ah, thank you for that. Your code works but I realize I didn't describe my issue as well as I should have. I need for the user to be able to control the orbit with the mouse. In other words, as they move the mouse right, it will orbit towards the right, and same for the left and up and down. Right now the camera orbits around its own center when the user moves the mouse. I just need the axis it's rotating around to be at a distance.

Thanks for your code though. Perhaps I can use it in some way towards what it is I'm after.

Re: Help me convert this simple camera code block? [Re: jaknine] #219531
08/03/08 03:13
08/03/08 03:13
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
lol, should be fun incorporating it directly into a mickey mouse.x situation =)

this i haven't tested so if i'm missing a bracket just stick it in...

Code:
function orbitMe(ent){
	me = ent;

	var panTurn, 0; var tiltTurn, 0;
	var orbitDist, 100;
	while(mouse_right){
		panTurn += mickey.x;
		tiltTurn += mickey.y;

		camera.x = my.x + (orbitDist * sin(180+ang(panTurn)));
		camera.y = my.y + (orbitDist * cos(180+ang(panTurn)));

		camera.z = my.x + (orbitDist * sin(180+tiltTurn));

		vec_set(temp,my.x);		// face the player
		vec_sub(temp,camera.x);
		vec_to_angle(temp,temp);
		vec_set(camera.pan,vector(temp.pan,temp.tilt,0));
		wait(1);
	}
}


Hope this helps, and hope it works! =)

Re: Help me convert this simple camera code block? [Re: MrGuest] #219631
08/03/08 18:15
08/03/08 18:15
Joined: Feb 2002
Posts: 288
California, USA
J
jaknine Offline OP
Member
jaknine  Offline OP
Member
J

Joined: Feb 2002
Posts: 288
California, USA
Thanks again for the help. When it comes to the camera stuff I'm not too proficient. Like I say, I'm using the cameraFree01.wdl template script for the camera and I just need something that will take the existing code in that script and make it so the camera can orbit around an arbitrary point. The script is so long and all the variables already set. Changing variables around in order to get a piece of code working doesn't really work in this case for me asI'm not really even sure what the camera is doing in the first place. I wrote in the right mouse button code just so I could use the mouse to control pan and tilt, but that's as far as my skills in modifying this code go.

Truly what I need is just a simple camera code where it can be controlled by the WASD keys just like the free camera, but instead rotating on its own axis for pan and tilt, it orbits around the current center of the view by using the right mouse button to control the rotation (move left and it orbits to the left, move right, and it does the opposite, etc.). I've looked all over for simple code that does this but I can't seem to find any, which is why I'm trying to modify the existing cameraFree code. If anyone knows of something I'm missing then please by all means point me in the right direction. I did find some code here in the forum that seems to be what I need, but I can't get it working for some reason, no matter how I try it.

Re: Help me convert this simple camera code block? [Re: jaknine] #219648
08/03/08 19:33
08/03/08 19:33
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
hey again,

do you have an algorithm written for what exactly you're trying to do?

depening on it's complexity i could write it for you but i want to make sure i don't need to keep adapting it smile

----------

Quote:
Truly what I need is just a simple camera code where it can be controlled by the WASD keys just like the free camera, but instead rotating on its own axis for pan and tilt, it orbits around the current center of the view by using the right mouse button to control the rotation (move left and it orbits to the left, move right, and it does the opposite, etc.). I've looked all over for simple code that does this but I can't seem to find any, which is why I'm trying to modify the existing cameraFree code. If anyone knows of something I'm missing then please by all means point me in the right direction. I did find some code here in the forum that seems to be what I need, but I can't get it working for some reason, no matter how I try it.

My projects just come to a grinding halt so i'll add the requirements smile

from what i've read, here's what you want
W = move camera forward,
S = move camera backward,
A = move camera left,
D = move camera right,

mickey.x = pan camera around a world vector, or entity
mickey.y = tilt camera around a world vector, or entity
mickey.z = zoom in and out (not requested but would be good)

questions...
can there be an entity selected?
if there is an entity selected, will 'A' move left from it's position, left from the world position, or rotate left around the selected entity?

if there is no entity selected, will 'A' move left from it's position, left from the world position, or rotate left around the centre point on screen

'D' see 'A' move right

if there is an entity selected and the camera is higher than the entity, or central world space. Will 'W' move the camera go above this point staying at it's same .z coordinates, or move directly towards the entity or space? (zoom in)

'S' see 'W' move backwards (zoom out)

can the camera go through terrain?

if the camera is centred on an entity and the entity moves, will it follow that entity, face that entity, both or neither?

is the orbit distance fixed at all times or can it be increased/decreased?

if a new entity / world point is selected, will the camera move directly to it (teleport) or move there accelerating and decelerating, or move there at a constant speed, or not move at all?

just a few things you should think about and what kind of game are you making, might give me some insight smile

Hope this helps!

Last edited by MrGuest; 08/04/08 02:33. Reason: Specified Requirements

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1