Spot on Texture

Blitz3D Forums/Blitz3D Programming/Spot on Texture

Eric(Posted 2004) [#1]
I have a Mesh Terrain, and a Lunar Lander type ship.. As I get close to the ground it's hard to tell how far above I am are... I was thinking of a shadow system, but Most of the ones I see are a little more complicated than I need. I just want a landing spot to appear directly below the Lander. It should scale accordingly, as I get close to the ground it gets bigger. My landing Spot will probably be just an 'X' with a circle around it. Once i learn how to implement this I can get fancy. How can I apply a second texture, my landing spot at just the right location. I really hope I made sense. I'm sure it has to do with multitexturing.

Regards,
ERic


Damien Sturdy(Posted 2004) [#2]
ive done this two ways, one is to constantly have a hidden pivot, reset it to your ships location, and mvoe it directly down, Have it set to collide with the floor. You can then simply just position a "shadow" entity at that location..

However, this is outdated and i know it can be done with linepick. However, ive never used that command, so i darent explain it!


Eric(Posted 2004) [#3]
I'm actually trying to do this with textures if I can. Thanks for the advice.

Regards,
Eric


Rob Farley(Posted 2004) [#4]
load a texture on a handle with flags set to clamp U and V (can't remember those off the top of my head).

mytex = loadtexture("Spot.png",flags)

apply the texture on the next channel to your terrain

entitytexture terrian,mytex,0,2

Then move it around with positiontexture mytex,x,y (values go from 0-1)

Also play with scaletexture mytex,x,y too.

That should get you started.


Eric(Posted 2004) [#5]
Rob,

My Terrain is like this... I Created a terrain with Terragen, Imported it into TrueSpace. My Mesh Terrain is 32 x 32 .I have a Texture Apply In Slot 0, Scaled .1 x .1
Then I have a Texture of a Circle In Slot2 Clamped U and V it's 64,64. I had to Scale the Texture to .01 x .01.

Currently I have the Circle multitextured on top of the Terrain. My TexturePosition is 49.5 x 49.5 to Center it on the Terrain.

All Looks Good Except I can't figure out the correlation between The Mesh Size and Scale and the Texture Size and scale... along with Position. I want the texture to be at the same TRUE X and Z coords as my Lander.

Can you or someone else please help me with this.

Thanks,
Eric

Eric


Eric(Posted 2004) [#6]
Can Someone please help with the above question.

Thanks,
Eric


Eric(Posted 2004) [#7]
Can Anyone Help me?


Damien Sturdy(Posted 2004) [#8]
Hang around mate, il try something when i get home later. This would help me out too you see!


Eric(Posted 2004) [#9]
Ok thanks, and If I come up with something, I will post it here.

Regards,
Eric


Eric(Posted 2004) [#10]
Is there Anyone That Can Help With Texture Coords?


Ross C(Posted 2004) [#11]
Well, normally, the texture co-ords should range between 0 and 1. But since you've scaled the texture, you will have scaled it's movement too.

You wrote

Then I have a Texture of a Circle In Slot2 Clamped U and V it's 64,64. I had to Scale the Texture to .01 x .01.

Currently I have the Circle multitextured on top of the Terrain. My TexturePosition is 49.5 x 49.5 to Center it on the Terrain.



You have scaled the texture to .01 which is a 100th it's normal size. To get the texture in the middle you have set the textures position to 49.5, which is half of 100.

Since you scaled the texture down, you've scaled it's movement down by the same amount. Just remember the positiontexture is more of a percentage.if you scale the mesh up, 49.5 will still be the centre. Only scaling the actual texture will change it's positioning.

Hope that made some sense ;)


skidracer(Posted 2004) [#12]
Once you have your shadow code working so that drawing at 0,0 is correct then you need to position it at 1,1.

I would add entity markers at both positions with the origin a different color than the corner (1,1) marker.

It should then simply be a matter of changing the multiplier to the TexturePosition to get the shadow at 1,1 at global coordinates 1,1.

PositionTexture offsetx#+multx#*globalx#,offsety#+multy#*globaly#

At a guess the multipliers will be something like 1.0/meshwidth(terrainmesh),1.0/meshheight(terrainmesh) for an unscaled terrainmesh model.


Eric(Posted 2004) [#13]
Ok Thanks for the Replies, I have been toying with formula for too many hours, sometimes when your too close to the problem it illudes you.

My Mesh Terrain is Centered at 0,0,0
The Terrain Mesh is 32 x 32 Then Scaled 10,5,10

My Ship Is At Entity Position 0,0,0

The Texture is 64 x 64 Scaled To .01

Looking from top down. Camera Rotated to 90,0,0

If I don't scale the Circle Mesh. It covers the entire Terrain... One big Circle.

As I scale the texture it starts to move to the upper right hand side of the terrain.

Every attempt I have made to keep the texture centered as I scale it, fails... I figure if I can maintain coords of the Actual Scaled Texture, I can create proper offsets.

The actual Scale of the Spot Texture is going to change dynamically in game. So it is important that I have something that works based on Texture Scale.

Also it's position must be directly linked to EntityX#(Ship) and EntityZ#(Ship).

Can you give me some more guidance.

What I am trying to produce is a "Landing Spot" At I get closer to the target landing area, A target Spot will appear and start to get bigger as I approach the terrain.

Thanks a million,
Eric


Eric(Posted 2004) [#14]
Please Please Please , I'm to the point of frustration now.. Can you guys lend me a hand?


Rob Farley(Posted 2004) [#15]
Scale your spot to one extreme and position it correctly.

Scale your spot to the other extreme and position it correctly.

Now, take the difference of the scales and divide that by the position difference.

Then this will give you the mulitplier for the scale.

Apply this multiplier to the position of your spot dependant on your spot scale.


Eric(Posted 2004) [#16]
Ok, Now I did this, and the Multiply ends up being -.14356

Let's say EntityY() is Fixed @ 10 Units and the X and Z Axis are free to move with the keyboard. how do I incorporate the info above to make sure that the texture is Directly below my entity. I figured this would be easy and that there was a direct correlation. But My gosh I can't believe I haven't figured this out yet. Just another stubling block. Ya know I have always wanted to Make a lunar Lander type game since I had my first Computer the 'PET' I did the best I could with that system... and Again on the Amiga with Amos Basic.. Now it time for the 3d incarnation of my favorite game and Something so "Simple" is driving me nuts.

Does anyone have code examples?

Regards,
Eric


Ross C(Posted 2004) [#17]
Well, your formula for positioning your texture should be something like this:

t_scale_x = 0.1
t_scale_y = 0.1

t_coord_x = 0.3 ; coords range between 0 and 1
t_coord_y = 0.7 ; coords range between 0 and 1

ScaleTexture texture , t_scale_x , t_scale_y

PositionTexture texture, t_coord_x * (1/t_scale_x) , t_coord_y * (1/t_scale_y)



That should work, as long as you adjust the variables when your going to scale the texture, and when your going to move the texture. Remember, the textures co-ords are always between 0 and 1, to keep it simple. 0 being left most and 1 being right most for x. Same for y, cept on a the Y axis.

For example, say you scaled the texture down a bit, and wanted to position it in the centre, then you would do:

[code]
t_scale_x = 0.01
t_scale_y = 0.01

t_coord_x = 0.5 ; coords range between 0 and 1
t_coord_y = 0.5 ; coords range between 0 and 1

ScaleTexture texture , t_scale_x , t_scale_y

PositionTexture texture, t_coord_x * (1/t_scale_x) , t_coord_y * (1/t_scale_y)



Hope that helps some more :)


Eric(Posted 2004) [#18]
It Does, Thanks, Now another thing I should think about is the Scale of my Mesh terrain. That affects the Size of the Texture. There are a lot of variables to concider here.

If my EntityX#=0 Which is Centered on the X Axis of the Terrain.. The Texture Coord should be .5. How do I fit this into the Equation. The only thing I am trying to do is make this spot follow my ship. based on True EntityX and Z coords. The Texture Needs to follow the Lander, If the Terrain Scale changes or the Texture scale changes.. It should always remain Centered on the Lander.

Regards,
Eric

Ross, I am at work and can't play around with what the sample you gave me.


Damien Sturdy(Posted 2004) [#19]
Sorry didnt get back to you! by the time i got back here theres already much more help that i was able to find oit. i managed it with a quad but because i was able to scale everything to my liking from scratch, it isnt mutch help. The main problem being scaling of textures. hmmmm.

Just thought id post to apologise for my disapearence....


Eric(Posted 2004) [#20]
I appreciate you getting back to me... I can't believe I can't get this to work yet.


DJWoodgate(Posted 2004) [#21]
This works for a blitz terrain...

TFormPoint posx,0,posz,0,terrain
PositionTexture texture,-0.5+TFormedX()/uscale,(tsize/vscale-0.5)-TFormedZ()/vscale

posx and posz are the world x and z positions. tsize is the terrain grid size. Uscale and vscale are the texture scale. Don't ask me why you need to apply the tsize/vscale offset though because I have not worked it out yet!

I just noticed you say you are using a mesh terrain. Well the same prinicple should apply as for a blitz terrain, with some alteration for UV's and so on. Anyway just post a link to the terrain or a similar one if you are still having problems.


Eric(Posted 2004) [#22]
I Don't have a way to post links right now... May I E-mail you what I have...And maybe you could make sense of it.

My code is very haphazard do to coding frustrations.

Your help would be greatly appreciated


DJWoodgate(Posted 2004) [#23]
Sure, just the terrain mesh will do and I will have a look at it this evening (GMT).


Eric(Posted 2004) [#24]
David,

I sent you the Mesh Terrain, There is no texture applied. I usually scale the Mesh to 10,10,10.

Please let me know if you received it Via E-mail.

again, Thanks.

Eric


DJWoodgate(Posted 2004) [#25]
Yes, got it and after some trial and error came up with this, which should work for you provided you are not using loadermatrix() or otherwise changing the physical mesh. Once I got the texture moving in the right direction and correctly centred, with a texture scale of 1, I then decreased the scale to 0.5 and then 0.25 and worked out how to calculate the offsets after applying them manually. Consequently there may well be a more elegant way of expressing this.

TFormPoint posx,0,posz,0,terrain ; also need to specify posy if your terrain is pitched or rolled.
PositionTexture texture,(0.5/uscale-0.5)+(-TFormedX()/(32*uscale)),(0.5/vscale-0.5)+(-TFormedZ()/(32*vscale))

terrain is your land mesh, uscale and vscale are the texture scales. Your mesh is 32x32 in x/z extending from -16 to +16 with uvs in the range 0..1 hence the use of 32 above multiplied by texture scale which gets the tformed coords in the right ballpark.


Eric(Posted 2004) [#26]
You David are a brain... Perfect!!
Now I am going to pick it apart and figure out how it works... It looks close to what I was doing, except, I could not change terrain Scale or it got all screwed up...Your code works no matter what my Scale is...I just have to adjust the Scale of the Spot Texture down as I increase the scale of the Terrain Mesh.

Again...Thanks a million!!
Eric