Jump to content

Tapemeter questions


Recommended Posts

Hallo everybody, a couple of questions from an old user that never managed to make a mod but still gets the hitch time and again.

Does anyone have experience with modding the reputation tapemeter? Can you instantiate one in the flight scene, with a different texture, and control it?

Also, what would be the cost of compositing two 512x64 textures at every video update to create a third one (to display in the tapemeter), would that be negligible or not?

Edited by thorfinn
Link to comment
Share on other sites

Can you instantiate one in the flight scene, with a different texture, and control it?

Also, what would be the cost of compositing two 512x64 textures at every video update to create a third one (to display in the tapemeter), would that be negligible or not?

Yep, you can. The second part needs clarification: if you're creating a brand new third texture every frame, you'll end up uploading that texture data to the GPU on every frame which is wasteful although not necessarily a huge bottleneck.

Here's somewhere to start:

[KSPAddon(KSPAddon.Startup.Flight, false)]
class DuplicateRepWidget : MonoBehaviour
{
Gauge gauge;

IEnumerator Start()
{
var widget = FindObjectOfType<CurrencyWidgetsApp>();
while (!widget.widgetSpawner.Spawned) yield return 0;

var stockRep = widget.widgetSpawner.transform.Find("RepWidget");

var newRep = (GameObject)Instantiate(stockRep.gameObject, stockRep.transform.position, stockRep.transform.rotation);
newRep.SetActive(true);
newRep.transform.Translate(new Vector3(-Screen.width * 0.5f, 0f, 0f));

Component.Destroy(newRep.GetComponent<ReputationWidget>());

gauge = newRep.GetComponentInChildren<Gauge>();

StartCoroutine(TickTock());
}

IEnumerator TickTock()
{
gauge.minValue = 0f;
gauge.maxValue = 100f;
float delta = 33f;

while (true)
{
float newValue = gauge.Value + delta * Time.deltaTime;
if (newValue > 100f || newValue < 0f)
delta = -delta;

gauge.setValue(Mathf.Clamp(newValue, gauge.minValue, gauge.maxValue));

yield return 0;
}
}
}

Link to comment
Share on other sites

Thank you! (I'll have a lot of studying to do, though)

The second part needs clarification: if you're creating a brand new third texture every frame (...)

I'd like to have a scale that not only moves (and the tapemeter widget handles that), but can be covered and uncovered by a second slider. I suppose that to do that I should superimpose the cover texture shifted by X pixels over the scale texture, clip the result and get a third one to pass to the widget. Or is there a better way?

It's for a lift reserve indicator. The idea is grabbing cL, cLmax and Q from FAR/NEAR and driving the tapemeter to display how many Gz you are pulling (scale position) together with how many you COULD pull at the moment (edge of the uncovered scale). Gz being corrected for local gravity and centrifugal force, so that "1.0" is always what you need for level flight, either on Kerbin or on Duna at whatever speed you are flying.

Edited by thorfinn
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...