Camera turn around player

Posted By: SurudoiRyu

Camera turn around player - 08/14/08 08:48

Hi there,

Im willing to rotate my mouse around my player entity.
It is a 3rd person cam and mouse rotate 360 degrees around the player.

This can be done by right mouse button.

I got this so far now i can change it allready with the mouse but i can not get it so that i rotate around the player so i can face the entity's front.

Code:
function Camera_Action()
{
	var mouseR_onhold = 0;
	
	camera.tilt = -15;
	while(1)
	{
		vec_set(camera.x,vector(-180,0,50));
		vec_rotate(camera.x,my.pan);
		vec_add(camera.x,my.x);
		camera.pan = my.pan;
		if(mouse_right) // right Mousebutton pressed?
		{
			mouseR_onhold = 1;
			mouse_map = NULL;
			camera.pan -= mouse_force.x;
			my.pan -= mouse_force.x;
			camera.tilt += mouse_force.y;
		}
		
		if(!mouse_right && mouseR_onhold == 1)
		{
			mouse_map = arrow;
		}

		wait(1);
	}
	
}


Hope someone can help me change my code so that it becomes what i want smile

Greetzzz, and thnx allready
Posted By: DJBMASTER

Re: Camera turn around player - 08/14/08 09:51

I posted this snipper a while ago. It revolves the camera around an entity whilst looking at it.

You might need to tweak it a bit, but the basic structure is there...

http://www.coniserver.net/ubb7/ubbthread...9528#Post219528
Posted By: SurudoiRyu

Re: Camera turn around player - 08/14/08 21:17

Ok thnx smile

I tryed to play a bit with the code
But it became some real mess >.<
it goes around the player start pos now. but doesn't walk with the char.
It goes one side very quick.
It doesnt work as it should be.
Maybe because i just use camera. and not an entity.

Tries diffrent things but all just sucked.
Even de start pos. got screwed a bit.

Code:
function Camera_Action()
{
	var mouseR_onhold = 0;
	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
	var temp;

	camera.tilt = -15;
	while(1)
	{
		//vec_set(camera.x,vector(-180,0,50));
		vec_rotate(camera.x,my.pan);
		//vec_add(camera.x,my.x);
		camera.pan = my.pan;
		if(mouse_right) // right Mousebutton pressed?
		{
			mouseR_onhold = 1;
			mouse_map = NULL;
			camera.pan -= mouse_force.x +(radius * sin(theta));
			my.pan -= mouse_force.x;
			camera.tilt += mouse_force.y;
			
			
			theta+=1*time_step;
			//camera.x = centerx +(radius * sin(theta));
			//camera.y = centery + (radius * cos(theta));
//			vec_set(temp,my.x); 
//			vec_sub(temp,my.x);
//			vec_to_angle(my.pan,temp); // now MY looks at YOU
//			vec_set(camera.x,my.x - 15);
		}
		
		if(!mouse_right && mouseR_onhold == 1)
		{
			mouse_map = arrow;
		}

		wait(1);
	}
	
}


plz can u help me fix it smile

Thnx allready,
Posted By: SurudoiRyu

Re: Camera turn around player - 08/18/08 13:03

Anyone else can help me with it ?

Greetzzz,
Posted By: Trooper119

Re: Camera turn around player - 08/18/08 16:23

Well first I would define your mouse correctly what I would do (there are several ways to do it) is this define the mouse key map at the top

#define mouseRight 281

and replace if(mouse_right) with
if(key_pressed(mouseRight))
//This assumes your using lite-C

Increase your sensitivity of the mouse by like 5 or 10 or so (just add * 5 ect. after mouse_force.x ect.) so you can actually see it move.

It looks like you took his code, then massacred it, instead of just taking out the automatic movement and replacing it with mouse_force movement. I'll edit with what I'm talking about below.
Posted By: Trooper119

Re: Camera turn around player - 08/18/08 16:44

Assuming this code works as described, all you need to do is assign the angle according to mouse_force (and a modifier). Pretty much ignore my previous post, I got confused and started babbling, that was my fault.

Your Code [editted]:
Code:
function Camera_Action()
{
	var mouseR_onhold = 0;  //Not needed
        var centerx = 0; // centre of circle (x)
        var centery = 0;  // centre of circle (y)
        var centerz = 0;  //Change these to point to your player
        var radius = 400; // radius of circle
        var thetaX = 0; // degrees done around the circle
        var thetaZ = 0;
	
        my = player = camera;        //Important, he is using a my pointer, since for 
                                     //whatever reason your not making the camera 
                                     //an action, you need to get the my pointer point to the camera somehow
        camera.genius = camera;      //This you could probably get rid of, depends on what you want
	while(1)
	{
		camera.pan = my.pan;
		camera.tilt = clamp(camera.tilt,-70,70); //Change tilt to what you want or get rid of this
		if(mouse_right) // right Mousebutton pressed?
		{
			mouseR_onhold = 1;  //Not needed
			mouse_map = NULL;   //It would be nice if you checked if mouse_map wasn't NULL before-hand
			
			thetaX+=mouse_force.x * 5;  //I'd make a variable for 5 and tweak it to what 
                                                    //you want the sensitivity to be, same with next one
			thetaZ+=mouse_force.y * 5;
			camera.x = centerx + (radius * sinv(thetaX));
			camera.y = centery + (radius * cosv(thetaX));
			camera.z = centerz + (radius * cosv(thetaZ)); //might be sinv() or tanv(), tweak till you like the result
		
			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);
		}

		//Your previous function was round-about, I'd do this
		if(mouse_map == NULL)
		{
			mouse_map = arrow;
		}

		wait(1);
	}
	
}

Posted By: SurudoiRyu

Re: Camera turn around player - 08/18/08 17:24

Hi thnx for your reply,

I had sort of the same in first place did the same as it does now.
It places the camera in the center coords of the player and looks up.
and i cant rotate it.
aswell the camera isnt attached to the player anymore.


code that i use atm:
Code:
function Camera_Action()
{
		var mouseR_onhold = 0;
		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
		var temp;
		//
	
		camera.tilt = -15;
		while(1)
		{
				vec_set(camera.x,vector(-180,0,50));
				vec_rotate(camera.x,my.pan);
				vec_add(camera.x,my.x);
				camera.pan = my.pan;
				if(mouse_right) // right Mousebutton pressed?
				{
						mouse_map = NULL;
						camera.pan -= mouse_force.x;
						my.pan -= mouse_force.x;
						camera.tilt += mouse_force.y;
				}
				
				if(!mouse_right && mouseR_onhold == 1)
				{
						mouse_map = arrow;
				}
		
				wait(1);
		}
		
}


i like to use this but then rotate like the most online RPG games.
Now it rotates with the player aswell, but i want to rotate around the player so i can see its face or watch my back.

hope u can help me,

Greetzzzz,
Posted By: Trooper119

Re: Camera turn around player - 08/18/08 18:10

In order to keep the player and camera together, adjust the center variables so they point to the player's x and y variables.

What does my code do, bug up, or does it run? Let me know so I can help. Also what does your code currently do?
Posted By: SurudoiRyu

Re: Camera turn around player - 08/18/08 18:38

Well my code does:

Place the camera behind the player.
Keep the same panning.
Rotate the camera when i rightclick the mouse button and rotates the direction u go with your mouse.

the code u passed does:
place the camera on the plyers x y z so im inside the player.
doesn't keep same panning.
Doesnt rotate the camera according the mouse force
And looks up to the sky.

So my code is almost there the only thing is the tilting and panning.

Panning u can compare to the camera of World of warcraft im trying to get something like that.

greetzzz. hope u understand if not i will make an example.
Posted By: Trooper119

Re: Camera turn around player - 08/18/08 18:42

I understand your post, did you try DGBMASTER's code as an action (you can't control it, but did you test to see if it works?)

EDIT: I changed the code, it shouldn't help much since not much has changed, I'm thinking if you take a hard look at all of the contributions so far you should be able to think of something
Posted By: MrGuest

Re: Camera turn around player - 08/18/08 19:28

just some simple things to try... smirk

camera.tilt += mouse_force.y; this won't' make the camera look at the player, but only change the camera tilt,

change this to at the least
Code:
 height += mouse_force.y


then where you apply the view potision, change the 50 to height
Code:
 vec_set(-180, 0, height);


oh and obviously declare your height var as 50 at the start with too
Code:
var height = 50


then have it look back at the player
Code:
 vec_set(temp,your.x); 
  vec_sub(temp,my.x);
  vec_to_angle(my.pan,temp);


this has a good chance of not working at all, but the basic principals are there what you need

you may also want to add so when the mouse_force.y increase, the camera also gets closer

Hope this helps
at least a little smile
Posted By: Neurosys

Re: Camera turn around player - 08/29/08 09:25

I have a perfect lite-c working version but im trying to convert it to c++ to work in my C++ app cuz im not using lite-c anymore. Anyone wanting lite-c could try this is works pretty well. This is my lite-c player_code action. (it uses some globals and has a bit of init so I'll post the whole code:

Code:
//include <default.fx>;
//include <mtlFX.wdl>;
//include <default.fx>;
//include <mtlFX.wdl>;
#include <acknex.h>
#include <default.c>
#include "mtlFX.c"
#define PRAGMA_PATH "%EXE_DIR%\code";
#define PRAGMA_PATH "images";
#define PRAGMA_PATH "terrains";
#define PRAGMA_PATH "levels";
#define PRAGMA_PATH "models";

////////////////////////////////////////////////////////////////////
#define xmax 1680
#define ymax 1050
#define fscreen 1
 
BMAP* nneglogo = "nnegamingLOGO.bmp";
BMAP* dhlogo = "dementia_hillsLOGO.bmp";
BMAP* dhmenustart = "dhmenustart.bmp";
BMAP* dhmenustartover = "dhmenustart_over.bmp";
BMAP* mcursor = "brokenarrow.pcx";
var camh;
var distx,disty,distz,distxy;
var tempforcex,tempforcey;
var tempforcex2,tempforcey2;

ENTITY* skycube;

PANEL* splash1 = {
	
	pos_x=0;
	pos_y=0;
	layer=2;
	bmap = nneglogo;
	flags = VISIBLE;	
}


PANEL* splash2 = {
	pos_x=0;
	pos_y=0;
	layer=1;
	bmap = dhlogo;
	flags = VISIBLE;	
}

PANEL* mainmenu = {
	pos_x=0;
	pos_y=350;
	layer=3;
	button(0,0,dhmenustart,dhmenustart,dhmenustartover,startworld,NULL,NULL);
	flags = OVERLAY;
}

PANEL* deb = {
	pos_x = 200;
	pos_y = 300;
	digits(0,0,"CamHeight: %.1f",*,1,camh);
	digits(0,12,"Camera.Tilt: %.1f",*,1,camera.tilt);
	digits(0,24,"Mouse Force X: %.1f",*,1,mouse_force.x);
	digits(0,36,"Mouse Force y: %.1f",*,1,mouse_force.y);
	digits(0,48,"Distance X : %.1f",*,1,distx);
	digits(0,60,"Distance Y : %.1f",*,1,disty);
	digits(0,72,"Distance Z : %.1f",*,1,distz);
	digits(0,84,"Distance XY : %.1f",*,1,distxy);
	digits(0,96,"TempForce X : %.1f",*,1,tempforcex);
	digits(0,108,"TempForce Y : %.1f",*,1,tempforcey);
	digits(0,120,"Player.Pan : %.1f",*,1,player.pan);
	digits(0,132,"Player.Tilt : %.1f",*,1,player.tilt);
	digits(0,144,"Camera.Arc : %.1f",*,1,camera.arc);
	flags = OVERLAY | VISIBLE;
}

function startworld(){

	//Start Loading Shit
	camera.arc = 30; //Zoom Factor
	while(player == NULL) { wait(1); }
   vec_set(camera.x,vector(-180,0,70));
	vec_rotate(camera.x,player.pan);
	vec_add(camera.x,player.x);
	camera.pan = player.pan;
	camera.tilt = -10;
	distx = player.x - camera.x;
	disty = player.y - camera.y;
	distz = player.z - camera.z;
	toggle(mainmenu,VISIBLE);
	toggle(splash1,VISIBLE);
	toggle(splash2,VISIBLE);
	mouse_mode=1;
}

action players_code() { 
		 tempforcex = 1;tempforcey = 1;
		 var anim_percentage; // animation percentage
       VECTOR movement_speed; // player's movement speed
       VECTOR tempcamera;
       var distance_to_ground; // the distance between player's origin and the ground
       var camdist = 230;
       var camheight = 145;
       VECTOR temp;
       VECTOR temp2;
       player = my; // I'm the player
		 while (1) {
		 		
		 		//Calculate Mouse Control
				if ( mouse_left ) {
					if (mouse_force.x != 0 && !mouse_right) {
						tempforcex+=mouse_force.x * 9 * time_step;
					}
					if (mouse_force.y != 0) {
						tempforcey+=mouse_force.y * 6 * time_step;
					}	
				} 
				if ( mouse_right ) {
					my.pan -= 6 * (mouse_force.x) * time_step; // rotate the player
				}
				//depending upon mouse force change cam offset
				if (abs(tempforcex) >= 0 && abs(tempforcex) < 90) {
					camera.x=player.x - camdist * cos(player.pan + tempforcex);
					camera.y=player.y - camdist * sin(player.pan + tempforcex);
				} else if ( abs(tempforcex) > 90 && abs(tempforcex) < 180) {
					camera.x=player.x - camdist * -cos(180-(player.pan + tempforcex));
					camera.y=player.y - camdist * sin(180-(player.pan + tempforcex));
					
				} else if ( abs(tempforcex) > 180 && abs(tempforcex) < 270) {
					camera.x=player.x - camdist * -cos(180-(player.pan + tempforcex));
					camera.y=player.y - camdist * sin(180-(player.pan + tempforcex));
					
				} else if (abs(tempforcex) > 270 && abs(tempforcex) < 360) {
					camera.x=player.x - camdist * cos(player.pan + tempforcex);
					camera.y=player.y - camdist * sin(player.pan + tempforcex);
				} else if ( tempforcex < -360 ) { 
					tempforcex = tempforcex + 360;
				} else if ( tempforcex > 360 ) { 
					tempforcex = tempforcex - 360;
				}
				if (tempforcey < 0 && tempforcey > -90) {
					camera.z=player.z - camheight * sin(player.tilt + tempforcey);
				} else if (tempforcey > 0  && tempforcey < 90) {
					camera.z=player.z - camheight * sin(180 - (player.tilt + tempforcey));
				} else if ( tempforcey >= 90 ) {
					tempforcey = 89;
				} else if ( tempforcey <= -90 ) {
					tempforcey = -89;	
				}
				
				if (!mouse_left) { 
					if (tempforcex < 1) {
						tempforcex++;
					} else if (tempforcex > 1) {
						tempforcex--; 
					}
					
					if (tempforcey < -22) {
						tempforcey++;
					} else if (tempforcey > -22) {
						tempforcey--; 
					}
					if (abs(tempforcex) > 0 && abs(tempforcex) < 1){
						tempforcex=0;
					}
					if (tempforcey > -22 && tempforcey < -21){
						tempforcey=-22;
					}
					if (tempforcey < -22 && tempforcey > -23 ){
						tempforcey=-22;
					}
				}
				
				camh = camheight;
				
				//LOOK AT PLAYER
				vec_set(temp2.x,player.x);
				temp2.z+=20;
				vec_sub(temp2.x,camera.x);
				vec_to_angle(camera.pan,temp2); 
				
				camera.arc+=mickey.z * 0.01;
				my.pan += 6 * (key_a - key_d) * time_step; // rotate the player using the "A" and "D" keys
         	vec_set (temp.x, my.x); // copy player's position to temp
         	temp.z -= 5000; // set temp.z 5000 quants below player's origin
         	distance_to_ground = c_trace (my.x, temp.x, IGNORE_ME | USE_BOX);
         	if ( mouse_left && mouse_right ){
         		movement_speed.x = 10 * 1 * time_step; // move the player using "W" and "S"	
				} else {
					movement_speed.x = 10 * (key_w - key_s) * time_step; // move the player using "W" and "S"	
				}
         	movement_speed.y = 0; // don't move sideways
           	movement_speed.z = - (distance_to_ground - 20); // 17 = experimental value
         	movement_speed.z = maxv(-35 * time_step, movement_speed.z); // 35 = falling speed
         	c_move (my, movement_speed.x, nullvector, GLIDE); // move the player
  				if ((key_w == OFF) && (key_s == OFF)) {
  					if(mouse_left && mouse_right){
  						ent_animate(my, "Walka", anim_percentage, ANM_CYCLE); // play the "walk" animation	
  					} else {
  						ent_animate(my, "Standa", anim_percentage, ANM_CYCLE); // play the "stand" animation
  					}					
   	      }	else { 
      	      ent_animate(my, "Walka", anim_percentage, ANM_CYCLE); // play the "walk" animation
         	}
         	anim_percentage += 8 * time_step; // 5 = animation speed
         	wait (1);       
       	}
}




function main()
{
	video_set(xmax,ymax,32,fscreen);
	screen_color.blue=0;
	screen_color.red=0;
	screen_color.green=0;
	splash1.size_x = xmax;
	splash1.size_y = ymax;
	var xm = (int)xmax;
	var ym = (int)ymax;
	splash1.scale_x = xm / 1024;
   splash1.scale_y = ym / 768;
	splash2.size_x = xmax;
	splash2.size_y = ymax;
	splash2.scale_x = xm / 1024;
   splash2.scale_y = ym / 768;
	//wait(2);
	//wait(-8);
	splash1.bmap=dhlogo;
	while(splash1.pos_x <= 125) {
		splash1.pos_x += 3 * time_step;
		//wait(1);
	}
	toggle(mainmenu,VISIBLE);
	level_load("dh.wmb");
	skycube = ent_createlayer("Sky_2+6.tga", SKY | CUBE | VISIBLE, 0);
	mouse_map= mcursor;
	mouse_mode = 2;
	//delay the inevitable
	while(key_pressed(key_for_str("q"))  == 0) {
		//Process Mouse
		mouse_pos.x = mouse_cursor.x;
      mouse_pos.y = mouse_cursor.y;
      
      if (player != NULL) {

		}
		//next cycle      
		wait(1);
	}
	sys_exit("p00!");
}

Posted By: DJBMASTER

Re: Camera turn around player - 08/29/08 09:48

This was the code i PM'd SurudoiRyu, using a modified version of my orbit contribution...

Code:
VECTOR* move_vec[3]; // needed vector to move player
VECTOR* temp[3]; // temporary vector to perform angle calculations
	
action move_me() // attach action to player in WED
{

player = me;
float theta = 0.0;

while (1)
{
move_vec[0] = (key_w - key_s)*5 *time_step; // move player on x axis
move_vec[1] = (key_a - key_d) *5 *time_step; // move player on y axis
c_move(me,move_vec,nullvector,GLIDE); // function to actually move player, with GLIDE collision
		
if(mouse_left==1)
  {
   theta+= 0.08 * time_step;
   vec_set(camera.x,vector(me.x +(300 * sin(theta)),me.y +(300 * cos(theta)),camera.z)); // actual rotation code, (300 is the radius)
   vec_set(temp,me.x); 
   vec_sub(temp,camera.x);
   vec_to_angle(camera.pan,temp); // camera always face the player
  }
		
if(mouse_right==1)
  {
   theta-= 0.08 * time_step;
   vec_set(camera.x,vector(me.x +(300 * sin(theta)),me.y +(300 * cos(theta)),camera.z)); // actual rotation code, (300 is the radius)
   vec_set(temp,me.x); 
   vec_sub(temp,camera.x);
   vec_to_angle(camera.pan,temp); // camera always face the player
  }
		
if(mouse_left==0 && mouse_right==0)
{
		
camera.x = me.x - 300;
camera.y = me.y;
camera.z = me.z+300;
				
vec_set(temp,me.x); 
vec_sub(temp,camera.x);
vec_to_angle(camera.pan,temp);
		
}
wait (1);
}

Posted By: Neurosys

Re: Camera turn around player - 08/29/08 23:32

ok... Got it. Here is my total conversion to C++ and implementation of 100% working, easily modded to preference, Player Orbiting Camera And Movement controls.

Very WoW-like camera. hold left mouse = 360 x-axis rotation and -90 to 10 z axis rotation (up n down). right mouse only = pans player AND camera via mouse_force.x.
right and left mouse button = free camera again and moving forward and mouse_force.x controls pan.
w,s = forward,backward
a,d = turn left,turn right
mousewheel scroll = camera zoom distance (increment/decrement camera distance from player)

I think its neato.

Code:
#define WIN32_LEAN_AND_MEAN		
#include <windows.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include "adll.h" // Include the engine data types, variables, and functions
#include "mtlFX.h"


//Prototypes
var rad2deg(float radians);
float deg2rad(var degrees);
var abz(var val);
//Globals

ENTITY* terrain1;
ENTITY* playermodel;
ENTITY* skycube;
BMAP* mcursor;
TEXT* tDebug;
PANEL* pDebug;




var abz(var val) {
	var retval;
	if (val >= _VAR(0)) { return val; }
	retval = _VAR(0) - val;
	return retval;
}


float deg2rad(var degrees) {
    float deg2rad = (float)(degrees / 57.29578);
	return deg2rad;
}



var rad2deg(float radians) {
    var rad2deg = _VAR(radians * 57.29578);
	return rad2deg;
}


//Function Definitions

void player_code() {
	ENTITY *my;
	my =(ENTITY *)ev->me;
	ev->player = my; // I'm the player
 	VECTOR* move_vec =_vec(0,0,0);
	VECTOR* temp_vec =_vec(0,0,0);
	var distance_to_ground;

	//Calculate Movement
	move_vec->x = (v(key_w) - v(key_s))* 0.015 * v(time_step); // move player on x axis
	move_vec->y = 0;//(v(key_a) - v(key_d)) * 0.025 *v(time_step); // move player on y axis
	my->pan-= (v(key_d) - v(key_a)) * 0.02 * v(time_step);

	//Read Forces
	if (v(mouse_left)) { 
		my->skill[0] += (v(mouse_force).x * 0.02 * v(time_step));
		my->skill[6] += (v(mouse_force).y * 0.02 * v(time_step));
		if ( my->skill[0] < _VAR(-360) ) { my->skill[0] += _VAR(360); }
		if ( my->skill[0] > _VAR(360) ) { my->skill[0] -= _VAR(360); }
		if ( my->skill[6] <= _VAR(-89) ) { my->skill[6] = _VAR(-90); }
		if ( my->skill[6] >= _VAR(9) ) { my->skill[6] = _VAR(10); }
	} else {
		if (my->skill[0] < _VAR(0)) { my->skill[0]+= 3 * v(time_step); }
		if (my->skill[0] > _VAR(0)) { my->skill[0]-= 3 * v(time_step); }
		if (my->skill[0] > _VAR(-1) && my->skill[0] < _VAR(1) ) { my->skill[0]=0; }
		if (my->skill[6] < _VAR(-61)) { my->skill[6]+= 3 * v(time_step); }
		if (my->skill[6] > _VAR(-59)) { my->skill[6]-= 3 * v(time_step); }
		if (my->skill[6] < _VAR(-61) && my->skill[6] > _VAR(-59) ) { my->skill[6]=-60; }
	}
	if (v(mouse_right)) { 
		my->pan-= v(mouse_force).x * 0.02 * v(time_step); 
		if( v(mouse_left) ){
			move_vec->x = _VAR(2) * 0.015 * v(time_step); // move player on x axis
		}
	}
	my->skill[3] -=v(mickey).z*0.0001;  //Calc Zoom Distance

	//Calculate Z Axis Gravity And Move Player
	vec_set(temp_vec,(VECTOR*)&my->x);
	temp_vec->z -= _VAR(5000); //Set to 5000 below player
	distance_to_ground = c_trace((VECTOR*)&my->x,temp_vec, _VAR(IGNORE_ME | USE_BOX));
	if (distance_to_ground != 0) {
		move_vec->z = -(distance_to_ground - _VAR(25));
		move_vec->z = maxv(_VAR(-35) * v(time_step),move_vec->z);
	}
	c_move(me,move_vec,_vec(0,0,0),GLIDE); // function to actually move player, with GLIDE collision
	
	//Animate As Needed
	if (v(key_w) == OFF && v(key_s) == OFF) {
		if(v(mouse_left) && v(mouse_right)){
  			ent_animate(my, "Walka", my->skill[5], ANM_CYCLE);
  		} else {
  			ent_animate(my, "Standa", my->skill[5], ANM_CYCLE);
  		}
	} else {
		ent_animate(my, "Walka", my->skill[5], ANM_CYCLE);
	}
	my->skill[5] += 6 * v(time_step);	
	my->skill[5] = my->skill[5]%_VAR(100);
	
	//Move The Camera
	if (abz(my->skill[0]) >= _VAR(0) && abz(my->skill[0]) < _VAR(90)) {
		vec_set((VECTOR*)&v(camera).x,vector(my->x -(my->skill[3] * cosv(my->pan + my->skill[0])),my->y -(my->skill[3] * sinv(my->pan + my->skill[0])),my->z+_VAR(my->skill[4])));
	} else if (abz(my->skill[0]) > _VAR(90) && abz(my->skill[0]) < _VAR(180)) {
		vec_set((VECTOR*)&v(camera).x,vector(my->x -(my->skill[3] * -cosv(_VAR(180)-(my->pan + my->skill[0]))),my->y -(my->skill[3] * sinv(_VAR(180)-(my->pan + my->skill[0]))),my->z+_VAR(my->skill[4])));
	} else if (abz(my->skill[0]) > _VAR(180) && abz(my->skill[0]) < _VAR(270)) {
		vec_set((VECTOR*)&v(camera).x,vector(my->x -(my->skill[3] * -cosv(_VAR(180)-(my->pan + my->skill[0]))),my->y -(my->skill[3] * sinv(_VAR(180)-(my->pan + my->skill[0]))),my->z+_VAR(my->skill[4])));
	} else if (abz(my->skill[0]) > _VAR(270) && abz(my->skill[0]) < _VAR(360)) {
		vec_set((VECTOR*)&v(camera).x,vector(my->x -(my->skill[3] * cosv(my->pan + my->skill[0])),my->y -(my->skill[3] * sinv(my->pan + my->skill[0])),my->z+_VAR(my->skill[4])));		
	}
	
	if (my->skill[6] < _VAR(0) && my->skill[6] > _VAR(-90)) {
		v(camera).z=my->z - my->skill[4] * sinv(my->tilt + my->skill[6]);
	} else if (my->skill[6] > _VAR(0) && my->skill[6] < _VAR(90)) {
		v(camera).z=my->z - my->skill[4] * sinv(_VAR(180)-(my->tilt + my->skill[6]));
	} 
	//Keep Eye On Player After Moving
	vec_set(temp_vec,(VECTOR*)&my->x); 
	vec_sub(temp_vec,(VECTOR*)&v(camera).x);
	temp_vec->z+=40;  
	vec_to_angle((ANGLE*)&v(camera).pan,temp_vec);
	
}

//WINMAIN!!!OMFGZ!!!
// application instance handle, // always zero // application command line // window flags
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd) {
	ev = engine_open(NULL);
	if (!ev) return 1;	// acknex.dll not found
		
	//Add Content Folders Paths
	add_folder("terrains");
	add_folder("images");
	add_folder("models");
	add_folder("code");
	level_load("dh.wmb");
	engine_frame();
	
	//Initialize The Graphics Environment
	video_set(_VAR(1280),_VAR(1024),_VAR(32),_VAR(0));
	
	//Setup The Worldscape
	terrain1 = ent_for_name("terrain0x0");
	playermodel = ent_for_name("playermodel");  //These two are placed in the level by wed. This will change. Maybe. I hate wed.
	
	//Ready The Player
	playermodel->x=0;
	playermodel->y=0;
	playermodel->z=_VAR(550);
	//Init player skills
	playermodel->skill[0] = 0; //thetax
	playermodel->skill[1] = 0; //tempforcex
	playermodel->skill[2] = 0; //tempforcey
	playermodel->skill[3] = 180; //Camera Distance
	playermodel->skill[4] = 70; //Camera Height
	playermodel->skill[5] = 0; //Player Animation Percent
	playermodel->skill[6] = -60; //thetay
	playermodel->event=(EVENT)player_code;
	playermodel->emask |= DYNAMIC;
	playermodel->emask |= ENABLE_FRAME;
	
	//Wait for the player to materialize
	while(ev->player == NULL) { engine_frame(); }

	//Move Camera to Player And Look at the fucker
	vec_set((VECTOR*)&v(camera).x,_vec(-180,0,70));
	vec_rotate((VECTOR*)&v(camera).x,(ANGLE*)&v(player).pan);
	vec_add((VECTOR*)&v(camera).x,(VECTOR*)&v(player).x);
	v(camera).pan = v(player).pan;

	//Stall For A Frame (add more if ur compy sux0rz)
	engine_frame();
	
	//Make a Pretty Sky
	skycube = (ENTITY *)ent_createlayer("skycube+6.tga", _VAR(SKY | CUBE | VISIBLE), _VAR(0));

	//Bring Up The Mouse
	mcursor = bmap_create("brokenarrow.pcx");
	ev->mouse_map = mcursor;
	v(mouse_mode)=2;

	//GUI time
	tDebug = txt_create(_VAR(5),_VAR(1));
	tDebug->pos_x = _VAR(200);
	tDebug->pos_y = _VAR(200);
	tDebug->flags |= VISIBLE;
	pDebug = pan_create("digits(0,10,\"TEMPFORCEX: \",*,0,NULL); \
						digits(70,10,4,*,1,player.skill2); \
						digits(0,20,\"TEMPFORCEY: \",*,0,NULL);\
						digits(70,20,4,*,1,player.skill3); \
						digits(140,10,\"THETA X: \",*,0,NULL); \
						digits(230,10,4,*,1,player.skill1); \
						digits(310,10,\"THETA Y: \",*,0,NULL); \
						digits(410,10,4,*,1,player.skill7); \
						digits(140,20,\"Camera Distance: \",*,0,NULL); \
						digits(230,20,4,*,1,player.skill4); \
						digits(140,30,\"Camera Height: \",*,0,NULL); \
						digits(230,30,4,*,1,player.skill5); \
						digits(0,40,\"PLAYER X: \",*,0,NULL);\
						digits(70,40,4,*,1,player.x); \
						digits(0,50,\"PLAYER Y: \",*,0,NULL);\
						digits(70,50,4,*,1,player.y); \
						digits(0,60,\"PLAYER Z: \",*,0,NULL);\
						digits(70,60,4,*,1,player.z); \
						digits(140,40,\"Camera X: \",*,0,NULL);\
						digits(230,40,4,*,1,camera.x); \
						digits(140,50,\"Camera Y: \",*,0,NULL);\
						digits(230,50,4,*,1,camera.y); \
						digits(140,60,\"Camera Z: \",*,0,NULL);\
						digits(230,60,4,*,1,camera.z); \
						digits(140,120,\"AnimPercent: \",*,0,NULL);\
						digits(230,120,4,*,1,player.skill6); \
						digits(0,90,\"MOUSELEFT: \",*,0,NULL);\
						digits(70,90,4,*,1,mouse_left); \
						digits(0,100,\"MOUSERIGHT: \",*,0,NULL);\
						digits(70,100,4,*,1,mouse_right);",_VAR(1));
	pDebug->flags |= VISIBLE;
	pDebug->pos_x = _VAR(600);
	pDebug->pos_y = _VAR(200);

	//Main Loop
	while (engine_frame()) {
		//Main Loop
		v(mouse_pos).x = v(mouse_cursor).x;
		v(mouse_pos).y = v(mouse_cursor).y;
		if (v(key_esc)) { sys_exit(""); }
	}//Main Loop
	engine_close();
	return 0;
}



Your Humble Servant,
Neurosys
© 2024 lite-C Forums