c# - Can anyone spot why my XNA model doesn't render correctly? -
my last question put on hold because tried provide of source code (which pretty small example is). problem able draw quad , position camera , face towards {0,0,0}. whatever reason, when draw model should soldier standing in center, don't see it. while debugging see model loaded correctly, has bones/meshes etc unsure of why don't see it.
my camera setup such:
public class cameramanager : gamecomponent { private graphicsdevicemanager fgraphicsdevicemanager; public matrix viewmatrix { get; private set; } public matrix projectionmatrix { get; private set; } public vector3 cameraposition { get; set; } public vector3 cameratarget { get; set; } public float aspectratio { get; set; } public float nearclip { get; set; } public float farclip { get; set; } public float viewangle { get; set; } public cameramanager(game pgame, graphicsdevicemanager pgraphicsdevicemanager) : base(pgame) { fgraphicsdevicemanager = pgraphicsdevicemanager; cameraposition = new vector3(500, 300, 100); cameratarget = vector3.zero; viewport vviewport = pgraphicsdevicemanager.graphicsdevice.viewport; aspectratio = (float)vviewport.width / (float)vviewport.height; nearclip = 1.0f; farclip = 2000.0f; viewangle = mathhelper.piover4; } public override void update(gametime pgametime) { viewmatrix = matrix.createlookat(cameraposition, cameratarget, vector3.up); projectionmatrix = matrix.createperspectivefieldofview(viewangle, aspectratio, nearclip, farclip); base.update(pgametime); } }
notice camera doesn't change, set static out in world looking @ zero.
now model class:
public class soldier : drawablegamecomponent { game1 fgame; model fmodel; public vector3 forward { get; set; } public vector3 position { get; set; } public soldier(game1 pgame) : base(pgame) { fgame = pgame; forward = vector3.forward; position = vector3.zero; } protected override void loadcontent() { fmodel = fgame.content.load<model>(@"models\human\soldier\mp_us_support"); //fmodel = fgame.content.load<model>(@"models\vehicles\planes\model_plane"); } public override void update(gametime pgametime) { base.update(pgametime); } public override void draw(gametime pgametime) { foreach (modelmesh vmesh in fmodel.meshes) { foreach (basiceffect vbasiceffect in vmesh.effects) { vbasiceffect.projection = fgame.fcameramanager.viewmatrix; vbasiceffect.view = fgame.fcameramanager.projectionmatrix; vbasiceffect.world = matrix.identity; } vmesh.draw(); } base.draw(pgametime); } }
again, model loads fine (i think). set projection/view camera's viewmatrix/projectionmatrix.
and in game1.cs add these components:
protected override void initialize() { //initialize camera fcameramanager = new cameramanager(this,fgraphicsdevicemanager); this.components.add(fcameramanager); //initialize map fmap = new flatmap(this); this.components.add(fmap); //initialize soldier fsoldier = new soldier(this); this.components.add(fsoldier); this.ismousevisible = true; base.initialize();
}
if interested in full source code can found here: http://www.filedropper.com/worldexplorergame (26mb due model, otherwise amount of source code super small).
you have swapped projection , view transformation:
vbasiceffect.projection = fgame.fcameramanager.projectionmatrix; vbasiceffect.view = fgame.fcameramanager.viewmatrix;
btw, model seems bit detailed. if want have multiple soldiers , want maintain real-timeness, should consider simplifying model.
Comments
Post a Comment