2018-08-17 15:46 EDT


View Issue Details Jump to Notes ] Related Changesets ]
IDProjectCategoryView StatusLast Update
0001978FSSCPcutscenespublic2012-12-14 17:54
Reporterchief1983 
Assigned ToValathil 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
Product Version3.6.11 
Target VersionFixed in Version 
Summary0001978: set camera host does not use object's eye if available
DescriptionOk, so I can set camera host to any subobject of a ship, like a capital ship's turret. If I have defined an eyepoint and tied it to that subobject, shouldn't set-camera-host use the eyepoint and not just the center of the object? If I set camera host to the parent object I would think it should use that ship's main eye point as well.
Additional InformationBasically, I was trying to use SEXPs to jump to a turret view, but I can't because the camera doesn't tie to the eyepoint, so it doesn't follow the turret. I'm assuming an eyepoint attached to a subobject does follow the subobject, and not the parent object?
TagsNo tags attached.
Attached Files
  • patch file icon 1978.patch (4,437 bytes) 2012-12-13 22:34 -
    Index: code/camera/camera.cpp
    ===================================================================
    --- code/camera/camera.cpp	(revision 9426)
    +++ code/camera/camera.cpp	(working copy)
    @@ -11,6 +11,7 @@
     #include "ship/ship.h" //compute_slew_matrix
     #include "graphics/font.h"
     #include "mod_table/mod_table.h"
    +#include "globalincs/linklist.h"
     
     //*************************IMPORTANT GLOBALS*************************
     float VIEWER_ZOOM_DEFAULT = 0.75f;			//	Default viewer zoom, 0.625 as per multi-lateral agreement on 3/24/97
    @@ -110,6 +111,22 @@
     
     	object_host = object_h(objp);
     	object_host_submodel = n_object_host_submodel;
    +	set_custom_position_function(NULL);
    +	set_custom_orientation_function(NULL);
    +	if(n_object_host_submodel > 0) {
    +		if(objp->type == OBJ_SHIP) {
    +			ship_subsys* ssp = GET_FIRST(&Ships[objp->instance].subsys_list);
    +			while ( ssp != END_OF_LIST( &Ships[objp->instance].subsys_list ) ) {
    +				if(ssp->system_info->subobj_num == n_object_host_submodel) {
    +					if(ssp->system_info->type == SUBSYSTEM_TURRET) {
    +						set_custom_position_function(get_turret_cam_pos);
    +						set_custom_orientation_function(get_turret_cam_orient);
    +					}
    +				}
    +				ssp = GET_NEXT( ssp );
    +			}
    +		}
    +	}
     }
     
     void camera::set_object_target(object *objp, int n_object_target_submodel)
    @@ -119,6 +136,7 @@
     
     	object_target = object_h(objp);
     	object_target_submodel = n_object_target_submodel;
    +
     }
     
     /**
    @@ -290,7 +308,9 @@
     		pos_x.get(&pt.xyz.x, NULL);
     		pos_y.get(&pt.xyz.y, NULL);
     		pos_z.get(&pt.xyz.z, NULL);
    -
    +		
    +		eye* eyep = NULL;
    +		
     		if(object_host.IsValid())
     		{
     			object *objp = object_host.objp;
    @@ -309,7 +329,30 @@
     			}
     			else
     			{
    -				model_find_world_point( &c_pos, &pt, pm->id, object_host_submodel, &objp->orient, &objp->pos );
    +				if(pm->n_view_positions > 0) {
    +					for(int i = 0; i < pm->n_view_positions; ++i) {
    +						if(pm->view_positions[i].parent == object_host_submodel) {
    +							eyep = &pm->view_positions[i];
    +							break;
    +						}
    +						int sm = pm->submodel[object_host_submodel].first_child;
    +						while(sm > 0) { //look for eyepoints attached to children, important for turret arms
    +							if(pm->view_positions[i].parent == sm) {
    +								eyep = &pm->view_positions[i];
    +								break;
    +							}
    +							sm = pm->submodel[sm].next_sibling;
    +						}
    +					}
    +				}
    +				if(eyep) {
    +					vec3d dummy, c_pos_in;
    +					find_submodel_instance_point_normal( &c_pos_in, &dummy, objp, object_host_submodel+1, &eyep->pnt, &dummy);
    +					vm_vec_unrotate(&c_pos, &c_pos_in, &objp->orient);
    +					vm_vec_add2(&c_pos, &objp->pos);
    +				} else {
    +					model_find_world_point( &c_pos, &pt, pm->id, object_host_submodel, &objp->orient, &objp->pos );
    +				}
     			}
     		}
     		else
    @@ -317,10 +360,14 @@
     			c_pos = pt;
     		}
     
    +		vec3d custom_pos;
     		//Do custom position stuff, if needed
     		if(func_custom_position != NULL)
     		{
    -			func_custom_position(this, &c_pos);
    +			func_custom_position(this, &custom_pos);
    +			if(!eyep) {
    +				c_pos = custom_pos;
    +			}
     		}
     	}
     
    @@ -983,3 +1030,29 @@
     			sub->do_frame(frametime);
     	}
     }
    +
    +vec3d normal_cache;
    +
    +void get_turret_cam_pos(camera *cam, vec3d *pos)
    +{
    +	object_h obj(cam->get_object_host());
    +	if(!obj.IsValid())
    +		return;
    +	ship* shipp = &Ships[cam->get_object_host()->instance];
    +	ship_subsys* ssp = GET_FIRST(&shipp->subsys_list);
    +	while ( ssp != END_OF_LIST( &shipp->subsys_list ) ) {
    +		if(ssp->system_info->subobj_num == cam->get_object_host_submodel()) {
    +			ship_get_global_turret_gun_info(cam->get_object_host(), ssp, pos, &normal_cache, 1, NULL);
    +			break;
    +		}
    +		ssp = GET_NEXT( ssp );
    +	}
    +}
    +
    +void get_turret_cam_orient(camera *cam, matrix *ori)
    +{
    +	object_h obj(cam->get_object_host());
    +	if(!obj.IsValid())
    +		return;
    +	vm_vector_2_matrix(ori, &normal_cache, vm_vec_same(&normal_cache, &cam->get_object_host()->orient.vec.uvec)?NULL:&cam->get_object_host()->orient.vec.uvec, NULL);
    +}
    \ No newline at end of file
    Index: code/camera/camera.h
    ===================================================================
    --- code/camera/camera.h	(revision 9426)
    +++ code/camera/camera.h	(working copy)
    @@ -168,6 +168,9 @@
     camid cam_get_current();
     uint cam_get_num();
     
    +void get_turret_cam_pos(camera *cam, vec3d *pos);
    +void get_turret_cam_orient(camera *cam, matrix *ori);
    +
     void subtitles_close();
     void subtitles_do_frame(float frametime);
     void subtitles_do_frame_post_shaded(float frametime);
    
    patch file icon 1978.patch (4,437 bytes) 2012-12-13 22:34 +

-Relationships
+Relationships

-Notes

~0011222

chief1983 (administrator)

Anyone have any thoughts?

~0012256

chief1983 (administrator)

*bump* for great justice

~0012327

Goober5000 (administrator)

Hmm yes, it should use the eyepoint. :nervous:

Actually, it should be fairly easy to fix this; the eyepoint code isn't that complicated. Who (if anyone) is the camera code guru these days?

~0012328

chief1983 (administrator)

Backslash was just looking at this earlier today. I believe the SEXP was added by WMC though after reading some old forum posts over the weekend.

~0012329

Backslash (developer)

Well don't let the idea that I was looking at it prevent anyone more experienced from taking it on. :-) I don't fully understand it yet.

Looks to me like subobject eyepoints are never paid attention to in the code at all. If so, this is a feature request not a bug fix ;-)

~0012330

chief1983 (administrator)

Last edited: 2010-08-25 20:40

I don't think goober was offering but it would be nice if he were :)

Also, I'm not sure the SEXP will even use the parent object's eyepoint. I don't remember if I tested for that or not.

~0012336

Goober5000 (administrator)

Ah crap. :( WMC's code is so terribly complicated that it's hard to figure out anything.

I *think* the relevant code should be around line 388 of camera.cpp, in the camera::get_info method. At least, that's the only part of the camera code that actually does something with the submodel, instead of getting or setting it.

But I can't guarantee that there isn't something I'm missing. I didn't have time to look at the code for very long.

~0012411

chief1983 (administrator)

http://swc.fs2downloads.com/files/private/mod1978.zip should have some materials to help reproduce the issue.

~0012765

chief1983 (administrator)

Ok, I updated that pack with something that might actually be useful. There's a mission, and a corvette with a top turret that has an eyepoint. The turret will start tracking you at mission start, and you can probably maneuver your fighter in front of it and watch the turret follow you. However, the point is that the eyepoint should be following the arms, and the camera should be attached to the eyepoint when I set it to the turret's arms. At least there's enough stuff here to reproduce what I'm talking about now, in case anyone else wants to actually see it.

Use 2 to set the camera to the corvette's turret, and 3 to go back to your fighter. Only works once because I don't FRED much and I don't know how to reset it each time. 1 just unprotects the Argo, which used to be the target of the corvette, but now it won't attack it for some reason. Probably because it's a different size than the previous ship that was in that spot in the mission and might be below the turret's firing arc now.

~0014442

Valathil (developer)

Ok i attached a patch which fixes the eyepoints but added something cool as well.
Since the eyepoint was defined on a turret in the testcase MjnMixael and i thought that the intention was to have the camera following the turret like a gun cam. I added that for all turrets with the camera situated on the firing points but if you have a eyepoint defined on the turret it overrides it so you can do the cam in the middle of two barrels or something. Please code review and comment if its the way it should be.

~0014454

The_E (administrator)

All of my yes. The patch is good, and the feature added is how I personally would expect it to behave.

~0014455

Valathil (developer)

One thing i thought about tho is when you set a separate target for the camera i think it gets overridden by the new custom function. Is setting the host to a turret and then a specific target a use case that has to be handled or do we want gun cam all day everyday?

~0014457

chief1983 (administrator)

You definitely understood where I was going with this, although I might have made a mistake in my test model/mission that would have not required any special treatment for turrets. Attaching the eyepoint to the barrel subobject would require the intended effect as long as the eyepoint moves with that subobject. I'll try to follow up on IRC to double check how this was implemented, I might have misunderstood your note.

~0014459

Valathil (developer)

It might have removed the need for the child model checking but i wanted it to work with all turrets even without defined eyepoints so i implemented it that way.

~0014460

chief1983 (administrator)

Sounds splendid to me.

~0014461

Valathil (developer)

Fix committed to trunk@9432.

~0014463

chief1983 (administrator)

Ballin'.
+Notes

+Related Changesets

-Issue History
Date Modified Username Field Change
2009-08-19 13:05 chief1983 New Issue
2009-11-02 17:08 chief1983 Note Added: 0011222
2010-07-22 01:28 chief1983 Note Added: 0012256
2010-08-24 22:37 Goober5000 Note Added: 0012327
2010-08-24 23:39 chief1983 Note Added: 0012328
2010-08-25 19:54 Backslash Note Added: 0012329
2010-08-25 20:38 chief1983 Note Added: 0012330
2010-08-25 20:40 chief1983 Note Edited: 0012330
2010-08-29 01:03 Goober5000 Note Added: 0012336
2010-10-15 12:42 chief1983 Note Added: 0012411
2011-08-17 19:17 chief1983 Note Added: 0012765
2012-01-10 14:35 chief1983 Assigned To => chief1983
2012-01-10 14:35 chief1983 Status new => code review
2012-01-10 14:48 chief1983 Assigned To chief1983 =>
2012-01-10 14:48 chief1983 Status code review => new
2012-12-13 22:34 Valathil Assigned To => Valathil
2012-12-13 22:34 Valathil Status new => assigned
2012-12-13 22:34 Valathil File Added: 1978.patch
2012-12-13 22:38 Valathil Note Added: 0014442
2012-12-13 22:38 Valathil Status assigned => code review
2012-12-14 06:40 The_E Note Added: 0014454
2012-12-14 08:42 Valathil Note Added: 0014455
2012-12-14 12:39 chief1983 Note Added: 0014457
2012-12-14 12:49 Valathil Note Added: 0014459
2012-12-14 14:10 chief1983 Note Added: 0014460
2012-12-14 16:47 Valathil Changeset attached => fs2open trunk r9432
2012-12-14 16:47 Valathil Note Added: 0014461
2012-12-14 16:47 Valathil Status code review => resolved
2012-12-14 16:47 Valathil Resolution open => fixed
2012-12-14 17:54 chief1983 Note Added: 0014463
+Issue History