Textures

Aug 6, 2009 at 10:06 PM

Hi,

I would like to know how can I load 2D textures to the race car from Tutorial 12, I tried this in VehicleCreator.cs :

Material carMat = new Material();
carMat.Diffuse = Color.LightBlue.ToVector4();
carMat.Specular = Color.White.ToVector4();
carMat.SpecularPower = 10;
carMat.Texture = Content.Load<Texture2D>("cooltexture");   <--- this is where the error occurs

And got this error:

Error    1    The name 'Content' does not exist in the current context

Regards,

Emerson

Coordinator
Aug 8, 2009 at 9:17 PM

Hi Emerson,

Content is a property of a Game class, so you can't directly access Content property from outside of Game (in this case, it's Tutorial12.cs) class. From outside of Game class, you should use State.Content. State class is a static class in Goblin and you can access both Device and Content property of the Game class through State class.

Also, if you are simply assigning a texture to the race car which uses Box geometry as its body, you won't see any textures since Box does not allow texture mapping. In that case, you need to create your own PrimitiveShape and correctly assing the texture coordinates (see Tutorial 7 for making your custom shape with textures). Another way is to use an existing .x or .fbx model that contains texture, and in this case, you should simply set Model.UseInternalMaterial to true instead of assigning your own Material (see Tutorial 2).

 

Ohan

Aug 11, 2009 at 3:48 AM

Hi Ohan,

Thanks for the reply. I've tried something different. I added to VehicleCreator.cs a new parameter "public static RaceCar AddRaceCar(Scene scene, TransformNode parentTrans, ContentManager Content)". That solved my problem. Next I tried to add a .fbx for the tires but now I don't know where exactly I add the code to modify its scale and rotation. I've added in RaceCar.cs this:

public RaceCar(Object container, NewtonPhysics engine): base(container)
        {
            this.engine = engine;

            tireTransNode = new TransformNode[4];
            for (int i = 0; i < 4; i++)
            {
                tireTransNode[i] = new TransformNode();
                tireTransNode[i].Scale = new Vector3(0.0001f, 0.0001f, 0.0002f);     <- new line!
            }

However, no change is made. The tires appears bigger than it should be and also it's not in the correct orientation. What could the problem be??

 

Emerson

Coordinator
Aug 25, 2009 at 3:27 PM

Sorry for late reply. I just realized you posted new one.

I haven't tried modifying the scale or orientation of a tire which is not a primitive shape (which is used to represent the tire model in the tutorial), so I may have some bugs. I will look into that problem.

Ohan