|
Re: Camera turn around player
[Re: Trooper119]
#222298
08/18/08 19:28
08/18/08 19:28
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
just some simple things to try... 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 then where you apply the view potision, change the 50 to height vec_set(-180, 0, height); oh and obviously declare your height var as 50 at the start with too then have it look back at the player 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
|
|
|
Re: Camera turn around player
[Re: Trooper119]
#224238
08/29/08 09:25
08/29/08 09:25
|
Joined: Aug 2008
Posts: 61
Neurosys
Junior Member
|
Junior Member
Joined: Aug 2008
Posts: 61
|
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:
//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!");
}
|
|
|
Re: Camera turn around player
[Re: Neurosys]
#224242
08/29/08 09:48
08/29/08 09:48
|
Joined: Nov 2007
Posts: 1,143 United Kingdom
DJBMASTER
Serious User
|
Serious User
Joined: Nov 2007
Posts: 1,143
United Kingdom
|
This was the code i PM'd SurudoiRyu, using a modified version of my orbit contribution...
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);
}
Last edited by DJBMASTER; 08/29/08 09:50.
|
|
|
Re: Camera turn around player
[Re: DJBMASTER]
#224416
08/29/08 23:32
08/29/08 23:32
|
Joined: Aug 2008
Posts: 61
Neurosys
Junior Member
|
Junior Member
Joined: Aug 2008
Posts: 61
|
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.
#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
|
|
|
|