void view_handle_create_single_rot_handle(d3pnt *pnt,d3vct *vct,d3ang *ang,d3pnt *hand_pnt) { matrix_type mat; // rotations if (ang!=NULL) { if (ang->x!=0) { matrix_rotate_x(&mat,ang->x); matrix_vertex_multiply(&mat,&vct->x,&vct->y,&vct->z); } if (ang->y!=0) { matrix_rotate_y(&mat,ang->y); matrix_vertex_multiply(&mat,&vct->x,&vct->y,&vct->z); } if (ang->z!=0) { matrix_rotate_z(&mat,ang->z); matrix_vertex_multiply(&mat,&vct->x,&vct->y,&vct->z); } } // make point hand_pnt->x=pnt->x+(int)vct->x; hand_pnt->y=pnt->y+(int)vct->y; hand_pnt->z=pnt->z+(int)vct->z; }
void select_model_get_drag_direction(d3pnt *pnt) { float fx,fy,fz; matrix_type mat; fx=(float)pnt->x; fy=(float)pnt->y; fz=(float)pnt->z; if (state.model.ang.x!=0) { matrix_rotate_x(&mat,state.model.ang.x); matrix_vertex_multiply(&mat,&fx,&fy,&fz); } if (state.model.ang.y!=0) { matrix_rotate_y(&mat,angle_add(state.model.ang.y,180.0f)); matrix_vertex_multiply(&mat,&fx,&fy,&fz); } if (state.model.ang.z!=0) { matrix_rotate_z(&mat,state.model.ang.z); matrix_vertex_multiply(&mat,&fx,&fy,&fz); } pnt->x=(int)fx; pnt->y=(int)fy; pnt->z=(int)fz; }
void model_get_view_complex_bounding_box(model_type *model,d3pnt *pnt,d3ang *ang,float resize,int *px,int *py,int *pz) { int n,yadd,sz; float fx,fy,fz; matrix_type rot_x_mat,rot_z_mat,rot_y_mat; sz=(int)((float)(model->view_box.size.x>>1)*resize); px[0]=px[3]=px[4]=px[7]=-sz; px[1]=px[2]=px[5]=px[6]=sz; yadd=model->view_box.size.y>>1; py[4]=py[5]=py[6]=py[7]=(int)(((float)yadd)*resize)-yadd; py[0]=py[1]=py[2]=py[3]=-(int)((float)(model->view_box.size.y+yadd)*resize)-yadd; sz=(int)((float)(model->view_box.size.z>>1)*resize); pz[0]=pz[1]=pz[4]=pz[5]=-sz; pz[2]=pz[3]=pz[6]=pz[7]=sz; matrix_rotate_x(&rot_x_mat,ang->x); matrix_rotate_z(&rot_z_mat,ang->z); matrix_rotate_y(&rot_y_mat,ang->y); for (n=0;n!=8;n++) { fx=(float)px[n]; fy=(float)py[n]; fz=(float)pz[n]; matrix_vertex_multiply(&rot_x_mat,&fx,&fy,&fz); matrix_vertex_multiply(&rot_z_mat,&fx,&fy,&fz); matrix_vertex_multiply(&rot_y_mat,&fx,&fy,&fz); px[n]=((int)fx)+pnt->x; py[n]=((int)fy)+pnt->y; pz[n]=((int)fz)+pnt->z; } }
void view_draw_debug_bounding_box(d3pnt *pnt,d3ang *ang,d3pnt *size) { int n,xsz,zsz,px[8],py[8],pz[8]; float fx,fy,fz; matrix_type rot_x_mat,rot_y_mat,rot_z_mat; d3col col; // bounding box xsz=size->x>>1; zsz=size->z>>1; px[0]=px[1]=px[4]=px[5]=-xsz; px[2]=px[3]=px[6]=px[7]=xsz; py[0]=py[1]=py[2]=py[3]=-size->y; py[4]=py[5]=py[6]=py[7]=0; pz[1]=pz[2]=pz[5]=pz[6]=-zsz; pz[0]=pz[3]=pz[4]=pz[7]=zsz; matrix_rotate_x(&rot_x_mat,ang->x); matrix_rotate_z(&rot_z_mat,ang->z); matrix_rotate_y(&rot_y_mat,ang->y); for (n=0;n!=8;n++) { fx=(float)px[n]; fy=(float)py[n]; fz=(float)pz[n]; matrix_vertex_multiply(&rot_x_mat,&fx,&fy,&fz); matrix_vertex_multiply(&rot_z_mat,&fx,&fy,&fz); matrix_vertex_multiply(&rot_y_mat,&fx,&fy,&fz); px[n]=(int)fx; py[n]=(int)fy; pz[n]=(int)fz; } for (n=0;n!=8;n++) { px[n]=px[n]+pnt->x; py[n]=py[n]+pnt->y; pz[n]=pz[n]+pnt->z; } // draw box col.r=col.g=0.2f; col.b=1.0f; glLineWidth(2.0f); view_primitive_3D_line_cube(&col,1.0f,px,py,pz); glLineWidth(1.0f); }
void gl_lights_build_from_model(model_draw *draw,view_glsl_light_list_type *light_list) { int n,cx,cy,cz,sz,idx; float fx,fy,fz; d3pnt pnt,min,max; matrix_type mat; // need to move model if no rot on memmove(&pnt,&draw->pnt,sizeof(d3pnt)); if (draw->no_rot.on) { matrix_rotate_y(&mat,draw->no_rot.ang.y); fx=(float)(pnt.x-draw->no_rot.center.x); fy=(float)(pnt.y-draw->no_rot.center.y); fz=(float)(pnt.z-draw->no_rot.center.z); matrix_vertex_multiply(&mat,&fx,&fy,&fz); pnt.x=((int)fx)+draw->no_rot.center.x; pnt.y=((int)fy)+draw->no_rot.center.y; pnt.z=((int)fz)+draw->no_rot.center.z; } // get model bounds sz=draw->size.x>>1; min.x=pnt.x-sz; max.x=pnt.x+sz; sz=draw->size.z>>1; min.z=pnt.z-sz; max.z=pnt.z+sz; min.y=pnt.y-draw->size.y; max.y=pnt.y; // any rotations cx=pnt.x+draw->center.x; cy=pnt.y+draw->center.y; cz=pnt.z+draw->center.z; rotate_point(&min.x,&min.y,&min.z,cx,cy,cz,draw->rot.x,draw->rot.y,draw->rot.z); rotate_point(&max.x,&max.y,&max.z,cx,cy,cz,draw->rot.x,draw->rot.y,draw->rot.z); gl_lights_build_from_box(&pnt,&min,&max,light_list); // do any tints for (n=0;n!=max_view_lights_per_poly;n++) { idx=n*3; light_list->col[idx]*=draw->tint.r; light_list->col[idx+1]*=draw->tint.g; light_list->col[idx+2]*=draw->tint.b; } }
void camera_chase_static_get_position(d3pnt *pnt,d3ang *ang) { int cx,cz,cy; float fx,fy,fz; matrix_type mat; obj_type *obj; obj=object_find_uid(camera.obj_uid); // get static chase position fx=0; fy=0; fz=(float)camera.chase_distance; matrix_rotate_zyx(&mat,camera.cur_chase_ang.x,camera.cur_chase_ang.y,camera.cur_chase_ang.z); matrix_vertex_multiply(&mat,&fx,&fy,&fz); cx=(int)fx+obj->pnt.x; cy=(int)fy+obj->pnt.y-obj->size.y; cz=(int)fz+obj->pnt.z; // new camera position pnt->x=camera.pnt.x=cx+camera.chase_offset.x; pnt->y=camera.pnt.y=cy+camera.chase_offset.y; pnt->z=camera.pnt.z=cz+camera.chase_offset.z; // looking angles ang->x=(camera.cur_chase_ang.x+camera.ang.x); ang->y=angle_add(camera.cur_chase_ang.y,camera.ang.y); ang->z=camera.ang.z; }
void camera_chase_static_calc_position(void) { float fx,fy,fz; obj_type *obj; matrix_type mat; obj=server.obj_list.objs[camera.obj_idx]; // new camera position fx=0; fy=0; fz=(float)map.camera.chase.distance; matrix_rotate_zyx(&mat,map.camera.chase.track_ang.x,map.camera.chase.track_ang.y,map.camera.chase.track_ang.z); matrix_vertex_multiply(&mat,&fx,&fy,&fz); camera.cur_pos.pnt.x=(obj->pnt.x+((int)fx))+map.camera.pnt_offset.x; camera.cur_pos.pnt.y=((obj->pnt.y+obj->size.eye_offset)+((int)fy))+map.camera.pnt_offset.y; camera.cur_pos.pnt.z=(obj->pnt.z+((int)fz))+map.camera.pnt_offset.z; // looking angles camera.cur_pos.ang.x=map.camera.chase.track_ang.x+map.camera.ang_offset.x; if (camera.cur_pos.ang.x>180.0f) camera.cur_pos.ang.x-=360.0f; camera.cur_pos.ang.y=map.camera.chase.track_ang.y+map.camera.ang_offset.y; camera.cur_pos.ang.z=map.camera.chase.track_ang.z+map.camera.ang_offset.z; }
void gl_3D_rotate(d3pnt *pnt,d3ang *ang) { float fx,fz,fy,ang_x; matrix_type mat; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // need to cap look up/down at 90 ang_x=ang->x; if (ang_x>=90.0f) ang_x=89.9f; if (ang_x<=-90.0f) ang_x=-89.9f; // create the look at vector matrix_rotate_zyx(&mat,ang_x,ang->y,0.0f); fx=fy=0.0f; fz=-((float)camera.plane.near_z); matrix_vertex_multiply(&mat,&fx,&fy,&fz); if (pnt==NULL) { gluLookAt(fx,fy,fz,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f); } else { gluLookAt((pnt->x+fx),(pnt->y+fy),(pnt->z+fz),pnt->x,pnt->y,pnt->z,0.0f,1.0f,0.0f); } }
void map_mesh_rotate(map_type *map,int mesh_idx,d3pnt *center_pnt,d3ang *rot_ang) { int n,nvertex,npoly; float fx,fy,fz; d3vct f_mpt; d3pnt *pt; matrix_type mat; map_mesh_type *mesh; map_mesh_poly_type *poly; mesh=&map->mesh.meshes[mesh_idx]; // get mesh rotation center f_mpt.x=(float)(center_pnt->x+mesh->rot_off.x); f_mpt.y=(float)(center_pnt->y+mesh->rot_off.y); f_mpt.z=(float)(center_pnt->z+mesh->rot_off.z); // matrixes matrix_rotate_xyz(&mat,rot_ang->x,rot_ang->y,rot_ang->z); // rotate vertexes nvertex=mesh->nvertex; pt=mesh->vertexes; for (n=0; n!=nvertex; n++) { fx=((float)pt->x)-f_mpt.x; fy=((float)pt->y)-f_mpt.y; fz=((float)pt->z)-f_mpt.z; matrix_vertex_multiply(&mat,&fx,&fy,&fz); pt->x=(int)(fx+f_mpt.x); pt->y=(int)(fy+f_mpt.y); pt->z=(int)(fz+f_mpt.z); pt++; } // fix boxes npoly=mesh->npoly; poly=mesh->polys; for (n=0; n!=npoly; n++) { map_prepare_mesh_poly(mesh,poly); poly++; } // fix mesh box map_prepare_mesh_box(mesh); }
bool particle_spawn(int particle_idx,int obj_idx,d3pnt *pt,particle_rotate *rot,particle_motion *motion) { int n,count,shift,idx; float xoff,yoff,zoff; d3pnt ppt; d3ang ang; matrix_type mat; iface_particle_type *particle; particle=&iface.particle_list.particles[particle_idx]; // single particles if (!particle->group.on) { return(particle_spawn_single(particle_idx,obj_idx,pt,rot,motion)); } // get offset to camera position camera_get_angle_from(pt,&ang); matrix_rotate_xy(&mat,ang.x,ang.y); // groups of particles count=particle->group.count; for (n=0;n!=count;n++) { idx=particle_find_index(particle->group.particles[n].name); if (idx==-1) continue; if (iface.particle_list.particles[idx].group.on) continue; // don't respawn other groups // compute shifts memmove(&ppt,pt,sizeof(d3pnt)); shift=iface.particle_list.particles[idx].group.particles[n].shift; if (shift!=0) { xoff=yoff=0.0f; zoff=-(float)shift; matrix_vertex_multiply(&mat,&xoff,&yoff,&zoff); ppt.x+=(int)xoff; ppt.y+=(int)yoff; ppt.z+=(int)zoff; } // spawn particle if (!particle_spawn_single(idx,obj_idx,&ppt,rot,motion)) return(FALSE); } return(TRUE); }
void rotate_2D_line(int *lx,int *lz,int *rx,int *rz,int cx,int cz,float ang_y) { float fx,fy,fz; matrix_type mat; matrix_rotate_y(&mat,ang_y); fx=(float)((*lx)-cx); fy=0; fz=(float)((*lz)-cz); matrix_vertex_multiply(&mat,&fx,&fy,&fz); *lx=(int)fx+cx; *lz=(int)fz+cz; fx=(float)((*rx)-cx); fy=0; fz=(float)((*rz)-cz); matrix_vertex_multiply(&mat,&fx,&fy,&fz); *rx=(int)fx+cx; *rz=(int)fz+cz; }
void rotate_2D_point_center(int *x,int *z,float ang_y) { float fx,fy,fz; matrix_type mat; matrix_rotate_y(&mat,ang_y); fx=(float)*x; fy=0; fz=(float)*z; matrix_vertex_multiply(&mat,&fx,&fy,&fz); *x=(int)fx; *z=(int)fz; }
void model_get_point_position(model_draw_setup *draw_setup,int *x,int *y,int *z) { int cx,cy,cz; float fx,fy,fz; matrix_type rot_x_mat,rot_z_mat,rot_y_mat,sway_mat; fx=(float)*x; fz=(float)*z; fy=(float)*y; // sway matrix_rotate_zyx(&sway_mat,draw_setup->sway.x,draw_setup->sway.y,draw_setup->sway.z); matrix_vertex_multiply(&sway_mat,&fx,&fy,&fz); // rotate cx=draw_setup->center.x; cy=draw_setup->center.y; cz=draw_setup->center.z; fx-=(float)cx; fy-=(float)cy; fz-=(float)cz; matrix_rotate_x(&rot_x_mat,draw_setup->ang.x); matrix_rotate_z(&rot_z_mat,draw_setup->ang.z); matrix_rotate_y(&rot_y_mat,draw_setup->ang.y); matrix_vertex_multiply(&rot_x_mat,&fx,&fy,&fz); matrix_vertex_multiply(&rot_z_mat,&fx,&fy,&fz); matrix_vertex_multiply(&rot_y_mat,&fx,&fy,&fz); *x=(int)(fx+draw_setup->move.x)+cx; *y=(int)(fy+draw_setup->move.y)+cy; *z=(int)(fz+draw_setup->move.z)+cz; }
void rotate_2D_point(int *x,int *z,int cx,int cz,float ang_y) { float fx,fy,fz; matrix_type mat; matrix_rotate_y(&mat,ang_y); fx=(float)((*x)-cx); fy=0; fz=(float)((*z)-cz); matrix_vertex_multiply(&mat,&fx,&fy,&fz); *x=(int)fx+cx; *z=(int)fz+cz; }
void rotate_point_center(int *x,int *y,int *z,float ang_x,float ang_y,float ang_z) { float fx,fy,fz; matrix_type mat; matrix_rotate_xyz(&mat,ang_x,ang_y,ang_z); fx=(float)*x; fy=(float)*y; fz=(float)*z; matrix_vertex_multiply(&mat,&fx,&fy,&fz); *x=(int)fx; *y=(int)fy; *z=(int)fz; }
void rotate_point(int *x,int *y,int *z,int cx,int cy,int cz,float ang_x,float ang_y,float ang_z) { float fx,fy,fz; matrix_type mat; matrix_rotate_xyz(&mat,ang_x,ang_y,ang_z); fx=(float)((*x)-cx); fy=(float)((*y)-cy); fz=(float)((*z)-cz); matrix_vertex_multiply(&mat,&fx,&fy,&fz); *x=(int)fx+cx; *y=(int)fy+cy; *z=(int)fz+cz; }
void rotate_2D_polygon(int ptsz,int *x,int *z,int cx,int cz,float ang_y) { int n; int *px,*pz; float fx,fy,fz; matrix_type mat; matrix_rotate_y(&mat,ang_y); px=x; pz=z; for (n=0;n<ptsz;n++) { fx=(float)((*px)-cx); fy=0; fz=(float)((*pz)-cz); matrix_vertex_multiply(&mat,&fx,&fy,&fz); *px++=(int)fx+cx; *pz++=(int)fz+cz; } }
void rotate_polygon_center(int ptsz,int *x,int *y,int *z,float ang_x,float ang_y,float ang_z) { int n; int *px,*py,*pz; float fx,fy,fz; matrix_type mat; matrix_rotate_xyz(&mat,ang_x,ang_y,ang_z); px=x; py=y; pz=z; for (n=0;n<ptsz;n++) { fx=(float)*px; fy=(float)*py; fz=(float)*pz; matrix_vertex_multiply(&mat,&fx,&fy,&fz); *px++=(int)fx; *py++=(int)fy; *pz++=(int)fz; } }
void rotate_polygon(int ptsz,int *x,int *y,int *z,int cx,int cy,int cz,float ang_x,float ang_y,float ang_z) { int n; int *px,*py,*pz; float fx,fy,fz; matrix_type mat; matrix_rotate_xyz(&mat,ang_x,ang_y,ang_z); px=x; py=y; pz=z; for (n=0;n<ptsz;n++) { fx=(float)((*px)-cx); fy=(float)((*py)-cy); fz=(float)((*pz)-cz); matrix_vertex_multiply(&mat,&fx,&fy,&fz); *px++=(int)fx+cx; *py++=(int)fy+cy; *pz++=(int)fz+cz; } }
void view_dim3rtl_effect_mesh_ring_update(effect_type *effect,int count,int image_offset) { int n,k,life_tick,idx, material_id; short *polys,*vk; float mx,my,mz,fx,fy,fz, outer_sz,inner_sz,rd, color_dif,alpha,gx,gy,g_size, f_count,f_tick; float *vp,*uv; d3pnt pnt; rtlColor col; iface_ring_type *ring; ring_effect_data *eff_ring; matrix_type mat_x,mat_y,mat_z; eff_ring=&effect->data.ring; ring=&iface.ring_list.rings[eff_ring->ring_idx]; // get size life_tick=effect->life_tick; f_tick=(float)life_tick; f_count=(float)count; outer_sz=(float)(ring->end_outer_size-ring->start_outer_size); outer_sz=((outer_sz*f_count)/f_tick)+(float)ring->start_outer_size; inner_sz=(float)(ring->end_inner_size-ring->start_inner_size); inner_sz=((inner_sz*f_count)/f_tick)+(float)ring->start_inner_size; // setup images effect_image_animate_get_uv(count,image_offset,&ring->animate,&gx,&gy,&g_size); // position and ring rotation ring_draw_position(effect,count,&pnt); mx=(float)pnt.x; my=(float)pnt.y; mz=(float)pnt.z; fx=f_count*ring->rot.x; fx+=(fx*ring->rot_accel.x); fx=angle_add(eff_ring->ang.x,fx); fy=f_count*ring->rot.y; fy+=(fy*ring->rot_accel.y); fy=angle_add(eff_ring->ang.y,fy); fz=f_count*ring->rot.z; fz+=(fz*ring->rot_accel.z); fz=angle_add(eff_ring->ang.z,fz); matrix_rotate_x(&mat_x,-fx); matrix_rotate_z(&mat_z,fz); matrix_rotate_y(&mat_y,fy); // create the ring vertexes rtlSceneMeshMapVertexPointer(view_rtl_draw_scene_id,effect->rtl_mesh_id,(void**)&vp); rtlSceneMeshMapUVPointer(view_rtl_draw_scene_id,effect->rtl_mesh_id,(void**)&uv); for (n=0;n!=360;n+=10) { rd=((float)n)*ANG_to_RAD; // outer fx=cosf(rd)*outer_sz; fy=-(sinf(rd)*outer_sz); fz=0.0f; matrix_vertex_multiply(&mat_x,&fx,&fy,&fz); matrix_vertex_multiply(&mat_z,&fx,&fy,&fz); matrix_vertex_multiply(&mat_y,&fx,&fy,&fz); *vp++=mx+fx; *vp++=my+fy; *vp++=mz+fz; *uv++=gx+(g_size*((fx+outer_sz)/(outer_sz*2.0f))); *uv++=gy+(g_size*((fy+outer_sz)/(outer_sz*2.0f))); // inner fx=cosf(rd)*inner_sz; fy=-(sinf(rd)*inner_sz); fz=0.0f; matrix_vertex_multiply(&mat_x,&fx,&fy,&fz); matrix_vertex_multiply(&mat_z,&fx,&fy,&fz); matrix_vertex_multiply(&mat_y,&fx,&fy,&fz); *vp++=mx+fx; *vp++=my+fy; *vp++=mz+fz; *uv++=gx+(g_size*((fx+outer_sz)/(outer_sz*2.0f))); *uv++=gy+(g_size*((fy+outer_sz)/(outer_sz*2.0f))); } rtlSceneMeshUnMapVertexPointer(view_rtl_draw_scene_id,effect->rtl_mesh_id); rtlSceneMeshUnMapUVPointer(view_rtl_draw_scene_id,effect->rtl_mesh_id); // create the polys // last one needs to wrap around to beginning material_id=ring->rtl_material_id; polys=(short*)malloc(sizeof(short)*(36*10)); vk=polys; idx=0; for (n=0;n!=36;n++) { *vk++=4; *vk++=material_id; *vk++=idx; *vk++=idx; *vk++=idx+1; *vk++=idx+1; if (n!=35) { k=idx+2; } else { k=0; } *vk++=k+1; *vk++=k+1; *vk++=k; *vk++=k; idx+=2; } rtlSceneMeshSetPoly(view_rtl_draw_scene_id,effect->rtl_mesh_id,RL_MESH_FORMAT_POLY_SHORT_VERTEX_UV,36,polys); free(polys); // set color and alpha color_dif=ring->end_color.r-ring->start_color.r; col.r=ring->start_color.r+((color_dif*f_count)/f_tick); color_dif=ring->end_color.g-ring->start_color.g; col.g=ring->start_color.g+((color_dif*f_count)/f_tick); color_dif=ring->end_color.b-ring->start_color.b; col.b=ring->start_color.b+((color_dif*f_count)/f_tick); alpha=ring->end_alpha-ring->start_alpha; col.a=((alpha*f_count)/f_tick)+ring->start_alpha; rtlSceneMeshSetPolyColorAll(view_rtl_draw_scene_id,effect->rtl_mesh_id,&col); }
void camera_chase_calc_position(void) { int radius; float fang,fx,fy,fz; d3pnt spt,ept; ray_trace_contact_type contact; matrix_type mat; obj_type *obj; obj=server.obj_list.objs[camera.obj_idx]; // get camera starting position radius=object_get_radius(obj); fx=0; fy=0; fz=(float)(radius>>2); // always move camera back to protect against hitting walls in front of player fang=angle_add(camera.cur_pos.chase_ang.x,(obj->view_ang.x*2)); matrix_rotate_zyx(&mat,fang,camera.cur_pos.chase_ang.y,camera.cur_pos.chase_ang.z); matrix_vertex_multiply(&mat,&fx,&fy,&fz); spt.x=((int)fx)+obj->pnt.x; spt.y=((int)fy)+(obj->pnt.y+obj->size.eye_offset); spt.z=((int)fz)+obj->pnt.z; // get camera ending position fx=0; fy=0; fz=(float)map.camera.chase.distance; fang=angle_add(camera.cur_pos.chase_ang.x,-obj->view_ang.x); matrix_rotate_zyx(&mat,fang,camera.cur_pos.chase_ang.y,camera.cur_pos.chase_ang.z); matrix_vertex_multiply(&mat,&fx,&fy,&fz); ept.x=((int)fx)+obj->pnt.x; ept.y=((int)fy)+(obj->pnt.y+obj->size.eye_offset); ept.z=((int)fz)+obj->pnt.z; // setup contacts contact.obj.on=TRUE; contact.obj.ignore_idx=obj->idx; contact.proj.on=FALSE; contact.origin=poly_ray_trace_origin_unknown; ray_trace_map_by_point(&spt,&ept,&contact); // the position camera.cur_pos.pnt.x=contact.hpt.x+map.camera.pnt_offset.x; camera.cur_pos.pnt.y=contact.hpt.y+map.camera.pnt_offset.y; camera.cur_pos.pnt.z=contact.hpt.z+map.camera.pnt_offset.z; if (obj->bump.on) camera.cur_pos.pnt.y+=obj->bump.smooth_offset; // looking angles // need to reverse X looking angle so it // behaves opposite track X angle camera.cur_pos.ang.x=(camera.cur_pos.chase_ang.x-map.camera.ang_offset.x)-obj->view_ang.x; camera.cur_pos.ang.y=angle_add(camera.cur_pos.chase_ang.y,map.camera.ang_offset.y); camera.cur_pos.ang.z=camera.cur_pos.chase_ang.z+map.camera.ang_offset.z; }
void camera_chase_get_position(d3pnt *pnt,d3ang *ang) { int n,xadd,yadd,zadd,radius,div, cx,cz,cy; float fang,fx,fy,fz; d3pnt spt,ept,hpt; ray_trace_contact_type contact; matrix_type mat; obj_type *obj; weapon_type *weap; obj=object_find_uid(camera.obj_uid); // get maximum camera offset fx=0; fy=0; fz=(float)camera.chase_distance; fang=angle_add(camera.cur_chase_ang.x,-obj->view_ang.x); matrix_rotate_zyx(&mat,fang,camera.cur_chase_ang.y,camera.cur_chase_ang.z); matrix_vertex_multiply(&mat,&fx,&fy,&fz); cx=(int)fx+obj->pnt.x; cy=(int)fy+obj->pnt.y; cz=(int)fz+obj->pnt.z; // get camera movement div=camera_chase_get_division(abs(cx-obj->pnt.x),abs(cz-obj->pnt.z),abs(cy-obj->pnt.y)); if (div==0) div=1; xadd=(cx-obj->pnt.x)/div; yadd=(cy-obj->pnt.y)/div; zadd=(cz-obj->pnt.z)/div; // get camera starting position radius=camera.chase_size; fx=0; fy=0; fz=(float)(radius>>2); // always move camera back to protect against hitting walls in front of player fang=angle_add(camera.cur_chase_ang.x,(obj->view_ang.x*2)); matrix_rotate_zyx(&mat,fang,camera.cur_chase_ang.y,camera.cur_chase_ang.z); matrix_vertex_multiply(&mat,&fx,&fy,&fz); cx=(int)fx+obj->pnt.x; cz=(int)fz+obj->pnt.z; cy=(int)fy+(obj->pnt.y-obj->size.y); // setup contacts contact.obj.on=TRUE; contact.obj.ignore_uid=obj->uid; contact.proj.on=FALSE; contact.origin=poly_ray_trace_origin_unknown; // move camera for (n=0;n!=div;n++) { // xz movement spt.x=cx; spt.y=cy; spt.z=cz; ept.x=cx+xadd; ept.y=cy; ept.z=cz+zadd; contact.hit_mode=poly_ray_trace_hit_mode_wall_only; if (!ray_trace_map_by_point(&spt,&ept,&hpt,&contact)) { cx+=xadd; cz+=zadd; } // y movement spt.x=cx; spt.y=cy; spt.z=cz; ept.x=cx; ept.y=cy+yadd; ept.z=cz; contact.hit_mode=poly_ray_trace_hit_mode_floor_only; if (!ray_trace_map_by_point(&spt,&ept,&hpt,&contact)) cy+=yadd; } // new camera position camera.pnt.x=cx; camera.pnt.y=cy; camera.pnt.z=cz; // return values memmove(pnt,&camera.pnt,sizeof(d3pnt)); // looking angles ang->x=(camera.cur_chase_ang.x+camera.ang.x)-obj->view_ang.x; weap=weapon_find_current(obj); if (weap!=NULL) ang->x=object_player_look_constrain(obj,weap,ang->x); ang->y=angle_add(camera.cur_chase_ang.y,camera.ang.y); ang->z=camera.ang.z; }
void view_draw_debug_bounding_box(obj_type *obj) { int n,xsz,ysz,zsz,px[8],py[8],pz[8]; float fx,fy,fz; matrix_type rot_x_mat,rot_y_mat,rot_z_mat; model_type *mdl; mdl=model_find_uid(obj->draw.uid); if (mdl==NULL) return; // bounding box xsz=obj->size.x>>1; zsz=obj->size.z>>1; ysz=obj->size.y; if (obj->duck.mode!=dm_stand) ysz-=obj->duck.y_move; px[0]=px[1]=px[4]=px[5]=-xsz; px[2]=px[3]=px[6]=px[7]=xsz; py[0]=py[1]=py[2]=py[3]=-ysz; py[4]=py[5]=py[6]=py[7]=0; pz[1]=pz[2]=pz[5]=pz[6]=-zsz; pz[0]=pz[3]=pz[4]=pz[7]=zsz; matrix_rotate_x(&rot_x_mat,obj->draw.setup.ang.x); matrix_rotate_z(&rot_z_mat,obj->draw.setup.ang.z); matrix_rotate_y(&rot_y_mat,obj->draw.setup.ang.y); for (n=0;n!=8;n++) { fx=(float)(px[n]-mdl->center.x); fy=(float)(py[n]-mdl->center.y); fz=(float)(pz[n]-mdl->center.z); matrix_vertex_multiply(&rot_x_mat,&fx,&fy,&fz); matrix_vertex_multiply(&rot_z_mat,&fx,&fy,&fz); matrix_vertex_multiply(&rot_y_mat,&fx,&fy,&fz); px[n]=((int)fx)+mdl->center.x; py[n]=((int)fy)+mdl->center.y; pz[n]=((int)fz)+mdl->center.z; } for (n=0;n!=8;n++) { px[n]=px[n]+obj->pnt.x; py[n]=py[n]+obj->pnt.y; pz[n]=pz[n]+obj->pnt.z; } // draw box glColor4f(0.2f,0.2f,1.0f,1.0f); glLineWidth(2.0f); glBegin(GL_LINE_LOOP); glVertex3i(px[0],py[0],pz[0]); glVertex3i(px[1],py[1],pz[1]); glVertex3i(px[2],py[2],pz[2]); glVertex3i(px[3],py[3],pz[3]); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(px[4],py[4],pz[4]); glVertex3i(px[5],py[5],pz[5]); glVertex3i(px[6],py[6],pz[6]); glVertex3i(px[7],py[7],pz[7]); glEnd(); glBegin(GL_LINES); glVertex3i(px[0],py[0],pz[0]); glVertex3i(px[4],py[4],pz[4]); glVertex3i(px[1],py[1],pz[1]); glVertex3i(px[5],py[5],pz[5]); glVertex3i(px[2],py[2],pz[2]); glVertex3i(px[6],py[6],pz[6]); glVertex3i(px[3],py[3],pz[3]); glVertex3i(px[7],py[7],pz[7]); glEnd(); glLineWidth(1.0f); glColor4f(0.0f,0.0f,0.0f,1.0f); }